Split Ship a Sales Order
Use a Sales Order with Multiple Sales Order Items
GET /v-beta/sales_orders/0d3c142a-7516-5f5b-8a40-b437b5e01317 HTTP/1.1
Host: api.shipengine.com
API-Key: __YOUR_API_KEY_HERE__
curl -iX GET https://api.shipengine.com/v-beta/sales_orders/0d3c142a-7516-5f5b-8a40-b437b5e01317 \
-H 'API-Key: __YOUR_API_KEY_HERE__' \
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Host", "api.shipengine.com")
$headers.Add("API-Key", "__YOUR_API_KEY_HERE__")
$response = Invoke-RestMethod 'https://api.shipengine.com/v-beta/sales_orders/0d3c142a-7516-5f5b-8a40-b437b5e01317' -Method 'GET' -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__");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://api.shipengine.com/v-beta/sales_orders/0d3c142a-7516-5f5b-8a40-b437b5e01317", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
var request = require('request');
var options = {
'method': 'GET',
'url': 'https://api.shipengine.com/v-beta/sales_orders/0d3c142a-7516-5f5b-8a40-b437b5e01317',
'headers': {
'Host': 'api.shipengine.com',
'API-Key': '__YOUR_API_KEY_HERE__'
}
};
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/v-beta/sales_orders/0d3c142a-7516-5f5b-8a40-b437b5e01317",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Host: api.shipengine.com",
"API-Key: __YOUR_API_KEY_HERE__"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
url = "https://api.shipengine.com/v-beta/sales_orders/0d3c142a-7516-5f5b-8a40-b437b5e01317"
payload = {}
headers = {
'Host': 'api.shipengine.com',
'API-Key': '__YOUR_API_KEY_HERE__'
}
response = requests.request("GET", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
require "uri"
require "net/http"
url = URI("https://api.shipengine.com/v-beta/sales_orders/0d3c142a-7516-5f5b-8a40-b437b5e01317")
https = Net::HTTP.new(url.host, url.port);
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Host"] = "api.shipengine.com"
request["API-Key"] = "__YOUR_API_KEY_HERE__"
response = https.request(request)
puts response.read_body
var client = new RestClient("https://api.shipengine.com/v-beta/sales_orders/0d3c142a-7516-5f5b-8a40-b437b5e01317");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Host", "api.shipengine.com");
request.AddHeader("API-Key", "__YOUR_API_KEY_HERE__");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
Request request = new Request.Builder()
.url("https://api.shipengine.com/v-beta/sales_orders/0d3c142a-7516-5f5b-8a40-b437b5e01317")
.method("GET", null)
.addHeader("Host", "api.shipengine.com")
.addHeader("API-Key", "__YOUR_API_KEY_HERE__")
.build();
Response response = client.newCall(request).execute();
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.shipengine.com/v-beta/sales_orders/0d3c142a-7516-5f5b-8a40-b437b5e01317"
method := "GET"
client := &http.Client {
}
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
}
req.Header.Add("Host", "api.shipengine.com")
req.Header.Add("API-Key", "__YOUR_API_KEY_HERE__")
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/v-beta/sales_orders/0d3c142a-7516-5f5b-8a40-b437b5e01317"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
NSDictionary *headers = @{
@"Host": @"api.shipengine.com",
@"API-Key": @"__YOUR_API_KEY_HERE__"
};
[request setAllHTTPHeaderFields:headers];
[request setHTTPMethod:@"GET"];
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)
var request = URLRequest(url: URL(string: "https://api.shipengine.com/v-beta/sales_orders/0d3c142a-7516-5f5b-8a40-b437b5e01317")!,timeoutInterval: Double.infinity)
request.addValue("api.shipengine.com", forHTTPHeaderField: "Host")
request.addValue("__YOUR_API_KEY_HERE__", forHTTPHeaderField: "API-Key")
request.httpMethod = "GET"
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()
Create a Shipment for the First Item
POST /v-beta/shipments HTTP/1.1
Host: api.shipengine.com
API-Key: __YOUR_API_KEY_HERE__
Content-Type: application/json
{
"shipments": [
{
"validate_address": "validate_and_clean",
"carrier_id": "se-123890",
"service_code": "usps_priority_mail",
"warehouse_id": "se-241419",
"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"
},
"packages": [
{
"package_code": "package",
"weight": {
"value": 1.0,
"unit": "ounce"
}
}
],
"items": [
{
"sales_order_id": "0d3c142a-7516-5f5b-8a40-b437b5e01317",
"sales_order_item_id": "0399c595-774a-599b-a566-27ea86fec17d",
"quantity": 1
}
]
}
]
}
curl -iX POST https://api.shipengine.com/v-beta/shipments \
-H 'API-Key: __YOUR_API_KEY_HERE__' \
-H 'Content-Type: application/json' \
-d '{
"shipments": [
{
"validate_address": "validate_and_clean",
"carrier_id": "se-123890",
"service_code": "usps_priority_mail",
"warehouse_id": "se-241419",
"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"
},
"packages": [
{
"package_code": "package",
"weight": {
"value": 1.0,
"unit": "ounce"
}
}
],
"items": [
{
"sales_order_id": "0d3c142a-7516-5f5b-8a40-b437b5e01317",
"sales_order_item_id": "0399c595-774a-599b-a566-27ea86fec17d",
"quantity": 1
}
]
}
]
}'
$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 `"validate_address`": `"validate_and_clean`",`n `"carrier_id`": `"se-123890`",`n `"service_code`": `"usps_priority_mail`",`n `"warehouse_id`": `"se-241419`",`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 `"packages`": [`n {`n `"package_code`": `"package`",`n `"weight`": {`n `"value`": 1.0,`n `"unit`": `"ounce`"`n }`n }`n ],`n `"items`": [`n {`n `"sales_order_id`": `"0d3c142a-7516-5f5b-8a40-b437b5e01317`",`n `"sales_order_item_id`": `"0399c595-774a-599b-a566-27ea86fec17d`",`n `"quantity`": 1`n }`n ]`n }`n ]`n}"
$response = Invoke-RestMethod 'https://api.shipengine.com/v-beta/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":[{"validate_address":"validate_and_clean","carrier_id":"se-123890","service_code":"usps_priority_mail","warehouse_id":"se-241419","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"},"packages":[{"package_code":"package","weight":{"value":1,"unit":"ounce"}}],"items":[{"sales_order_id":"0d3c142a-7516-5f5b-8a40-b437b5e01317","sales_order_item_id":"0399c595-774a-599b-a566-27ea86fec17d","quantity":1}]}]});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.shipengine.com/v-beta/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/v-beta/shipments',
'headers': {
'Host': 'api.shipengine.com',
'API-Key': '__YOUR_API_KEY_HERE__',
'Content-Type': 'application/json'
},
body: JSON.stringify({"shipments":[{"validate_address":"validate_and_clean","carrier_id":"se-123890","service_code":"usps_priority_mail","warehouse_id":"se-241419","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"},"packages":[{"package_code":"package","weight":{"value":1,"unit":"ounce"}}],"items":[{"sales_order_id":"0d3c142a-7516-5f5b-8a40-b437b5e01317","sales_order_item_id":"0399c595-774a-599b-a566-27ea86fec17d","quantity":1}]}]})
};
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/v-beta/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 \"validate_address\": \"validate_and_clean\",\n \"carrier_id\": \"se-123890\",\n \"service_code\": \"usps_priority_mail\",\n \"warehouse_id\": \"se-241419\",\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 \"packages\": [\n {\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n }\n }\n ],\n \"items\": [\n {\n \"sales_order_id\": \"0d3c142a-7516-5f5b-8a40-b437b5e01317\",\n \"sales_order_item_id\": \"0399c595-774a-599b-a566-27ea86fec17d\",\n \"quantity\": 1\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/v-beta/shipments"
payload = "{\n \"shipments\": [\n {\n \"validate_address\": \"validate_and_clean\",\n \"carrier_id\": \"se-123890\",\n \"service_code\": \"usps_priority_mail\",\n \"warehouse_id\": \"se-241419\",\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 \"packages\": [\n {\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n }\n }\n ],\n \"items\": [\n {\n \"sales_order_id\": \"0d3c142a-7516-5f5b-8a40-b437b5e01317\",\n \"sales_order_item_id\": \"0399c595-774a-599b-a566-27ea86fec17d\",\n \"quantity\": 1\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/v-beta/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 \"validate_address\": \"validate_and_clean\",\n \"carrier_id\": \"se-123890\",\n \"service_code\": \"usps_priority_mail\",\n \"warehouse_id\": \"se-241419\",\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 \"packages\": [\n {\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n }\n }\n ],\n \"items\": [\n {\n \"sales_order_id\": \"0d3c142a-7516-5f5b-8a40-b437b5e01317\",\n \"sales_order_item_id\": \"0399c595-774a-599b-a566-27ea86fec17d\",\n \"quantity\": 1\n }\n ]\n }\n ]\n}"
response = https.request(request)
puts response.read_body
var client = new RestClient("https://api.shipengine.com/v-beta/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 \"validate_address\": \"validate_and_clean\",\n \"carrier_id\": \"se-123890\",\n \"service_code\": \"usps_priority_mail\",\n \"warehouse_id\": \"se-241419\",\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 \"packages\": [\n {\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n }\n }\n ],\n \"items\": [\n {\n \"sales_order_id\": \"0d3c142a-7516-5f5b-8a40-b437b5e01317\",\n \"sales_order_item_id\": \"0399c595-774a-599b-a566-27ea86fec17d\",\n \"quantity\": 1\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 \"validate_address\": \"validate_and_clean\",\n \"carrier_id\": \"se-123890\",\n \"service_code\": \"usps_priority_mail\",\n \"warehouse_id\": \"se-241419\",\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 \"packages\": [\n {\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n }\n }\n ],\n \"items\": [\n {\n \"sales_order_id\": \"0d3c142a-7516-5f5b-8a40-b437b5e01317\",\n \"sales_order_item_id\": \"0399c595-774a-599b-a566-27ea86fec17d\",\n \"quantity\": 1\n }\n ]\n }\n ]\n}");
Request request = new Request.Builder()
.url("https://api.shipengine.com/v-beta/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/v-beta/shipments"
method := "POST"
payload := strings.NewReader("{\n \"shipments\": [\n {\n \"validate_address\": \"validate_and_clean\",\n \"carrier_id\": \"se-123890\",\n \"service_code\": \"usps_priority_mail\",\n \"warehouse_id\": \"se-241419\",\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 \"packages\": [\n {\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n }\n }\n ],\n \"items\": [\n {\n \"sales_order_id\": \"0d3c142a-7516-5f5b-8a40-b437b5e01317\",\n \"sales_order_item_id\": \"0399c595-774a-599b-a566-27ea86fec17d\",\n \"quantity\": 1\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/v-beta/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 \"validate_address\": \"validate_and_clean\",\n \"carrier_id\": \"se-123890\",\n \"service_code\": \"usps_priority_mail\",\n \"warehouse_id\": \"se-241419\",\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 \"packages\": [\n {\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n }\n }\n ],\n \"items\": [\n {\n \"sales_order_id\": \"0d3c142a-7516-5f5b-8a40-b437b5e01317\",\n \"sales_order_item_id\": \"0399c595-774a-599b-a566-27ea86fec17d\",\n \"quantity\": 1\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 \"validate_address\": \"validate_and_clean\",\n \"carrier_id\": \"se-123890\",\n \"service_code\": \"usps_priority_mail\",\n \"warehouse_id\": \"se-241419\",\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 \"packages\": [\n {\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n }\n }\n ],\n \"items\": [\n {\n \"sales_order_id\": \"0d3c142a-7516-5f5b-8a40-b437b5e01317\",\n \"sales_order_item_id\": \"0399c595-774a-599b-a566-27ea86fec17d\",\n \"quantity\": 1\n }\n ]\n }\n ]\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.shipengine.com/v-beta/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()
{
"has_errors": false,
"shipments": [
{
"sales_order_ids": [],
"items": [
{
"sales_order_id": "0d3c142a-7516-5f5b-8a40-b437b5e01317",
"sales_order_item_id": "0399c595-774a-599b-a566-27ea86fec17d",
"quantity": 1,
"name": "",
"sku": null,
"created_at": "2019-07-25T15:24:46.657Z",
"modified_at": "2019-07-25T15:24:46.657Z"
}
],
"errors": [],
"address_validation": {
"status": "verified",
"original_address": {
"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"
},
"matched_address": {
"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"
},
"messages": []
},
"shipment_id": "se-201053690",
"carrier_id": "se-123890",
"service_code": "usps_priority_mail",
"external_shipment_id": null,
"ship_date": "2019-07-25T05:00:00.000Z",
"created_at": "2019-07-25T15:24:46.657Z",
"modified_at": "2019-07-25T15:24:46.657Z",
"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": "se-241419",
"return_to": {
"name": "Example Corp. Returns",
"phone": "222-222-2222",
"company_name": "Example Corp.",
"address_line1": "345 Chambers Street",
"address_line2": "Suite 100",
"address_line3": null,
"city_locality": "New York City",
"state_province": "NY",
"postal_code": "10282",
"country_code": "US",
"address_residential_indicator": "unknown"
},
"confirmation": "none",
"customs": null,
"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,
"freight_class": null,
"custom_field1": null,
"custom_field2": null,
"custom_field3": 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
}
}
],
"total_weight": {
"value": 1.0,
"unit": "ounce"
}
}
]
}
{
"has_errors": false,
"shipments": [
{
"sales_order_ids": [],
"items": [
{
"sales_order_id": "0d3c142a-7516-5f5b-8a40-b437b5e01317",
"sales_order_item_id": "0399c595-774a-599b-a566-27ea86fec17d",
"quantity": 1,
"name": "",
"sku": null,
"created_at": "2019-07-25T15:24:46.657Z",
"modified_at": "2019-07-25T15:24:46.657Z"
}
],
"errors": [],
"address_validation": {
"status": "verified",
"original_address": {
"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"
},
"matched_address": {
"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"
},
"messages": []
},
"shipment_id": "se-201053690",
"carrier_id": "se-123890",
"service_code": "usps_priority_mail",
"external_shipment_id": null,
"ship_date": "2019-07-25T05:00:00.000Z",
"created_at": "2019-07-25T15:24:46.657Z",
"modified_at": "2019-07-25T15:24:46.657Z",
"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": "se-241419",
"return_to": {
"name": "Example Corp. Returns",
"phone": "222-222-2222",
"company_name": "Example Corp.",
"address_line1": "345 Chambers Street",
"address_line2": "Suite 100",
"address_line3": null,
"city_locality": "New York City",
"state_province": "NY",
"postal_code": "10282",
"country_code": "US",
"address_residential_indicator": "unknown"
},
"confirmation": "none",
"customs": null,
"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,
"freight_class": null,
"custom_field1": null,
"custom_field2": null,
"custom_field3": 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
}
}
],
"total_weight": {
"value": 1.0,
"unit": "ounce"
}
}
]
}
Create a Shipment for the Second Item
POST /v-beta/shipments HTTP/1.1
Host: api.shipengine.com
API-Key: __YOUR_API_KEY_HERE__
Content-Type: application/json
{
"shipments": [
{
"validate_address": "validate_and_clean",
"carrier_id": "se-123890",
"service_code": "usps_priority_mail",
"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"
},
"warehouse_id": "se-241419",
"packages": [
{
"package_code": "package",
"weight": {
"value": 1.0,
"unit": "ounce"
}
}
],
"items": [
{
"sales_order_id": "0d3c142a-7516-5f5b-8a40-b437b5e01317",
"sales_order_item_id": "4afd6df4-d679-51d7-a858-8aff7d6103c2",
"quantity": 1
}
]
}
]
}
curl -iX POST https://api.shipengine.com/v-beta/shipments \
-H 'API-Key: __YOUR_API_KEY_HERE__' \
-H 'Content-Type: application/json' \
-d '{
"shipments": [
{
"validate_address": "validate_and_clean",
"carrier_id": "se-123890",
"service_code": "usps_priority_mail",
"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"
},
"warehouse_id": "se-241419",
"packages": [
{
"package_code": "package",
"weight": {
"value": 1.0,
"unit": "ounce"
}
}
],
"items": [
{
"sales_order_id": "0d3c142a-7516-5f5b-8a40-b437b5e01317",
"sales_order_item_id": "4afd6df4-d679-51d7-a858-8aff7d6103c2",
"quantity": 1
}
]
}
]
}'
$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 `"validate_address`": `"validate_and_clean`",`n `"carrier_id`": `"se-123890`",`n `"service_code`": `"usps_priority_mail`",`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 `"warehouse_id`": `"se-241419`",`n `"packages`": [`n {`n `"package_code`": `"package`",`n `"weight`": {`n `"value`": 1.0,`n `"unit`": `"ounce`"`n }`n }`n ],`n `"items`": [`n {`n `"sales_order_id`": `"0d3c142a-7516-5f5b-8a40-b437b5e01317`",`n `"sales_order_item_id`": `"4afd6df4-d679-51d7-a858-8aff7d6103c2`",`n `"quantity`": 1`n }`n ]`n }`n ]`n}"
$response = Invoke-RestMethod 'https://api.shipengine.com/v-beta/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":[{"validate_address":"validate_and_clean","carrier_id":"se-123890","service_code":"usps_priority_mail","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"},"warehouse_id":"se-241419","packages":[{"package_code":"package","weight":{"value":1,"unit":"ounce"}}],"items":[{"sales_order_id":"0d3c142a-7516-5f5b-8a40-b437b5e01317","sales_order_item_id":"4afd6df4-d679-51d7-a858-8aff7d6103c2","quantity":1}]}]});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.shipengine.com/v-beta/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/v-beta/shipments',
'headers': {
'Host': 'api.shipengine.com',
'API-Key': '__YOUR_API_KEY_HERE__',
'Content-Type': 'application/json'
},
body: JSON.stringify({"shipments":[{"validate_address":"validate_and_clean","carrier_id":"se-123890","service_code":"usps_priority_mail","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"},"warehouse_id":"se-241419","packages":[{"package_code":"package","weight":{"value":1,"unit":"ounce"}}],"items":[{"sales_order_id":"0d3c142a-7516-5f5b-8a40-b437b5e01317","sales_order_item_id":"4afd6df4-d679-51d7-a858-8aff7d6103c2","quantity":1}]}]})
};
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/v-beta/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 \"validate_address\": \"validate_and_clean\",\n \"carrier_id\": \"se-123890\",\n \"service_code\": \"usps_priority_mail\",\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 \"warehouse_id\": \"se-241419\",\n \"packages\": [\n {\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n }\n }\n ],\n \"items\": [\n {\n \"sales_order_id\": \"0d3c142a-7516-5f5b-8a40-b437b5e01317\",\n \"sales_order_item_id\": \"4afd6df4-d679-51d7-a858-8aff7d6103c2\",\n \"quantity\": 1\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/v-beta/shipments"
payload = "{\n \"shipments\": [\n {\n \"validate_address\": \"validate_and_clean\",\n \"carrier_id\": \"se-123890\",\n \"service_code\": \"usps_priority_mail\",\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 \"warehouse_id\": \"se-241419\",\n \"packages\": [\n {\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n }\n }\n ],\n \"items\": [\n {\n \"sales_order_id\": \"0d3c142a-7516-5f5b-8a40-b437b5e01317\",\n \"sales_order_item_id\": \"4afd6df4-d679-51d7-a858-8aff7d6103c2\",\n \"quantity\": 1\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/v-beta/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 \"validate_address\": \"validate_and_clean\",\n \"carrier_id\": \"se-123890\",\n \"service_code\": \"usps_priority_mail\",\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 \"warehouse_id\": \"se-241419\",\n \"packages\": [\n {\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n }\n }\n ],\n \"items\": [\n {\n \"sales_order_id\": \"0d3c142a-7516-5f5b-8a40-b437b5e01317\",\n \"sales_order_item_id\": \"4afd6df4-d679-51d7-a858-8aff7d6103c2\",\n \"quantity\": 1\n }\n ]\n }\n ]\n}"
response = https.request(request)
puts response.read_body
var client = new RestClient("https://api.shipengine.com/v-beta/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 \"validate_address\": \"validate_and_clean\",\n \"carrier_id\": \"se-123890\",\n \"service_code\": \"usps_priority_mail\",\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 \"warehouse_id\": \"se-241419\",\n \"packages\": [\n {\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n }\n }\n ],\n \"items\": [\n {\n \"sales_order_id\": \"0d3c142a-7516-5f5b-8a40-b437b5e01317\",\n \"sales_order_item_id\": \"4afd6df4-d679-51d7-a858-8aff7d6103c2\",\n \"quantity\": 1\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 \"validate_address\": \"validate_and_clean\",\n \"carrier_id\": \"se-123890\",\n \"service_code\": \"usps_priority_mail\",\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 \"warehouse_id\": \"se-241419\",\n \"packages\": [\n {\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n }\n }\n ],\n \"items\": [\n {\n \"sales_order_id\": \"0d3c142a-7516-5f5b-8a40-b437b5e01317\",\n \"sales_order_item_id\": \"4afd6df4-d679-51d7-a858-8aff7d6103c2\",\n \"quantity\": 1\n }\n ]\n }\n ]\n}");
Request request = new Request.Builder()
.url("https://api.shipengine.com/v-beta/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/v-beta/shipments"
method := "POST"
payload := strings.NewReader("{\n \"shipments\": [\n {\n \"validate_address\": \"validate_and_clean\",\n \"carrier_id\": \"se-123890\",\n \"service_code\": \"usps_priority_mail\",\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 \"warehouse_id\": \"se-241419\",\n \"packages\": [\n {\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n }\n }\n ],\n \"items\": [\n {\n \"sales_order_id\": \"0d3c142a-7516-5f5b-8a40-b437b5e01317\",\n \"sales_order_item_id\": \"4afd6df4-d679-51d7-a858-8aff7d6103c2\",\n \"quantity\": 1\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/v-beta/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 \"validate_address\": \"validate_and_clean\",\n \"carrier_id\": \"se-123890\",\n \"service_code\": \"usps_priority_mail\",\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 \"warehouse_id\": \"se-241419\",\n \"packages\": [\n {\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n }\n }\n ],\n \"items\": [\n {\n \"sales_order_id\": \"0d3c142a-7516-5f5b-8a40-b437b5e01317\",\n \"sales_order_item_id\": \"4afd6df4-d679-51d7-a858-8aff7d6103c2\",\n \"quantity\": 1\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 \"validate_address\": \"validate_and_clean\",\n \"carrier_id\": \"se-123890\",\n \"service_code\": \"usps_priority_mail\",\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 \"warehouse_id\": \"se-241419\",\n \"packages\": [\n {\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n }\n }\n ],\n \"items\": [\n {\n \"sales_order_id\": \"0d3c142a-7516-5f5b-8a40-b437b5e01317\",\n \"sales_order_item_id\": \"4afd6df4-d679-51d7-a858-8aff7d6103c2\",\n \"quantity\": 1\n }\n ]\n }\n ]\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.shipengine.com/v-beta/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()
{
"has_errors": false,
"shipments": [
{
"sales_order_ids": [],
"items": [
{
"sales_order_id": "0d3c142a-7516-5f5b-8a40-b437b5e01317",
"sales_order_item_id": "4afd6df4-d679-51d7-a858-8aff7d6103c2",
"quantity": 1,
"name": "",
"sku": null,
"created_at": "2019-07-25T15:24:46.657Z",
"modified_at": "2019-07-25T15:24:46.657Z"
}
],
"errors": [],
"address_validation": {
"status": "verified",
"original_address": {
"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"
},
"matched_address": {
"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"
},
"messages": []
},
"shipment_id": "se-201055037",
"carrier_id": "se-123890",
"service_code": "usps_priority_mail",
"external_shipment_id": null,
"ship_date": "2019-07-25T05:00:00.000Z",
"created_at": "2019-07-25T15:24:46.657Z",
"modified_at": "2019-07-25T15:24:46.657Z",
"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": "se-241419",
"return_to": {
"name": "Example Corp. Returns",
"phone": "222-222-2222",
"company_name": "Example Corp.",
"address_line1": "345 Chambers Street",
"address_line2": "Suite 100",
"address_line3": null,
"city_locality": "New York City",
"state_province": "NY",
"postal_code": "10282",
"country_code": "US",
"address_residential_indicator": "unknown"
},
"confirmation": "none",
"customs": null,
"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,
"freight_class": null,
"custom_field1": null,
"custom_field2": null,
"custom_field3": 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
}
}
],
"total_weight": {
"value": 1.0,
"unit": "ounce"
}
}
]
}
{
"has_errors": false,
"shipments": [
{
"sales_order_ids": [],
"items": [
{
"sales_order_id": "0d3c142a-7516-5f5b-8a40-b437b5e01317",
"sales_order_item_id": "4afd6df4-d679-51d7-a858-8aff7d6103c2",
"quantity": 1,
"name": "",
"sku": null,
"created_at": "2019-07-25T15:24:46.657Z",
"modified_at": "2019-07-25T15:24:46.657Z"
}
],
"errors": [],
"address_validation": {
"status": "verified",
"original_address": {
"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"
},
"matched_address": {
"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"
},
"messages": []
},
"shipment_id": "se-201055037",
"carrier_id": "se-123890",
"service_code": "usps_priority_mail",
"external_shipment_id": null,
"ship_date": "2019-07-25T05:00:00.000Z",
"created_at": "2019-07-25T15:24:46.657Z",
"modified_at": "2019-07-25T15:24:46.657Z",
"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": "se-241419",
"return_to": {
"name": "Example Corp. Returns",
"phone": "222-222-2222",
"company_name": "Example Corp.",
"address_line1": "345 Chambers Street",
"address_line2": "Suite 100",
"address_line3": null,
"city_locality": "New York City",
"state_province": "NY",
"postal_code": "10282",
"country_code": "US",
"address_residential_indicator": "unknown"
},
"confirmation": "none",
"customs": null,
"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,
"freight_class": null,
"custom_field1": null,
"custom_field2": null,
"custom_field3": 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
}
}
],
"total_weight": {
"value": 1.0,
"unit": "ounce"
}
}
]
}
Create Labels for the Shipments
POST /v1/labels/shipment/se-201053690 HTTP/1.1
Host: api.shipengine.com
API-Key: __YOUR_API_KEY_HERE__
Content-Type: application/json
{
"label_format":"pdf"
}
curl -iX POST https://api.shipengine.com/v1/labels/shipment/se-201053690 \
-H 'API-Key: __YOUR_API_KEY_HERE__' \
-H 'Content-Type: application/json' \
-d '{
"label_format":"pdf"
}'
$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 `"label_format`":`"pdf`"`n}"
$response = Invoke-RestMethod 'https://api.shipengine.com/v1/labels/shipment/se-201053690' -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({"label_format":"pdf"});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.shipengine.com/v1/labels/shipment/se-201053690", 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/shipment/se-201053690',
'headers': {
'Host': 'api.shipengine.com',
'API-Key': '__YOUR_API_KEY_HERE__',
'Content-Type': 'application/json'
},
body: JSON.stringify({"label_format":"pdf"})
};
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/shipment/se-201053690",
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 \"label_format\":\"pdf\"\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/shipment/se-201053690"
payload = "{\n \"label_format\":\"pdf\"\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/shipment/se-201053690")
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 \"label_format\":\"pdf\"\n}"
response = https.request(request)
puts response.read_body
var client = new RestClient("https://api.shipengine.com/v1/labels/shipment/se-201053690");
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 \"label_format\":\"pdf\"\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 \"label_format\":\"pdf\"\n}");
Request request = new Request.Builder()
.url("https://api.shipengine.com/v1/labels/shipment/se-201053690")
.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/shipment/se-201053690"
method := "POST"
payload := strings.NewReader("{\n \"label_format\":\"pdf\"\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/shipment/se-201053690"]
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 \"label_format\":\"pdf\"\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 \"label_format\":\"pdf\"\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.shipengine.com/v1/labels/shipment/se-201053690")!,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()
{
"label_id": "se-test-201055037",
"status": "processing",
"shipment_id": "se-201055037",
"ship_date": "2019-07-25T05:00:00.000Z",
"created_at": "2019-07-25T15:24:46.657Z",
"shipment_cost": {
"currency": "usd",
"amount": 0.0
},
"insurance_cost": {
"currency": "usd",
"amount": 0.0
},
"tracking_number": "9999999999999",
"is_return_label": false,
"is_international": false,
"batch_id": "",
"carrier_id": "se-123890",
"service_code": "usps_priority_mail",
"package_code": "package",
"voided": false,
"voided_at": null,
"label_format": "pdf",
"label_layout": "4x6",
"trackable": true,
"carrier_code": "stamps_com",
"tracking_status": "unknown",
"label_download": {
"href": "https://api.shipengine.com/v1/downloads/6/xiceDRUJ4E-C8hOjeMfriQ/testlabel-201055037.pdf"
},
"form_download": null,
"insurance_claim": null,
"packages": [
{
"package_code": "package",
"weight": {
"value": 1.00,
"unit": "ounce"
},
"dimensions": {
"unit": "inch",
"length": 0.0,
"width": 0.0,
"height": 0.0
},
"insured_value": {
"currency": "usd",
"amount": 0.00
},
"tracking_number": null,
"label_messages": {
"reference1": null,
"reference2": null,
"reference3": null
}
}
]
}
{
"label_id": "se-test-201055037",
"status": "processing",
"shipment_id": "se-201055037",
"ship_date": "2019-07-25T05:00:00.000Z",
"created_at": "2019-07-25T15:24:46.657Z",
"shipment_cost": {
"currency": "usd",
"amount": 0.0
},
"insurance_cost": {
"currency": "usd",
"amount": 0.0
},
"tracking_number": "9999999999999",
"is_return_label": false,
"is_international": false,
"batch_id": "",
"carrier_id": "se-123890",
"service_code": "usps_priority_mail",
"package_code": "package",
"voided": false,
"voided_at": null,
"label_format": "pdf",
"label_layout": "4x6",
"trackable": true,
"carrier_code": "stamps_com",
"tracking_status": "unknown",
"label_download": {
"href": "https://api.shipengine.com/v1/downloads/6/xiceDRUJ4E-C8hOjeMfriQ/testlabel-201055037.pdf"
},
"form_download": null,
"insurance_claim": null,
"packages": [
{
"package_code": "package",
"weight": {
"value": 1.00,
"unit": "ounce"
},
"dimensions": {
"unit": "inch",
"length": 0.0,
"width": 0.0,
"height": 0.0
},
"insured_value": {
"currency": "usd",
"amount": 0.00
},
"tracking_number": null,
"label_messages": {
"reference1": null,
"reference2": null,
"reference3": null
}
}
]
}