Collect on Delivery
With the Collect on Delivery option you can now allow your customers to defer payment until they receive their shipment instead of paying at the time of their order.
Info
Looking for info on FedEx Ground Collect? You'll find that here!
Check Carrier support
First check that the carrier that you're using supports the Collect on Delivery option. Please see the following reference guide for further details
Collect on Delivery Fields
When creating a shipment, label, or rate in ShipEngine, you can use the advanced_options.collect_on_delivery
field to specify the Collect On Delivery options.
Example Snippet
{
"advanced_options": {
"collect_on_delivery": {
"payment_type": "cash",
"payment_amount": {
"amount": 10.7,
"currency": "usd"
}
}
}
}
{
"advanced_options": {
"collect_on_delivery": {
"payment_type": "cash",
"payment_amount": {
"amount": 10.7,
"currency": "usd"
}
}
}
}
Properties |
Description |
payment_type |
enumerated string, required any , cash , cash_equivalent , none |
amount |
decimal, required |
currency |
enumerated string, required usd , cad , aud , gbp , eur , nzd |
Info
To cancel a collect on delivery you must update the shipment, set the payment type
to none
and the amount
to 0
.
Info
The cash_equivalent
payment_type
specified in the request can cover a wide range of payment methods depending on the carrier. For example, users can pay with a cashier's check or a money order.
Please check with your selected carrier if this will be relevant to you or your customer.
Select Collect On Delivery
You can designate collect on delivery with the following API calls:
POST /v1/shipments
PUT /v1/shipments/{shipment_id}
POST /v1/labels
POST /v1/rates
Shipment Example
POST /v1/shipments HTTP/1.1
Host: api.shipengine.com
API-Key: __YOUR_API_KEY_HERE__
Content-Type: application/json
{
"shipments": [
{
"advanced_options": {
"collect_on_delivery": {
"payment_type": "cash",
"payment_amount": {
"amount": 10.7,
"currency": "usd"
}
}
},
"service_code": "ups_ground",
"validate_address": "no_validation",
"ship_to": {
"name": "Amanda Miller",
"phone": "555-555-5555",
"address_line1": "525 S Winchester Blvd",
"city_locality": "San Jose",
"state_province": "CA",
"postal_code": "95128",
"country_code": "US",
"address_residential_indicator": "yes"
},
"ship_from": {
"company_name": "Example Corp.",
"name": "John Doe",
"phone": "111-111-1111",
"address_line1": "4009 Marathon Blvd",
"address_line2": "Suite 300",
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "no"
},
"confirmation": "none",
"insurance_provider": "none",
"tags": [],
"packages": [
{
"weight": {
"value": 1,
"unit": "ounce"
}
}
]
}
]
}
curl -iX POST https://api.shipengine.com/v1/shipments \
-H 'API-Key: __YOUR_API_KEY_HERE__' \
-H 'Content-Type: application/json' \
-d '{
"shipments": [
{
"advanced_options": {
"collect_on_delivery": {
"payment_type": "cash",
"payment_amount": {
"amount": 10.7,
"currency": "usd"
}
}
},
"service_code": "ups_ground",
"validate_address": "no_validation",
"ship_to": {
"name": "Amanda Miller",
"phone": "555-555-5555",
"address_line1": "525 S Winchester Blvd",
"city_locality": "San Jose",
"state_province": "CA",
"postal_code": "95128",
"country_code": "US",
"address_residential_indicator": "yes"
},
"ship_from": {
"company_name": "Example Corp.",
"name": "John Doe",
"phone": "111-111-1111",
"address_line1": "4009 Marathon Blvd",
"address_line2": "Suite 300",
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "no"
},
"confirmation": "none",
"insurance_provider": "none",
"tags": [],
"packages": [
{
"weight": {
"value": 1,
"unit": "ounce"
}
}
]
}
]
}'
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Host", "api.shipengine.com")
$headers.Add("API-Key", "__YOUR_API_KEY_HERE__")
$headers.Add("Content-Type", "application/json")
$body = "{`n `"shipments`": [`n {`n `"advanced_options`": {`n `"collect_on_delivery`": {`n `"payment_type`": `"cash`",`n `"payment_amount`": {`n `"amount`": 10.7,`n `"currency`": `"usd`"`n }`n }`n },`n `"service_code`": `"ups_ground`",`n `"validate_address`": `"no_validation`",`n `"ship_to`": {`n `"name`": `"Amanda Miller`",`n `"phone`": `"555-555-5555`",`n `"address_line1`": `"525 S Winchester Blvd`",`n `"city_locality`": `"San Jose`",`n `"state_province`": `"CA`",`n `"postal_code`": `"95128`",`n `"country_code`": `"US`",`n `"address_residential_indicator`": `"yes`"`n },`n `"ship_from`": {`n `"company_name`": `"Example Corp.`",`n `"name`": `"John Doe`",`n `"phone`": `"111-111-1111`",`n `"address_line1`": `"4009 Marathon Blvd`",`n `"address_line2`": `"Suite 300`",`n `"city_locality`": `"Austin`",`n `"state_province`": `"TX`",`n `"postal_code`": `"78756`",`n `"country_code`": `"US`",`n `"address_residential_indicator`": `"no`"`n },`n `"confirmation`": `"none`",`n `"insurance_provider`": `"none`",`n `"tags`": [],`n `"packages`": [`n {`n `"weight`": {`n `"value`": 1,`n `"unit`": `"ounce`"`n }`n }`n ]`n }`n ]`n}"
$response = Invoke-RestMethod 'https://api.shipengine.com/v1/shipments' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
var myHeaders = new Headers();
myHeaders.append("Host", "api.shipengine.com");
myHeaders.append("API-Key", "__YOUR_API_KEY_HERE__");
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({"shipments":[{"advanced_options":{"collect_on_delivery":{"payment_type":"cash","payment_amount":{"amount":10.7,"currency":"usd"}}},"service_code":"ups_ground","validate_address":"no_validation","ship_to":{"name":"Amanda Miller","phone":"555-555-5555","address_line1":"525 S Winchester Blvd","city_locality":"San Jose","state_province":"CA","postal_code":"95128","country_code":"US","address_residential_indicator":"yes"},"ship_from":{"company_name":"Example Corp.","name":"John Doe","phone":"111-111-1111","address_line1":"4009 Marathon Blvd","address_line2":"Suite 300","city_locality":"Austin","state_province":"TX","postal_code":"78756","country_code":"US","address_residential_indicator":"no"},"confirmation":"none","insurance_provider":"none","tags":[],"packages":[{"weight":{"value":1,"unit":"ounce"}}]}]});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.shipengine.com/v1/shipments", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://api.shipengine.com/v1/shipments',
'headers': {
'Host': 'api.shipengine.com',
'API-Key': '__YOUR_API_KEY_HERE__',
'Content-Type': 'application/json'
},
body: JSON.stringify({"shipments":[{"advanced_options":{"collect_on_delivery":{"payment_type":"cash","payment_amount":{"amount":10.7,"currency":"usd"}}},"service_code":"ups_ground","validate_address":"no_validation","ship_to":{"name":"Amanda Miller","phone":"555-555-5555","address_line1":"525 S Winchester Blvd","city_locality":"San Jose","state_province":"CA","postal_code":"95128","country_code":"US","address_residential_indicator":"yes"},"ship_from":{"company_name":"Example Corp.","name":"John Doe","phone":"111-111-1111","address_line1":"4009 Marathon Blvd","address_line2":"Suite 300","city_locality":"Austin","state_province":"TX","postal_code":"78756","country_code":"US","address_residential_indicator":"no"},"confirmation":"none","insurance_provider":"none","tags":[],"packages":[{"weight":{"value":1,"unit":"ounce"}}]}]})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.shipengine.com/v1/shipments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"{\n \"shipments\": [\n {\n \"advanced_options\": {\n \"collect_on_delivery\": {\n \"payment_type\": \"cash\",\n \"payment_amount\": {\n \"amount\": 10.7,\n \"currency\": \"usd\"\n }\n }\n },\n \"service_code\": \"ups_ground\",\n \"validate_address\": \"no_validation\",\n \"ship_to\": {\n \"name\": \"Amanda Miller\",\n \"phone\": \"555-555-5555\",\n \"address_line1\": \"525 S Winchester Blvd\",\n \"city_locality\": \"San Jose\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95128\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"yes\"\n },\n \"ship_from\": {\n \"company_name\": \"Example Corp.\",\n \"name\": \"John Doe\",\n \"phone\": \"111-111-1111\",\n \"address_line1\": \"4009 Marathon Blvd\",\n \"address_line2\": \"Suite 300\",\n \"city_locality\": \"Austin\",\n \"state_province\": \"TX\",\n \"postal_code\": \"78756\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"confirmation\": \"none\",\n \"insurance_provider\": \"none\",\n \"tags\": [],\n \"packages\": [\n {\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }\n ]\n }\n ]\n}",
CURLOPT_HTTPHEADER => array(
"Host: api.shipengine.com",
"API-Key: __YOUR_API_KEY_HERE__",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
url = "https://api.shipengine.com/v1/shipments"
payload = "{\n \"shipments\": [\n {\n \"advanced_options\": {\n \"collect_on_delivery\": {\n \"payment_type\": \"cash\",\n \"payment_amount\": {\n \"amount\": 10.7,\n \"currency\": \"usd\"\n }\n }\n },\n \"service_code\": \"ups_ground\",\n \"validate_address\": \"no_validation\",\n \"ship_to\": {\n \"name\": \"Amanda Miller\",\n \"phone\": \"555-555-5555\",\n \"address_line1\": \"525 S Winchester Blvd\",\n \"city_locality\": \"San Jose\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95128\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"yes\"\n },\n \"ship_from\": {\n \"company_name\": \"Example Corp.\",\n \"name\": \"John Doe\",\n \"phone\": \"111-111-1111\",\n \"address_line1\": \"4009 Marathon Blvd\",\n \"address_line2\": \"Suite 300\",\n \"city_locality\": \"Austin\",\n \"state_province\": \"TX\",\n \"postal_code\": \"78756\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"confirmation\": \"none\",\n \"insurance_provider\": \"none\",\n \"tags\": [],\n \"packages\": [\n {\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }\n ]\n }\n ]\n}"
headers = {
'Host': 'api.shipengine.com',
'API-Key': '__YOUR_API_KEY_HERE__',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
require "uri"
require "net/http"
url = URI("https://api.shipengine.com/v1/shipments")
https = Net::HTTP.new(url.host, url.port);
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Host"] = "api.shipengine.com"
request["API-Key"] = "__YOUR_API_KEY_HERE__"
request["Content-Type"] = "application/json"
request.body = "{\n \"shipments\": [\n {\n \"advanced_options\": {\n \"collect_on_delivery\": {\n \"payment_type\": \"cash\",\n \"payment_amount\": {\n \"amount\": 10.7,\n \"currency\": \"usd\"\n }\n }\n },\n \"service_code\": \"ups_ground\",\n \"validate_address\": \"no_validation\",\n \"ship_to\": {\n \"name\": \"Amanda Miller\",\n \"phone\": \"555-555-5555\",\n \"address_line1\": \"525 S Winchester Blvd\",\n \"city_locality\": \"San Jose\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95128\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"yes\"\n },\n \"ship_from\": {\n \"company_name\": \"Example Corp.\",\n \"name\": \"John Doe\",\n \"phone\": \"111-111-1111\",\n \"address_line1\": \"4009 Marathon Blvd\",\n \"address_line2\": \"Suite 300\",\n \"city_locality\": \"Austin\",\n \"state_province\": \"TX\",\n \"postal_code\": \"78756\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"confirmation\": \"none\",\n \"insurance_provider\": \"none\",\n \"tags\": [],\n \"packages\": [\n {\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }\n ]\n }\n ]\n}"
response = https.request(request)
puts response.read_body
var client = new RestClient("https://api.shipengine.com/v1/shipments");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Host", "api.shipengine.com");
request.AddHeader("API-Key", "__YOUR_API_KEY_HERE__");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n \"shipments\": [\n {\n \"advanced_options\": {\n \"collect_on_delivery\": {\n \"payment_type\": \"cash\",\n \"payment_amount\": {\n \"amount\": 10.7,\n \"currency\": \"usd\"\n }\n }\n },\n \"service_code\": \"ups_ground\",\n \"validate_address\": \"no_validation\",\n \"ship_to\": {\n \"name\": \"Amanda Miller\",\n \"phone\": \"555-555-5555\",\n \"address_line1\": \"525 S Winchester Blvd\",\n \"city_locality\": \"San Jose\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95128\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"yes\"\n },\n \"ship_from\": {\n \"company_name\": \"Example Corp.\",\n \"name\": \"John Doe\",\n \"phone\": \"111-111-1111\",\n \"address_line1\": \"4009 Marathon Blvd\",\n \"address_line2\": \"Suite 300\",\n \"city_locality\": \"Austin\",\n \"state_province\": \"TX\",\n \"postal_code\": \"78756\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"confirmation\": \"none\",\n \"insurance_provider\": \"none\",\n \"tags\": [],\n \"packages\": [\n {\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }\n ]\n }\n ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n \"shipments\": [\n {\n \"advanced_options\": {\n \"collect_on_delivery\": {\n \"payment_type\": \"cash\",\n \"payment_amount\": {\n \"amount\": 10.7,\n \"currency\": \"usd\"\n }\n }\n },\n \"service_code\": \"ups_ground\",\n \"validate_address\": \"no_validation\",\n \"ship_to\": {\n \"name\": \"Amanda Miller\",\n \"phone\": \"555-555-5555\",\n \"address_line1\": \"525 S Winchester Blvd\",\n \"city_locality\": \"San Jose\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95128\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"yes\"\n },\n \"ship_from\": {\n \"company_name\": \"Example Corp.\",\n \"name\": \"John Doe\",\n \"phone\": \"111-111-1111\",\n \"address_line1\": \"4009 Marathon Blvd\",\n \"address_line2\": \"Suite 300\",\n \"city_locality\": \"Austin\",\n \"state_province\": \"TX\",\n \"postal_code\": \"78756\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"confirmation\": \"none\",\n \"insurance_provider\": \"none\",\n \"tags\": [],\n \"packages\": [\n {\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }\n ]\n }\n ]\n}");
Request request = new Request.Builder()
.url("https://api.shipengine.com/v1/shipments")
.method("POST", body)
.addHeader("Host", "api.shipengine.com")
.addHeader("API-Key", "__YOUR_API_KEY_HERE__")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.shipengine.com/v1/shipments"
method := "POST"
payload := strings.NewReader("{\n \"shipments\": [\n {\n \"advanced_options\": {\n \"collect_on_delivery\": {\n \"payment_type\": \"cash\",\n \"payment_amount\": {\n \"amount\": 10.7,\n \"currency\": \"usd\"\n }\n }\n },\n \"service_code\": \"ups_ground\",\n \"validate_address\": \"no_validation\",\n \"ship_to\": {\n \"name\": \"Amanda Miller\",\n \"phone\": \"555-555-5555\",\n \"address_line1\": \"525 S Winchester Blvd\",\n \"city_locality\": \"San Jose\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95128\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"yes\"\n },\n \"ship_from\": {\n \"company_name\": \"Example Corp.\",\n \"name\": \"John Doe\",\n \"phone\": \"111-111-1111\",\n \"address_line1\": \"4009 Marathon Blvd\",\n \"address_line2\": \"Suite 300\",\n \"city_locality\": \"Austin\",\n \"state_province\": \"TX\",\n \"postal_code\": \"78756\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"confirmation\": \"none\",\n \"insurance_provider\": \"none\",\n \"tags\": [],\n \"packages\": [\n {\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }\n ]\n }\n ]\n}")
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
}
req.Header.Add("Host", "api.shipengine.com")
req.Header.Add("API-Key", "__YOUR_API_KEY_HERE__")
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
#import <Foundation/Foundation.h>
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.shipengine.com/v1/shipments"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
NSDictionary *headers = @{
@"Host": @"api.shipengine.com",
@"API-Key": @"__YOUR_API_KEY_HERE__",
@"Content-Type": @"application/json"
};
[request setAllHTTPHeaderFields:headers];
NSData *postData = [[NSData alloc] initWithData:[@"{\n \"shipments\": [\n {\n \"advanced_options\": {\n \"collect_on_delivery\": {\n \"payment_type\": \"cash\",\n \"payment_amount\": {\n \"amount\": 10.7,\n \"currency\": \"usd\"\n }\n }\n },\n \"service_code\": \"ups_ground\",\n \"validate_address\": \"no_validation\",\n \"ship_to\": {\n \"name\": \"Amanda Miller\",\n \"phone\": \"555-555-5555\",\n \"address_line1\": \"525 S Winchester Blvd\",\n \"city_locality\": \"San Jose\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95128\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"yes\"\n },\n \"ship_from\": {\n \"company_name\": \"Example Corp.\",\n \"name\": \"John Doe\",\n \"phone\": \"111-111-1111\",\n \"address_line1\": \"4009 Marathon Blvd\",\n \"address_line2\": \"Suite 300\",\n \"city_locality\": \"Austin\",\n \"state_province\": \"TX\",\n \"postal_code\": \"78756\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"confirmation\": \"none\",\n \"insurance_provider\": \"none\",\n \"tags\": [],\n \"packages\": [\n {\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }\n ]\n }\n ]\n}" dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postData];
[request setHTTPMethod:@"POST"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSError *parseError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
NSLog(@"%@",responseDictionary);
dispatch_semaphore_signal(sema);
}
}];
[dataTask resume];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
import Foundation
var semaphore = DispatchSemaphore (value: 0)
let parameters = "{\n \"shipments\": [\n {\n \"advanced_options\": {\n \"collect_on_delivery\": {\n \"payment_type\": \"cash\",\n \"payment_amount\": {\n \"amount\": 10.7,\n \"currency\": \"usd\"\n }\n }\n },\n \"service_code\": \"ups_ground\",\n \"validate_address\": \"no_validation\",\n \"ship_to\": {\n \"name\": \"Amanda Miller\",\n \"phone\": \"555-555-5555\",\n \"address_line1\": \"525 S Winchester Blvd\",\n \"city_locality\": \"San Jose\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95128\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"yes\"\n },\n \"ship_from\": {\n \"company_name\": \"Example Corp.\",\n \"name\": \"John Doe\",\n \"phone\": \"111-111-1111\",\n \"address_line1\": \"4009 Marathon Blvd\",\n \"address_line2\": \"Suite 300\",\n \"city_locality\": \"Austin\",\n \"state_province\": \"TX\",\n \"postal_code\": \"78756\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"confirmation\": \"none\",\n \"insurance_provider\": \"none\",\n \"tags\": [],\n \"packages\": [\n {\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }\n ]\n }\n ]\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.shipengine.com/v1/shipments")!,timeoutInterval: Double.infinity)
request.addValue("api.shipengine.com", forHTTPHeaderField: "Host")
request.addValue("__YOUR_API_KEY_HERE__", forHTTPHeaderField: "API-Key")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
return
}
print(String(data: data, encoding: .utf8)!)
semaphore.signal()
}
task.resume()
semaphore.wait()
{
"shipments": [
{
"advanced_options": {
"bill_to_account": null,
"bill_to_country_code": null,
"bill_to_party": null,
"bill_to_postal_code": null,
"contains_alcohol": false,
"delivered_duty_paid": false,
"non_machinable": false,
"saturday_delivery": false,
"dry_ice": false,
"dry_ice_weight": null,
"freight_class": null,
"custom_field1": null,
"custom_field2": null,
"custom_field3": null,
"collect_on_delivery": {
"payment_type": "cash",
"payment_amount": {
"currency": "usd",
"amount": 10.7
}
}
},
"errors": [],
"address_validation": null,
"shipment_id": "se-1020109",
"carrier_id": "se-95",
"service_code": "ups_ground",
"external_shipment_id": null,
"ship_date": "2019-09-25T00:00:00Z",
"created_at": "2019-09-25T19:03:49.0116799Z",
"modified_at": "2019-09-25T19:03:49.0126795Z",
"shipment_status": "pending",
"ship_to": {
"name": "Amanda Miller",
"phone": "555-555-5555",
"address_line1": "525 S Winchester Blvd",
"city_locality": "San Jose",
"state_province": "CA",
"postal_code": "95128",
"country_code": "US",
"address_residential_indicator": "yes"
},
"ship_from": {
"company_name": "Example Corp.",
"name": "John Doe",
"phone": "111-111-1111",
"address_line1": "4009 Marathon Blvd",
"address_line2": "Suite 300",
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "no"
},
"warehouse_id": null,
"return_to": {
"company_name": "Example Corp.",
"name": "John Doe",
"phone": "111-111-1111",
"address_line1": "4009 Marathon Blvd",
"address_line2": "Suite 300",
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "no"
},
"confirmation": "none",
"customs": null,
"external_order_id": null,
"order_source_code": null,
"insurance_provider": "none",
"tags": [],
"packages": [
{
"package_code": "package",
"weight": {
"value": 1.0,
"unit": "ounce"
},
"dimensions": {
"unit": "inch",
"length": 0.0,
"width": 0.0,
"height": 0.0
},
"insured_value": {
"currency": "usd",
"amount": 0.0
},
"label_messages": {
"reference1": null,
"reference2": null,
"reference3": null
},
"external_package_id": null
}
],
"total_weight": {
"value": 1.0,
"unit": "ounce"
},
"items": []
}
]
}
{
"shipments": [
{
"advanced_options": {
"bill_to_account": null,
"bill_to_country_code": null,
"bill_to_party": null,
"bill_to_postal_code": null,
"contains_alcohol": false,
"delivered_duty_paid": false,
"non_machinable": false,
"saturday_delivery": false,
"dry_ice": false,
"dry_ice_weight": null,
"freight_class": null,
"custom_field1": null,
"custom_field2": null,
"custom_field3": null,
"collect_on_delivery": {
"payment_type": "cash",
"payment_amount": {
"currency": "usd",
"amount": 10.7
}
}
},
"errors": [],
"address_validation": null,
"shipment_id": "se-1020109",
"carrier_id": "se-95",
"service_code": "ups_ground",
"external_shipment_id": null,
"ship_date": "2019-09-25T00:00:00Z",
"created_at": "2019-09-25T19:03:49.0116799Z",
"modified_at": "2019-09-25T19:03:49.0126795Z",
"shipment_status": "pending",
"ship_to": {
"name": "Amanda Miller",
"phone": "555-555-5555",
"address_line1": "525 S Winchester Blvd",
"city_locality": "San Jose",
"state_province": "CA",
"postal_code": "95128",
"country_code": "US",
"address_residential_indicator": "yes"
},
"ship_from": {
"company_name": "Example Corp.",
"name": "John Doe",
"phone": "111-111-1111",
"address_line1": "4009 Marathon Blvd",
"address_line2": "Suite 300",
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "no"
},
"warehouse_id": null,
"return_to": {
"company_name": "Example Corp.",
"name": "John Doe",
"phone": "111-111-1111",
"address_line1": "4009 Marathon Blvd",
"address_line2": "Suite 300",
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "no"
},
"confirmation": "none",
"customs": null,
"external_order_id": null,
"order_source_code": null,
"insurance_provider": "none",
"tags": [],
"packages": [
{
"package_code": "package",
"weight": {
"value": 1.0,
"unit": "ounce"
},
"dimensions": {
"unit": "inch",
"length": 0.0,
"width": 0.0,
"height": 0.0
},
"insured_value": {
"currency": "usd",
"amount": 0.0
},
"label_messages": {
"reference1": null,
"reference2": null,
"reference3": null
},
"external_package_id": null
}
],
"total_weight": {
"value": 1.0,
"unit": "ounce"
},
"items": []
}
]
}
Label Example
POST /v1/labels HTTP/1.1
Host: api.shipengine.com
API-Key: __YOUR_API_KEY_HERE__
Content-Type: application/json
{
"shipment": {
"advanced_options": {
"collect_on_delivery": {
"payment_type": "any",
"payment_amount": {
"amount": 10.7,
"currency": "usd"
}
}
},
"service_code": "ups_ground",
"external_shipment_id": "__YOUR_EXTERNAL_ID_HERE__",
"ship_to": {
"name": "John Stuckey",
"phone": "6625905259",
"company_name": "John Stuckey",
"address_line1": "3412 Pemberton Square Blvd",
"address_line2": "Ste 2-241",
"city_locality": "VICKSBURG",
"postal_code": "39180-5541",
"country_code": "US",
"state_province": "MS",
"address_residential_indicator": "unknown"
},
"ship_from": {
"name": "Fulfillment Center",
"phone": "877-743-2269",
"company_name": "BBQGuys",
"address_line1": "8151 Airline Hwy",
"city_locality": "Baton Rouge",
"postal_code": "70815",
"country_code": "US",
"state_province": "LA"
},
"confirmation": "none",
"packages": [
{
"weight": {
"value": 2,
"unit": "pound"
},
"dimensions": {
"unit": "inch",
"length": 2,
"width": 14,
"height": 17
}
}
]
}
}
curl -iX POST https://api.shipengine.com/v1/labels \
-H 'API-Key: __YOUR_API_KEY_HERE__' \
-H 'Content-Type: application/json' \
-d '{
"shipment": {
"advanced_options": {
"collect_on_delivery": {
"payment_type": "any",
"payment_amount": {
"amount": 10.7,
"currency": "usd"
}
}
},
"service_code": "ups_ground",
"external_shipment_id": "__YOUR_EXTERNAL_ID_HERE__",
"ship_to": {
"name": "John Stuckey",
"phone": "6625905259",
"company_name": "John Stuckey",
"address_line1": "3412 Pemberton Square Blvd",
"address_line2": "Ste 2-241",
"city_locality": "VICKSBURG",
"postal_code": "39180-5541",
"country_code": "US",
"state_province": "MS",
"address_residential_indicator": "unknown"
},
"ship_from": {
"name": "Fulfillment Center",
"phone": "877-743-2269",
"company_name": "BBQGuys",
"address_line1": "8151 Airline Hwy",
"city_locality": "Baton Rouge",
"postal_code": "70815",
"country_code": "US",
"state_province": "LA"
},
"confirmation": "none",
"packages": [
{
"weight": {
"value": 2,
"unit": "pound"
},
"dimensions": {
"unit": "inch",
"length": 2,
"width": 14,
"height": 17
}
}
]
}
}'
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Host", "api.shipengine.com")
$headers.Add("API-Key", "__YOUR_API_KEY_HERE__")
$headers.Add("Content-Type", "application/json")
$body = "{`n `"shipment`": {`n `"advanced_options`": {`n `"collect_on_delivery`": {`n `"payment_type`": `"any`",`n `"payment_amount`": {`n `"amount`": 10.7,`n `"currency`": `"usd`"`n }`n }`n },`n `"service_code`": `"ups_ground`",`n `"external_shipment_id`": `"__YOUR_EXTERNAL_ID_HERE__`",`n `"ship_to`": {`n `"name`": `"John Stuckey`",`n `"phone`": `"6625905259`",`n `"company_name`": `"John Stuckey`",`n `"address_line1`": `"3412 Pemberton Square Blvd`",`n `"address_line2`": `"Ste 2-241`",`n `"city_locality`": `"VICKSBURG`",`n `"postal_code`": `"39180-5541`",`n `"country_code`": `"US`",`n `"state_province`": `"MS`",`n `"address_residential_indicator`": `"unknown`"`n },`n `"ship_from`": {`n `"name`": `"Fulfillment Center`",`n `"phone`": `"877-743-2269`",`n `"company_name`": `"BBQGuys`",`n `"address_line1`": `"8151 Airline Hwy`",`n `"city_locality`": `"Baton Rouge`",`n `"postal_code`": `"70815`",`n `"country_code`": `"US`",`n `"state_province`": `"LA`"`n },`n `"confirmation`": `"none`",`n `"packages`": [`n {`n `"weight`": {`n `"value`": 2,`n `"unit`": `"pound`"`n },`n `"dimensions`": {`n `"unit`": `"inch`",`n `"length`": 2,`n `"width`": 14,`n `"height`": 17`n }`n }`n ]`n }`n}"
$response = Invoke-RestMethod 'https://api.shipengine.com/v1/labels' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
var myHeaders = new Headers();
myHeaders.append("Host", "api.shipengine.com");
myHeaders.append("API-Key", "__YOUR_API_KEY_HERE__");
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({"shipment":{"advanced_options":{"collect_on_delivery":{"payment_type":"any","payment_amount":{"amount":10.7,"currency":"usd"}}},"service_code":"ups_ground","external_shipment_id":"__YOUR_EXTERNAL_ID_HERE__","ship_to":{"name":"John Stuckey","phone":"6625905259","company_name":"John Stuckey","address_line1":"3412 Pemberton Square Blvd","address_line2":"Ste 2-241","city_locality":"VICKSBURG","postal_code":"39180-5541","country_code":"US","state_province":"MS","address_residential_indicator":"unknown"},"ship_from":{"name":"Fulfillment Center","phone":"877-743-2269","company_name":"BBQGuys","address_line1":"8151 Airline Hwy","city_locality":"Baton Rouge","postal_code":"70815","country_code":"US","state_province":"LA"},"confirmation":"none","packages":[{"weight":{"value":2,"unit":"pound"},"dimensions":{"unit":"inch","length":2,"width":14,"height":17}}]}});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.shipengine.com/v1/labels", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://api.shipengine.com/v1/labels',
'headers': {
'Host': 'api.shipengine.com',
'API-Key': '__YOUR_API_KEY_HERE__',
'Content-Type': 'application/json'
},
body: JSON.stringify({"shipment":{"advanced_options":{"collect_on_delivery":{"payment_type":"any","payment_amount":{"amount":10.7,"currency":"usd"}}},"service_code":"ups_ground","external_shipment_id":"__YOUR_EXTERNAL_ID_HERE__","ship_to":{"name":"John Stuckey","phone":"6625905259","company_name":"John Stuckey","address_line1":"3412 Pemberton Square Blvd","address_line2":"Ste 2-241","city_locality":"VICKSBURG","postal_code":"39180-5541","country_code":"US","state_province":"MS","address_residential_indicator":"unknown"},"ship_from":{"name":"Fulfillment Center","phone":"877-743-2269","company_name":"BBQGuys","address_line1":"8151 Airline Hwy","city_locality":"Baton Rouge","postal_code":"70815","country_code":"US","state_province":"LA"},"confirmation":"none","packages":[{"weight":{"value":2,"unit":"pound"},"dimensions":{"unit":"inch","length":2,"width":14,"height":17}}]}})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.shipengine.com/v1/labels",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"{\n \"shipment\": {\n \"advanced_options\": {\n \"collect_on_delivery\": {\n \"payment_type\": \"any\",\n \"payment_amount\": {\n \"amount\": 10.7,\n \"currency\": \"usd\"\n }\n }\n },\n \"service_code\": \"ups_ground\",\n \"external_shipment_id\": \"__YOUR_EXTERNAL_ID_HERE__\",\n \"ship_to\": {\n \"name\": \"John Stuckey\",\n \"phone\": \"6625905259\",\n \"company_name\": \"John Stuckey\",\n \"address_line1\": \"3412 Pemberton Square Blvd\",\n \"address_line2\": \"Ste 2-241\",\n \"city_locality\": \"VICKSBURG\",\n \"postal_code\": \"39180-5541\",\n \"country_code\": \"US\",\n \"state_province\": \"MS\",\n \"address_residential_indicator\": \"unknown\"\n },\n \"ship_from\": {\n \"name\": \"Fulfillment Center\",\n \"phone\": \"877-743-2269\",\n \"company_name\": \"BBQGuys\",\n \"address_line1\": \"8151 Airline Hwy\",\n \"city_locality\": \"Baton Rouge\",\n \"postal_code\": \"70815\",\n \"country_code\": \"US\",\n \"state_province\": \"LA\"\n },\n \"confirmation\": \"none\",\n \"packages\": [\n {\n \"weight\": {\n \"value\": 2,\n \"unit\": \"pound\"\n },\n \"dimensions\": {\n \"unit\": \"inch\",\n \"length\": 2,\n \"width\": 14,\n \"height\": 17\n }\n }\n ]\n }\n}",
CURLOPT_HTTPHEADER => array(
"Host: api.shipengine.com",
"API-Key: __YOUR_API_KEY_HERE__",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
url = "https://api.shipengine.com/v1/labels"
payload = "{\n \"shipment\": {\n \"advanced_options\": {\n \"collect_on_delivery\": {\n \"payment_type\": \"any\",\n \"payment_amount\": {\n \"amount\": 10.7,\n \"currency\": \"usd\"\n }\n }\n },\n \"service_code\": \"ups_ground\",\n \"external_shipment_id\": \"__YOUR_EXTERNAL_ID_HERE__\",\n \"ship_to\": {\n \"name\": \"John Stuckey\",\n \"phone\": \"6625905259\",\n \"company_name\": \"John Stuckey\",\n \"address_line1\": \"3412 Pemberton Square Blvd\",\n \"address_line2\": \"Ste 2-241\",\n \"city_locality\": \"VICKSBURG\",\n \"postal_code\": \"39180-5541\",\n \"country_code\": \"US\",\n \"state_province\": \"MS\",\n \"address_residential_indicator\": \"unknown\"\n },\n \"ship_from\": {\n \"name\": \"Fulfillment Center\",\n \"phone\": \"877-743-2269\",\n \"company_name\": \"BBQGuys\",\n \"address_line1\": \"8151 Airline Hwy\",\n \"city_locality\": \"Baton Rouge\",\n \"postal_code\": \"70815\",\n \"country_code\": \"US\",\n \"state_province\": \"LA\"\n },\n \"confirmation\": \"none\",\n \"packages\": [\n {\n \"weight\": {\n \"value\": 2,\n \"unit\": \"pound\"\n },\n \"dimensions\": {\n \"unit\": \"inch\",\n \"length\": 2,\n \"width\": 14,\n \"height\": 17\n }\n }\n ]\n }\n}"
headers = {
'Host': 'api.shipengine.com',
'API-Key': '__YOUR_API_KEY_HERE__',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
require "uri"
require "net/http"
url = URI("https://api.shipengine.com/v1/labels")
https = Net::HTTP.new(url.host, url.port);
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Host"] = "api.shipengine.com"
request["API-Key"] = "__YOUR_API_KEY_HERE__"
request["Content-Type"] = "application/json"
request.body = "{\n \"shipment\": {\n \"advanced_options\": {\n \"collect_on_delivery\": {\n \"payment_type\": \"any\",\n \"payment_amount\": {\n \"amount\": 10.7,\n \"currency\": \"usd\"\n }\n }\n },\n \"service_code\": \"ups_ground\",\n \"external_shipment_id\": \"__YOUR_EXTERNAL_ID_HERE__\",\n \"ship_to\": {\n \"name\": \"John Stuckey\",\n \"phone\": \"6625905259\",\n \"company_name\": \"John Stuckey\",\n \"address_line1\": \"3412 Pemberton Square Blvd\",\n \"address_line2\": \"Ste 2-241\",\n \"city_locality\": \"VICKSBURG\",\n \"postal_code\": \"39180-5541\",\n \"country_code\": \"US\",\n \"state_province\": \"MS\",\n \"address_residential_indicator\": \"unknown\"\n },\n \"ship_from\": {\n \"name\": \"Fulfillment Center\",\n \"phone\": \"877-743-2269\",\n \"company_name\": \"BBQGuys\",\n \"address_line1\": \"8151 Airline Hwy\",\n \"city_locality\": \"Baton Rouge\",\n \"postal_code\": \"70815\",\n \"country_code\": \"US\",\n \"state_province\": \"LA\"\n },\n \"confirmation\": \"none\",\n \"packages\": [\n {\n \"weight\": {\n \"value\": 2,\n \"unit\": \"pound\"\n },\n \"dimensions\": {\n \"unit\": \"inch\",\n \"length\": 2,\n \"width\": 14,\n \"height\": 17\n }\n }\n ]\n }\n}"
response = https.request(request)
puts response.read_body
var client = new RestClient("https://api.shipengine.com/v1/labels");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Host", "api.shipengine.com");
request.AddHeader("API-Key", "__YOUR_API_KEY_HERE__");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n \"shipment\": {\n \"advanced_options\": {\n \"collect_on_delivery\": {\n \"payment_type\": \"any\",\n \"payment_amount\": {\n \"amount\": 10.7,\n \"currency\": \"usd\"\n }\n }\n },\n \"service_code\": \"ups_ground\",\n \"external_shipment_id\": \"__YOUR_EXTERNAL_ID_HERE__\",\n \"ship_to\": {\n \"name\": \"John Stuckey\",\n \"phone\": \"6625905259\",\n \"company_name\": \"John Stuckey\",\n \"address_line1\": \"3412 Pemberton Square Blvd\",\n \"address_line2\": \"Ste 2-241\",\n \"city_locality\": \"VICKSBURG\",\n \"postal_code\": \"39180-5541\",\n \"country_code\": \"US\",\n \"state_province\": \"MS\",\n \"address_residential_indicator\": \"unknown\"\n },\n \"ship_from\": {\n \"name\": \"Fulfillment Center\",\n \"phone\": \"877-743-2269\",\n \"company_name\": \"BBQGuys\",\n \"address_line1\": \"8151 Airline Hwy\",\n \"city_locality\": \"Baton Rouge\",\n \"postal_code\": \"70815\",\n \"country_code\": \"US\",\n \"state_province\": \"LA\"\n },\n \"confirmation\": \"none\",\n \"packages\": [\n {\n \"weight\": {\n \"value\": 2,\n \"unit\": \"pound\"\n },\n \"dimensions\": {\n \"unit\": \"inch\",\n \"length\": 2,\n \"width\": 14,\n \"height\": 17\n }\n }\n ]\n }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n \"shipment\": {\n \"advanced_options\": {\n \"collect_on_delivery\": {\n \"payment_type\": \"any\",\n \"payment_amount\": {\n \"amount\": 10.7,\n \"currency\": \"usd\"\n }\n }\n },\n \"service_code\": \"ups_ground\",\n \"external_shipment_id\": \"__YOUR_EXTERNAL_ID_HERE__\",\n \"ship_to\": {\n \"name\": \"John Stuckey\",\n \"phone\": \"6625905259\",\n \"company_name\": \"John Stuckey\",\n \"address_line1\": \"3412 Pemberton Square Blvd\",\n \"address_line2\": \"Ste 2-241\",\n \"city_locality\": \"VICKSBURG\",\n \"postal_code\": \"39180-5541\",\n \"country_code\": \"US\",\n \"state_province\": \"MS\",\n \"address_residential_indicator\": \"unknown\"\n },\n \"ship_from\": {\n \"name\": \"Fulfillment Center\",\n \"phone\": \"877-743-2269\",\n \"company_name\": \"BBQGuys\",\n \"address_line1\": \"8151 Airline Hwy\",\n \"city_locality\": \"Baton Rouge\",\n \"postal_code\": \"70815\",\n \"country_code\": \"US\",\n \"state_province\": \"LA\"\n },\n \"confirmation\": \"none\",\n \"packages\": [\n {\n \"weight\": {\n \"value\": 2,\n \"unit\": \"pound\"\n },\n \"dimensions\": {\n \"unit\": \"inch\",\n \"length\": 2,\n \"width\": 14,\n \"height\": 17\n }\n }\n ]\n }\n}");
Request request = new Request.Builder()
.url("https://api.shipengine.com/v1/labels")
.method("POST", body)
.addHeader("Host", "api.shipengine.com")
.addHeader("API-Key", "__YOUR_API_KEY_HERE__")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.shipengine.com/v1/labels"
method := "POST"
payload := strings.NewReader("{\n \"shipment\": {\n \"advanced_options\": {\n \"collect_on_delivery\": {\n \"payment_type\": \"any\",\n \"payment_amount\": {\n \"amount\": 10.7,\n \"currency\": \"usd\"\n }\n }\n },\n \"service_code\": \"ups_ground\",\n \"external_shipment_id\": \"__YOUR_EXTERNAL_ID_HERE__\",\n \"ship_to\": {\n \"name\": \"John Stuckey\",\n \"phone\": \"6625905259\",\n \"company_name\": \"John Stuckey\",\n \"address_line1\": \"3412 Pemberton Square Blvd\",\n \"address_line2\": \"Ste 2-241\",\n \"city_locality\": \"VICKSBURG\",\n \"postal_code\": \"39180-5541\",\n \"country_code\": \"US\",\n \"state_province\": \"MS\",\n \"address_residential_indicator\": \"unknown\"\n },\n \"ship_from\": {\n \"name\": \"Fulfillment Center\",\n \"phone\": \"877-743-2269\",\n \"company_name\": \"BBQGuys\",\n \"address_line1\": \"8151 Airline Hwy\",\n \"city_locality\": \"Baton Rouge\",\n \"postal_code\": \"70815\",\n \"country_code\": \"US\",\n \"state_province\": \"LA\"\n },\n \"confirmation\": \"none\",\n \"packages\": [\n {\n \"weight\": {\n \"value\": 2,\n \"unit\": \"pound\"\n },\n \"dimensions\": {\n \"unit\": \"inch\",\n \"length\": 2,\n \"width\": 14,\n \"height\": 17\n }\n }\n ]\n }\n}")
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
}
req.Header.Add("Host", "api.shipengine.com")
req.Header.Add("API-Key", "__YOUR_API_KEY_HERE__")
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
#import <Foundation/Foundation.h>
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.shipengine.com/v1/labels"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
NSDictionary *headers = @{
@"Host": @"api.shipengine.com",
@"API-Key": @"__YOUR_API_KEY_HERE__",
@"Content-Type": @"application/json"
};
[request setAllHTTPHeaderFields:headers];
NSData *postData = [[NSData alloc] initWithData:[@"{\n \"shipment\": {\n \"advanced_options\": {\n \"collect_on_delivery\": {\n \"payment_type\": \"any\",\n \"payment_amount\": {\n \"amount\": 10.7,\n \"currency\": \"usd\"\n }\n }\n },\n \"service_code\": \"ups_ground\",\n \"external_shipment_id\": \"__YOUR_EXTERNAL_ID_HERE__\",\n \"ship_to\": {\n \"name\": \"John Stuckey\",\n \"phone\": \"6625905259\",\n \"company_name\": \"John Stuckey\",\n \"address_line1\": \"3412 Pemberton Square Blvd\",\n \"address_line2\": \"Ste 2-241\",\n \"city_locality\": \"VICKSBURG\",\n \"postal_code\": \"39180-5541\",\n \"country_code\": \"US\",\n \"state_province\": \"MS\",\n \"address_residential_indicator\": \"unknown\"\n },\n \"ship_from\": {\n \"name\": \"Fulfillment Center\",\n \"phone\": \"877-743-2269\",\n \"company_name\": \"BBQGuys\",\n \"address_line1\": \"8151 Airline Hwy\",\n \"city_locality\": \"Baton Rouge\",\n \"postal_code\": \"70815\",\n \"country_code\": \"US\",\n \"state_province\": \"LA\"\n },\n \"confirmation\": \"none\",\n \"packages\": [\n {\n \"weight\": {\n \"value\": 2,\n \"unit\": \"pound\"\n },\n \"dimensions\": {\n \"unit\": \"inch\",\n \"length\": 2,\n \"width\": 14,\n \"height\": 17\n }\n }\n ]\n }\n}" dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postData];
[request setHTTPMethod:@"POST"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSError *parseError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
NSLog(@"%@",responseDictionary);
dispatch_semaphore_signal(sema);
}
}];
[dataTask resume];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
import Foundation
var semaphore = DispatchSemaphore (value: 0)
let parameters = "{\n \"shipment\": {\n \"advanced_options\": {\n \"collect_on_delivery\": {\n \"payment_type\": \"any\",\n \"payment_amount\": {\n \"amount\": 10.7,\n \"currency\": \"usd\"\n }\n }\n },\n \"service_code\": \"ups_ground\",\n \"external_shipment_id\": \"__YOUR_EXTERNAL_ID_HERE__\",\n \"ship_to\": {\n \"name\": \"John Stuckey\",\n \"phone\": \"6625905259\",\n \"company_name\": \"John Stuckey\",\n \"address_line1\": \"3412 Pemberton Square Blvd\",\n \"address_line2\": \"Ste 2-241\",\n \"city_locality\": \"VICKSBURG\",\n \"postal_code\": \"39180-5541\",\n \"country_code\": \"US\",\n \"state_province\": \"MS\",\n \"address_residential_indicator\": \"unknown\"\n },\n \"ship_from\": {\n \"name\": \"Fulfillment Center\",\n \"phone\": \"877-743-2269\",\n \"company_name\": \"BBQGuys\",\n \"address_line1\": \"8151 Airline Hwy\",\n \"city_locality\": \"Baton Rouge\",\n \"postal_code\": \"70815\",\n \"country_code\": \"US\",\n \"state_province\": \"LA\"\n },\n \"confirmation\": \"none\",\n \"packages\": [\n {\n \"weight\": {\n \"value\": 2,\n \"unit\": \"pound\"\n },\n \"dimensions\": {\n \"unit\": \"inch\",\n \"length\": 2,\n \"width\": 14,\n \"height\": 17\n }\n }\n ]\n }\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.shipengine.com/v1/labels")!,timeoutInterval: Double.infinity)
request.addValue("api.shipengine.com", forHTTPHeaderField: "Host")
request.addValue("__YOUR_API_KEY_HERE__", forHTTPHeaderField: "API-Key")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
return
}
print(String(data: data, encoding: .utf8)!)
semaphore.signal()
}
task.resume()
semaphore.wait()
The collect on delivery payment option is not shown in the response from creating a label.
{
"label_id": "se-6615",
"status": "completed",
"shipment_id": "se-1020115",
"ship_date": "2019-09-26T00:00:00Z",
"created_at": "2019-09-26T17:48:59.2732285Z",
"shipment_cost": {
"currency": "usd",
"amount": 27.27
},
"insurance_cost": {
"currency": "usd",
"amount": 0.0
},
"tracking_number": "1Z14Y0487211178222",
"is_return_label": false,
"rma_number": null,
"is_international": false,
"batch_id": "",
"carrier_id": "se-95",
"service_code": "ups_ground",
"package_code": "package",
"voided": false,
"voided_at": null,
"label_format": "pdf",
"label_layout": "4x6",
"trackable": true,
"carrier_code": "ups",
"tracking_status": "in_transit",
"label_download": {
"pdf": "http://localhost:55163/v1/downloads/1/7OC4emEGkEmtutHwzbhvwg/label-6615.pdf",
"png": "http://localhost:55163/v1/downloads/1/7OC4emEGkEmtutHwzbhvwg/label-6615.png",
"zpl": "http://localhost:55163/v1/downloads/1/7OC4emEGkEmtutHwzbhvwg/label-6615.zpl",
"href": "http://localhost:55163/v1/downloads/1/7OC4emEGkEmtutHwzbhvwg/label-6615.pdf"
},
"form_download": null,
"insurance_claim": null,
"packages": [
{
"package_code": "package",
"weight": {
"value": 2.00,
"unit": "pound"
},
"dimensions": {
"unit": "inch",
"length": 2.00,
"width": 14.00,
"height": 17.00
},
"insured_value": {
"currency": "usd",
"amount": 0.00
},
"tracking_number": "1Z14Y0487211178222",
"label_messages": {
"reference1": null,
"reference2": null,
"reference3": null
},
"external_package_id": null
}
]
}
{
"label_id": "se-6615",
"status": "completed",
"shipment_id": "se-1020115",
"ship_date": "2019-09-26T00:00:00Z",
"created_at": "2019-09-26T17:48:59.2732285Z",
"shipment_cost": {
"currency": "usd",
"amount": 27.27
},
"insurance_cost": {
"currency": "usd",
"amount": 0.0
},
"tracking_number": "1Z14Y0487211178222",
"is_return_label": false,
"rma_number": null,
"is_international": false,
"batch_id": "",
"carrier_id": "se-95",
"service_code": "ups_ground",
"package_code": "package",
"voided": false,
"voided_at": null,
"label_format": "pdf",
"label_layout": "4x6",
"trackable": true,
"carrier_code": "ups",
"tracking_status": "in_transit",
"label_download": {
"pdf": "http://localhost:55163/v1/downloads/1/7OC4emEGkEmtutHwzbhvwg/label-6615.pdf",
"png": "http://localhost:55163/v1/downloads/1/7OC4emEGkEmtutHwzbhvwg/label-6615.png",
"zpl": "http://localhost:55163/v1/downloads/1/7OC4emEGkEmtutHwzbhvwg/label-6615.zpl",
"href": "http://localhost:55163/v1/downloads/1/7OC4emEGkEmtutHwzbhvwg/label-6615.pdf"
},
"form_download": null,
"insurance_claim": null,
"packages": [
{
"package_code": "package",
"weight": {
"value": 2.00,
"unit": "pound"
},
"dimensions": {
"unit": "inch",
"length": 2.00,
"width": 14.00,
"height": 17.00
},
"insured_value": {
"currency": "usd",
"amount": 0.00
},
"tracking_number": "1Z14Y0487211178222",
"label_messages": {
"reference1": null,
"reference2": null,
"reference3": null
},
"external_package_id": null
}
]
}