Methods
# static buy(delivery_id, rate_id, optionsopt) → {Promise.<Response>}
Purchased a shipping label
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
delivery_id |
string | The ID of the delivery for which you want to purchase a rate. |
|
rate_id |
string | The ID of the rate tha you wish to purchase. |
|
options |
Object |
<optional> |
Additional options you want to add while purchasing this rate. |
payment_method |
string |
<optional> |
The ID of the payment method you wish to use. We'll use the default card you have on file otherwise. |
metadata |
Integer |
<optional> |
You can add metadata as key-value pairs to a delivery. To remove a property, pass |
Returns the response object. The Response's data property
will be an array of Delivery
objects.
Example
//assuming we already created the delivery, we have access to the rates array, if any were returned
//we can pass back the id of the rate that we want to purchase the delivery
const delivery = response.data
const rate = delivery.rates[0].id //selected the first rate
const response = await dispatch.deliveries.buy(delivery.id, rate.id)
//if the purchase was successful, the purchased rate will be available on the purchased_rate property
const purchasedRate = response.data.purchased_rate
# static create(sender, recipient, parcels, optionsopt) → {Promise.<Response>}
Create a delivery intent. This will give you a list of rates to choose from.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
sender |
Object | The details about there this package is coming from. |
||
name |
string | The name of the sender. This could be a company name or a person's name. |
||
email |
string | The email of the sender. For on demand deliveries, this email will be used by the courier to contact the sender in case of any issues. |
||
phone |
string |
<optional> |
The phone number of this sender that an on demand courier could use to contact this sender if there is an issue. |
|
location_id |
string |
<optional> |
If you already have a location object, you can simply pass the id of the location and we'll use it's address. |
|
address |
string | Object.<NewAddress> |
<optional> |
If you do not have a location_id, you can just send your address and we'll create a location object for you. Your address can just be a full string and we'll parse it on our end, or you can send it as an object. |
|
recipient |
Object | The details about there this package is coming from. |
||
name |
string | The name of the sender. This could be a company name or a person's name. |
||
email |
string | The email of the sender. For on demand deliveries, this email will be used by the courier to contact the sender in case of any issues. |
||
phone |
string |
<optional> |
The phone number of this recipient that an on demand courier could use to contact this recipient if there is an issue. |
|
address |
string | Object.<NewAddress> | Your address can just be a full string and we'll parse it on our end, or you can send it as an object |
||
parcels |
Array.<Parcel> | An array of parcels that you want to send. |
||
options |
Object |
<optional> |
Additional options to include in your delivery. |
|
rate_cards |
Array |
<optional> |
An array of rate cards that you want to use for this transaction. These will be used instead of the rate cards you set on your Dispatch Dashboard. |
|
checkout_total |
Integer |
<optional> |
0 | The total cart/checkout value you submitted as an integer (e.g., $15.76 would be represented as 1576). This value is used to determine the free shipping tier that you can set up on the Dispatch dashboard. |
metadata |
Integer |
<optional> |
You can add metadata as key-value pairs to a delivery. To remove a property, pass |
|
verify_address |
Boolean |
<optional> |
true | If you want Dispatch to verify the sender and recipient addresses |
Returns the response object. The Response's data property
will be an array of Delivery
objects.
Examples
//This is a basic example for a standard shipment creating without additional options.
const sender = {
name: "Dispatch Roasters"
email: roasters@getdispatch.app,
phone: "4844836699",
location_id: "loc_j83498fhweofh4937fh"
}
const recipient = {
name: "Jamie Jones"
email: jamie.jones@getdispatch.app,
phone: "4844836699",
address: {
address_line1: "500 7th Ave",
city: "New York",
state: "NY"
zipcode: "10018"
}
}
const parcel = {
length: 10 // inches
width: 10 // inches
height: 10 // inches
weight: 10 // pounds
item_description: "Coffee", //optional
special_handling: "Fragile" //optional
}
//options are completely optional. You can omit the whole object
//or any properties from the object
const options = {
checkout_total: 5000, //$50.00
verify_address: false,
metadata: {
my_custom_id: "123456789"
}
}
const response = await dispatch.deliveries.create(sender, recipient, [parcel], options)
const delivery = response.data //this will have the delivery object
//in this example, we'll create the same shipment but add additional options
const sender = {
name: "Dispatch Roasters"
email: roasters@getdispatch.app,
location_id: "loc_j83498fhweofh4937fh"
}
const recipient = {
name: "Jamie Jones"
email: jamie.jones@getdispatch.app,
address: {
address_line1: "500 7th Ave",
city: "New York",
state: "NY"
zipcode: "10018"
}
}
const parcel = {
length: 10 // inches
width: 10 // inches
height: 10 // inches
weight: 10 // pounds
}
//if you wanted to add options, like the checkout_total, you can do so in the fourth argument
const options = {
//the checkout total is used to return free shipping options. These settings
//are configured once on the Dispatch dashboard
checkout_total: 10000 //this would be $100.00 since values are stored as integers
//the metadata allowed you to add custom properties to the delivery object
//most often used for an order number or customer number to be able to match
//delivery with your internal database later. The metadata property will be
//available on the delivery object when you retrieve it
metadata: {
customer_id: 123456789,
order_id: 987654321
temp_value: null //passing null will delete the key, if you had one saved before
}
}
dispatch.deliveries.create(sender, recipient, [parcel], options).then((response) => {
const delivery = response.data
console.log(delivery.metadata)
//handle post delivery creation operations...
}).catch((err) => {
console.error(err)
//handle errors...
})
# static list(options) → {Promise.<Response>}
Get a paginated list of deliveries
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | The options that you can use to return results |
limit |
integer | The amount of deliveries you want returned. The default is 15, but ranges from 1 to 100 |
page |
integer | The page you want to deliveries to start at. For example, a limit of 15 with a page value of 3, would return deliveries 30 - 45. The response object for the .list() method will have a pagination property which you can use to determine if there are more values in the database. |
location |
integer | Add a location ID the get just results from a specific location |
status |
integer | Will filter results based on statuses. Available options are: |
Returns the response object. The Response's data property
will be an array of Delivery
objects.
Example
const response = await dispatch.deliveries.list()
const deliveries = response.data //this will have an array of delivery objects
//check if there are more values in the database
if (data.pagination.has_more) {
//the delivery objects have a lot of data and setting the pagination to a loop can really hurt performance
//it's advised to just query in pages
//io query for the next page of deliveries you could do something like:
const nextResponse = dispatch.deliveries.list({limit: response.pagination.limit, page: response.pagination.current_page + 1})
}
# static refund(delivery_id) → {Promise.<Response>}
Refund a shipping label that you have already purchased
Parameters:
Name | Type | Description |
---|---|---|
delivery_id |
string | The ID of the delivery that you want to refund. |
Returns the response object.
Example
//a refund can only be done on a purchased label that has not been used
//refunds for on demand couriers need to happen within 5 minutes
const response = await dispatch.deliveries.refund("del_28374n8iudshf3nqifub")
# static retrieve(id) → {Promise.<Response>}
Retrieves a delivery using its ID
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The ID of the delivery that you want to retrieve |
Returns the response object. The Response's data property
will be an array of Delivery
objects.
Example
const response = await dispatch.deliveries.retrieve("del_fjdsklfju8jisjfdisoiu89j")
const delivery = response.data //this will contain the delivery object
# static update(delivery_id, updateopt) → {Promise.<Response>}
Update a delivery
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
delivery_id |
string | The ID of the delivery you want to update |
|
update |
Object |
<optional> |
An object of the fields you want to update |
sender |
Object |
<optional> |
The details about there this package is coming from. |
sender.name |
string |
<optional> |
The name of the sender. This could be a company name or a person's name. |
sender.email |
string |
<optional> |
The email of the sender. For on demand deliveries, this email will be used by the courier to contact the sender in case of any issues. |
sender.phone |
string |
<optional> |
The phone number of this sender that an on demand courier could use to contact this sender if there is an issue. |
recipient |
Object |
<optional> |
The details about there this package is coming from. |
recipient.name |
string |
<optional> |
The name of the sender. This could be a company name or a person's name. |
recipient.email |
string |
<optional> |
The email of the sender. For on demand deliveries, this email will be used by the courier to contact the sender in case of any issues. |
recipient.phone |
string |
<optional> |
The phone number of this recipient that an on demand courier could use to contact this recipient if there is an issue. |
options |
Object |
<optional> |
Additional options to include in your delivery. |
options.metadata |
Object |
<optional> |
You can add metadata as key-value pairs to a delivery. To remove a property, pass |
Returns the response object.
Example
// you can update emails, names, phone numbers, and metadata for the delivery
// if you want to update the delivery address you will have to create a new delivery.
const update = {
sender: {
name: "Dispatch Brewery",
email: "brewery@getdispatch.app",
phone: "1234567890"
},
recipient: {
phone: "1234567890" //only want to update the phone number for the recipient
},
options: {
// Metadata is optional information that you can attach to a delivery
metadata: {
timestamp: new Date(Date.now()),
updated_by: "Server Admin"
}
}
}
const response = await dispatch.deliveries.update("del_28374n8iudshf3nqifub", update)