When shipping internationally, various duties and tariffs may get applied to your packages depending on the country and type of product you are shipping. ShipEngine tells you exactly how much you can expect to pay. This is commonly referred to as the "fully landed shipping cost".
To accurately calculate the duties, tariffs, and other taxes for your shipment, ShipEngine needs to know the Harmonized Tariff Codes of the products in your shipment. You also need to set the calculate_tax_amount: true
flag to opt-in to this feature since there is additional cost involved.
POST /v1/rates HTTP/1.1
Host: api.shipengine.com
API-Key: __YOUR_API_KEY_HERE__
Content-Type: application/json
{
"rate_options": {
"carrier_ids": [
"se-82785"
],
"calculate_tax_amount": true
},
"shipment": {
"service_code": "usps_first_class_mail_international",
"customs": {
"contents": "merchandise",
"non_delivery": "treat_as_abandoned",
"customs_items": [
{
"harmonized_tariff_code": "0901.21",
"country_of_manufacture": "US",
"country_of_origin": "US",
"quantity": 2,
"description": "books",
"value": {
"currency": "usd",
"amount": 100
}
}
]
},
"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"
},
"ship_to": {
"name": "Amanda Miller",
"phone": "20 5555 5555",
"address_line1": "77 Netherpark Crescent",
"address_line2": "Suite 100",
"city_locality": "London",
"state_province": "N/A",
"postal_code": "ABC 123",
"country_code": "GB",
"address_residential_indicator": "yes"
},
"packages": [
{
"weight": {
"value": 9.6,
"unit": "ounce"
},
"dimensions": {
"unit": "inch",
"length": 12,
"width": 7.1,
"height": 6
}
}
]
}
}
curl -iX POST https://api.shipengine.com/v1/rates \
-H 'API-Key: __YOUR_API_KEY_HERE__' \
-H 'Content-Type: application/json' \
-d '{
"rate_options": {
"carrier_ids": [
"se-82785"
],
"calculate_tax_amount": true
},
"shipment": {
"service_code": "usps_first_class_mail_international",
"customs": {
"contents": "merchandise",
"non_delivery": "treat_as_abandoned",
"customs_items": [
{
"harmonized_tariff_code": "0901.21",
"country_of_manufacture": "US",
"country_of_origin": "US",
"quantity": 2,
"description": "books",
"value": {
"currency": "usd",
"amount": 100
}
}
]
},
"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"
},
"ship_to": {
"name": "Amanda Miller",
"phone": "20 5555 5555",
"address_line1": "77 Netherpark Crescent",
"address_line2": "Suite 100",
"city_locality": "London",
"state_province": "N/A",
"postal_code": "ABC 123",
"country_code": "GB",
"address_residential_indicator": "yes"
},
"packages": [
{
"weight": {
"value": 9.6,
"unit": "ounce"
},
"dimensions": {
"unit": "inch",
"length": 12,
"width": 7.1,
"height": 6
}
}
]
}
}'
$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 `"rate_options`": {`n `"carrier_ids`": [`n `"se-82785`"`n ],`n `"calculate_tax_amount`": true`n },`n `"shipment`": {`n `"service_code`": `"usps_first_class_mail_international`",`n `"customs`": {`n `"contents`": `"merchandise`",`n `"non_delivery`": `"treat_as_abandoned`",`n `"customs_items`": [`n {`n `"harmonized_tariff_code`": `"0901.21`",`n `"country_of_manufacture`": `"US`",`n `"country_of_origin`": `"US`",`n `"quantity`": 2,`n `"description`": `"books`",`n `"value`": {`n `"currency`": `"usd`",`n `"amount`": 100`n }`n }`n ]`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 `"ship_to`": {`n `"name`": `"Amanda Miller`",`n `"phone`": `"20 5555 5555`",`n `"address_line1`": `"77 Netherpark Crescent`",`n `"address_line2`": `"Suite 100`",`n `"city_locality`": `"London`",`n `"state_province`": `"N/A`",`n `"postal_code`": `"ABC 123`",`n `"country_code`": `"GB`",`n `"address_residential_indicator`": `"yes`"`n },`n `"packages`": [`n {`n `"weight`": {`n `"value`": 9.6,`n `"unit`": `"ounce`"`n },`n `"dimensions`": {`n `"unit`": `"inch`",`n `"length`": 12,`n `"width`": 7.1,`n `"height`": 6`n }`n }`n ]`n }`n}"
$response = Invoke-RestMethod 'https://api.shipengine.com/v1/rates' -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({"rate_options":{"carrier_ids":["se-82785"],"calculate_tax_amount":true},"shipment":{"service_code":"usps_first_class_mail_international","customs":{"contents":"merchandise","non_delivery":"treat_as_abandoned","customs_items":[{"harmonized_tariff_code":"0901.21","country_of_manufacture":"US","country_of_origin":"US","quantity":2,"description":"books","value":{"currency":"usd","amount":100}}]},"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"},"ship_to":{"name":"Amanda Miller","phone":"20 5555 5555","address_line1":"77 Netherpark Crescent","address_line2":"Suite 100","city_locality":"London","state_province":"N/A","postal_code":"ABC 123","country_code":"GB","address_residential_indicator":"yes"},"packages":[{"weight":{"value":9.6,"unit":"ounce"},"dimensions":{"unit":"inch","length":12,"width":7.1,"height":6}}]}});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.shipengine.com/v1/rates", 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/rates',
'headers': {
'Host': 'api.shipengine.com',
'API-Key': '__YOUR_API_KEY_HERE__',
'Content-Type': 'application/json'
},
body: JSON.stringify({"rate_options":{"carrier_ids":["se-82785"],"calculate_tax_amount":true},"shipment":{"service_code":"usps_first_class_mail_international","customs":{"contents":"merchandise","non_delivery":"treat_as_abandoned","customs_items":[{"harmonized_tariff_code":"0901.21","country_of_manufacture":"US","country_of_origin":"US","quantity":2,"description":"books","value":{"currency":"usd","amount":100}}]},"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"},"ship_to":{"name":"Amanda Miller","phone":"20 5555 5555","address_line1":"77 Netherpark Crescent","address_line2":"Suite 100","city_locality":"London","state_province":"N/A","postal_code":"ABC 123","country_code":"GB","address_residential_indicator":"yes"},"packages":[{"weight":{"value":9.6,"unit":"ounce"},"dimensions":{"unit":"inch","length":12,"width":7.1,"height":6}}]}})
};
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/rates",
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 \"rate_options\": {\n \"carrier_ids\": [\n \"se-82785\"\n ],\n \"calculate_tax_amount\": true\n },\n \"shipment\": {\n \"service_code\": \"usps_first_class_mail_international\",\n \"customs\": {\n \"contents\": \"merchandise\",\n \"non_delivery\": \"treat_as_abandoned\",\n \"customs_items\": [\n {\n \"harmonized_tariff_code\": \"0901.21\",\n \"country_of_manufacture\": \"US\",\n \"country_of_origin\": \"US\",\n \"quantity\": 2,\n \"description\": \"books\",\n \"value\": {\n \"currency\": \"usd\",\n \"amount\": 100\n }\n }\n ]\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 \"ship_to\": {\n \"name\": \"Amanda Miller\",\n \"phone\": \"20 5555 5555\",\n \"address_line1\": \"77 Netherpark Crescent\",\n \"address_line2\": \"Suite 100\",\n \"city_locality\": \"London\",\n \"state_province\": \"N/A\",\n \"postal_code\": \"ABC 123\",\n \"country_code\": \"GB\",\n \"address_residential_indicator\": \"yes\"\n },\n \"packages\": [\n {\n \"weight\": {\n \"value\": 9.6,\n \"unit\": \"ounce\"\n },\n \"dimensions\": {\n \"unit\": \"inch\",\n \"length\": 12,\n \"width\": 7.1,\n \"height\": 6\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/rates"
payload = "{\n \"rate_options\": {\n \"carrier_ids\": [\n \"se-82785\"\n ],\n \"calculate_tax_amount\": true\n },\n \"shipment\": {\n \"service_code\": \"usps_first_class_mail_international\",\n \"customs\": {\n \"contents\": \"merchandise\",\n \"non_delivery\": \"treat_as_abandoned\",\n \"customs_items\": [\n {\n \"harmonized_tariff_code\": \"0901.21\",\n \"country_of_manufacture\": \"US\",\n \"country_of_origin\": \"US\",\n \"quantity\": 2,\n \"description\": \"books\",\n \"value\": {\n \"currency\": \"usd\",\n \"amount\": 100\n }\n }\n ]\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 \"ship_to\": {\n \"name\": \"Amanda Miller\",\n \"phone\": \"20 5555 5555\",\n \"address_line1\": \"77 Netherpark Crescent\",\n \"address_line2\": \"Suite 100\",\n \"city_locality\": \"London\",\n \"state_province\": \"N/A\",\n \"postal_code\": \"ABC 123\",\n \"country_code\": \"GB\",\n \"address_residential_indicator\": \"yes\"\n },\n \"packages\": [\n {\n \"weight\": {\n \"value\": 9.6,\n \"unit\": \"ounce\"\n },\n \"dimensions\": {\n \"unit\": \"inch\",\n \"length\": 12,\n \"width\": 7.1,\n \"height\": 6\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/rates")
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 \"rate_options\": {\n \"carrier_ids\": [\n \"se-82785\"\n ],\n \"calculate_tax_amount\": true\n },\n \"shipment\": {\n \"service_code\": \"usps_first_class_mail_international\",\n \"customs\": {\n \"contents\": \"merchandise\",\n \"non_delivery\": \"treat_as_abandoned\",\n \"customs_items\": [\n {\n \"harmonized_tariff_code\": \"0901.21\",\n \"country_of_manufacture\": \"US\",\n \"country_of_origin\": \"US\",\n \"quantity\": 2,\n \"description\": \"books\",\n \"value\": {\n \"currency\": \"usd\",\n \"amount\": 100\n }\n }\n ]\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 \"ship_to\": {\n \"name\": \"Amanda Miller\",\n \"phone\": \"20 5555 5555\",\n \"address_line1\": \"77 Netherpark Crescent\",\n \"address_line2\": \"Suite 100\",\n \"city_locality\": \"London\",\n \"state_province\": \"N/A\",\n \"postal_code\": \"ABC 123\",\n \"country_code\": \"GB\",\n \"address_residential_indicator\": \"yes\"\n },\n \"packages\": [\n {\n \"weight\": {\n \"value\": 9.6,\n \"unit\": \"ounce\"\n },\n \"dimensions\": {\n \"unit\": \"inch\",\n \"length\": 12,\n \"width\": 7.1,\n \"height\": 6\n }\n }\n ]\n }\n}"
response = https.request(request)
puts response.read_body
var client = new RestClient("https://api.shipengine.com/v1/rates");
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 \"rate_options\": {\n \"carrier_ids\": [\n \"se-82785\"\n ],\n \"calculate_tax_amount\": true\n },\n \"shipment\": {\n \"service_code\": \"usps_first_class_mail_international\",\n \"customs\": {\n \"contents\": \"merchandise\",\n \"non_delivery\": \"treat_as_abandoned\",\n \"customs_items\": [\n {\n \"harmonized_tariff_code\": \"0901.21\",\n \"country_of_manufacture\": \"US\",\n \"country_of_origin\": \"US\",\n \"quantity\": 2,\n \"description\": \"books\",\n \"value\": {\n \"currency\": \"usd\",\n \"amount\": 100\n }\n }\n ]\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 \"ship_to\": {\n \"name\": \"Amanda Miller\",\n \"phone\": \"20 5555 5555\",\n \"address_line1\": \"77 Netherpark Crescent\",\n \"address_line2\": \"Suite 100\",\n \"city_locality\": \"London\",\n \"state_province\": \"N/A\",\n \"postal_code\": \"ABC 123\",\n \"country_code\": \"GB\",\n \"address_residential_indicator\": \"yes\"\n },\n \"packages\": [\n {\n \"weight\": {\n \"value\": 9.6,\n \"unit\": \"ounce\"\n },\n \"dimensions\": {\n \"unit\": \"inch\",\n \"length\": 12,\n \"width\": 7.1,\n \"height\": 6\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 \"rate_options\": {\n \"carrier_ids\": [\n \"se-82785\"\n ],\n \"calculate_tax_amount\": true\n },\n \"shipment\": {\n \"service_code\": \"usps_first_class_mail_international\",\n \"customs\": {\n \"contents\": \"merchandise\",\n \"non_delivery\": \"treat_as_abandoned\",\n \"customs_items\": [\n {\n \"harmonized_tariff_code\": \"0901.21\",\n \"country_of_manufacture\": \"US\",\n \"country_of_origin\": \"US\",\n \"quantity\": 2,\n \"description\": \"books\",\n \"value\": {\n \"currency\": \"usd\",\n \"amount\": 100\n }\n }\n ]\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 \"ship_to\": {\n \"name\": \"Amanda Miller\",\n \"phone\": \"20 5555 5555\",\n \"address_line1\": \"77 Netherpark Crescent\",\n \"address_line2\": \"Suite 100\",\n \"city_locality\": \"London\",\n \"state_province\": \"N/A\",\n \"postal_code\": \"ABC 123\",\n \"country_code\": \"GB\",\n \"address_residential_indicator\": \"yes\"\n },\n \"packages\": [\n {\n \"weight\": {\n \"value\": 9.6,\n \"unit\": \"ounce\"\n },\n \"dimensions\": {\n \"unit\": \"inch\",\n \"length\": 12,\n \"width\": 7.1,\n \"height\": 6\n }\n }\n ]\n }\n}");
Request request = new Request.Builder()
.url("https://api.shipengine.com/v1/rates")
.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/rates"
method := "POST"
payload := strings.NewReader("{\n \"rate_options\": {\n \"carrier_ids\": [\n \"se-82785\"\n ],\n \"calculate_tax_amount\": true\n },\n \"shipment\": {\n \"service_code\": \"usps_first_class_mail_international\",\n \"customs\": {\n \"contents\": \"merchandise\",\n \"non_delivery\": \"treat_as_abandoned\",\n \"customs_items\": [\n {\n \"harmonized_tariff_code\": \"0901.21\",\n \"country_of_manufacture\": \"US\",\n \"country_of_origin\": \"US\",\n \"quantity\": 2,\n \"description\": \"books\",\n \"value\": {\n \"currency\": \"usd\",\n \"amount\": 100\n }\n }\n ]\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 \"ship_to\": {\n \"name\": \"Amanda Miller\",\n \"phone\": \"20 5555 5555\",\n \"address_line1\": \"77 Netherpark Crescent\",\n \"address_line2\": \"Suite 100\",\n \"city_locality\": \"London\",\n \"state_province\": \"N/A\",\n \"postal_code\": \"ABC 123\",\n \"country_code\": \"GB\",\n \"address_residential_indicator\": \"yes\"\n },\n \"packages\": [\n {\n \"weight\": {\n \"value\": 9.6,\n \"unit\": \"ounce\"\n },\n \"dimensions\": {\n \"unit\": \"inch\",\n \"length\": 12,\n \"width\": 7.1,\n \"height\": 6\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/rates"]
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 \"rate_options\": {\n \"carrier_ids\": [\n \"se-82785\"\n ],\n \"calculate_tax_amount\": true\n },\n \"shipment\": {\n \"service_code\": \"usps_first_class_mail_international\",\n \"customs\": {\n \"contents\": \"merchandise\",\n \"non_delivery\": \"treat_as_abandoned\",\n \"customs_items\": [\n {\n \"harmonized_tariff_code\": \"0901.21\",\n \"country_of_manufacture\": \"US\",\n \"country_of_origin\": \"US\",\n \"quantity\": 2,\n \"description\": \"books\",\n \"value\": {\n \"currency\": \"usd\",\n \"amount\": 100\n }\n }\n ]\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 \"ship_to\": {\n \"name\": \"Amanda Miller\",\n \"phone\": \"20 5555 5555\",\n \"address_line1\": \"77 Netherpark Crescent\",\n \"address_line2\": \"Suite 100\",\n \"city_locality\": \"London\",\n \"state_province\": \"N/A\",\n \"postal_code\": \"ABC 123\",\n \"country_code\": \"GB\",\n \"address_residential_indicator\": \"yes\"\n },\n \"packages\": [\n {\n \"weight\": {\n \"value\": 9.6,\n \"unit\": \"ounce\"\n },\n \"dimensions\": {\n \"unit\": \"inch\",\n \"length\": 12,\n \"width\": 7.1,\n \"height\": 6\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 \"rate_options\": {\n \"carrier_ids\": [\n \"se-82785\"\n ],\n \"calculate_tax_amount\": true\n },\n \"shipment\": {\n \"service_code\": \"usps_first_class_mail_international\",\n \"customs\": {\n \"contents\": \"merchandise\",\n \"non_delivery\": \"treat_as_abandoned\",\n \"customs_items\": [\n {\n \"harmonized_tariff_code\": \"0901.21\",\n \"country_of_manufacture\": \"US\",\n \"country_of_origin\": \"US\",\n \"quantity\": 2,\n \"description\": \"books\",\n \"value\": {\n \"currency\": \"usd\",\n \"amount\": 100\n }\n }\n ]\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 \"ship_to\": {\n \"name\": \"Amanda Miller\",\n \"phone\": \"20 5555 5555\",\n \"address_line1\": \"77 Netherpark Crescent\",\n \"address_line2\": \"Suite 100\",\n \"city_locality\": \"London\",\n \"state_province\": \"N/A\",\n \"postal_code\": \"ABC 123\",\n \"country_code\": \"GB\",\n \"address_residential_indicator\": \"yes\"\n },\n \"packages\": [\n {\n \"weight\": {\n \"value\": 9.6,\n \"unit\": \"ounce\"\n },\n \"dimensions\": {\n \"unit\": \"inch\",\n \"length\": 12,\n \"width\": 7.1,\n \"height\": 6\n }\n }\n ]\n }\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.shipengine.com/v1/rates")!,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()
{
"rate_response": {
"rates": [
{
"rate_id": "se-5592488",
"rate_type": "shipment",
"carrier_id": "se-82785",
"shipping_amount": {
"currency": "usd",
"amount": 23.28
},
"insurance_amount": {
"currency": "usd",
"amount": 0.0
},
"confirmation_amount": {
"currency": "usd",
"amount": 0.0
},
"other_amount": {
"currency": "usd",
"amount": 0.0
},
"tax_amount": {
"currency": "usd",
"amount": 0.0
},
"zone": null,
"package_type": "package",
"delivery_days": null,
"guaranteed_service": false,
"estimated_delivery_date": null,
"carrier_delivery_days": null,
"ship_date": "2020-10-21T00:00:00Z",
"negotiated_rate": false,
"service_type": "USPS First Class Mail Intl",
"service_code": "usps_first_class_mail_international",
"trackable": false,
"carrier_code": "stamps_com",
"carrier_nickname": "Z - Test Stamps.com Account",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": []
},
{
"rate_id": "se-5592489",
"rate_type": "shipment",
"carrier_id": "se-82785",
"shipping_amount": {
"currency": "usd",
"amount": 53.34
},
"insurance_amount": {
"currency": "usd",
"amount": 0.0
},
"confirmation_amount": {
"currency": "usd",
"amount": 0.0
},
"other_amount": {
"currency": "usd",
"amount": 0.0
},
"tax_amount": {
"currency": "usd",
"amount": 0.0
},
"zone": null,
"package_type": "package",
"delivery_days": 10,
"guaranteed_service": false,
"estimated_delivery_date": "2020-10-31T00:00:00Z",
"carrier_delivery_days": "6 - 10",
"ship_date": "2020-10-21T00:00:00Z",
"negotiated_rate": false,
"service_type": "USPS Priority Mail Intl",
"service_code": "usps_priority_mail_international",
"trackable": false,
"carrier_code": "stamps_com",
"carrier_nickname": "Z - Test Stamps.com Account",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": []
},
{
"rate_id": "se-5592490",
"rate_type": "shipment",
"carrier_id": "se-82785",
"shipping_amount": {
"currency": "usd",
"amount": 71.6000
},
"insurance_amount": {
"currency": "usd",
"amount": 0.0
},
"confirmation_amount": {
"currency": "usd",
"amount": 0.0
},
"other_amount": {
"currency": "usd",
"amount": 0.0
},
"tax_amount": {
"currency": "usd",
"amount": 0.0
},
"zone": null,
"package_type": "medium_flat_rate_box",
"delivery_days": 10,
"guaranteed_service": false,
"estimated_delivery_date": "2020-10-31T00:00:00Z",
"carrier_delivery_days": "6 - 10",
"ship_date": "2020-10-21T00:00:00Z",
"negotiated_rate": false,
"service_type": "USPS Priority Mail Intl",
"service_code": "usps_priority_mail_international",
"trackable": false,
"carrier_code": "stamps_com",
"carrier_nickname": "Z - Test Stamps.com Account",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": []
}
],
"invalid_rates": [],
"rate_request_id": "se-702570",
"shipment_id": "se-6407542",
"created_at": "2020-10-21T15:10:10.0994241Z",
"status": "completed",
"errors": []
},
"shipment_id": "se-6407542",
"carrier_id": "se-82785",
"service_code": "usps_first_class_mail_international",
"external_shipment_id": null,
"ship_date": "2020-10-21T00:00:00Z",
"created_at": "2020-10-21T15:10:08.63Z",
"modified_at": "2020-10-21T15:10:08.567Z",
"shipment_status": "pending",
"ship_to": {
"name": "Amanda Miller",
"phone": "20 5555 5555",
"company_name": null,
"address_line1": "77 Netherpark Crescent",
"address_line2": "Suite 100",
"address_line3": null,
"city_locality": "London",
"state_province": "N/A",
"postal_code": "ABC 123",
"country_code": "GB",
"address_residential_indicator": "yes"
},
"ship_from": {
"name": "John Doe",
"phone": "111-111-1111",
"company_name": "Example Corp.",
"address_line1": "4009 Marathon Blvd",
"address_line2": "Suite 300",
"address_line3": null,
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "unknown"
},
"warehouse_id": null,
"return_to": {
"name": "John Doe",
"phone": "111-111-1111",
"company_name": "Example Corp.",
"address_line1": "4009 Marathon Blvd",
"address_line2": "Suite 300",
"address_line3": null,
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "unknown"
},
"confirmation": "none",
"customs": {
"contents": "merchandise",
"customs_items": [
{
"customs_item_id": "se-582249",
"description": "books",
"quantity": 2,
"value": 100.00,
"harmonized_tariff_code": "0901.21",
"country_of_origin": "US",
"unit_of_measure": null
}
],
"non_delivery": "treat_as_abandoned"
},
"external_order_id": null,
"order_source_code": 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,
"dry_ice": false,
"dry_ice_weight": null,
"freight_class": null,
"custom_field1": null,
"custom_field2": null,
"custom_field3": null,
"collect_on_delivery": null
},
"insurance_provider": "none",
"tags": [],
"packages": [
{
"package_code": "package",
"weight": {
"value": 9.60,
"unit": "ounce"
},
"dimensions": {
"unit": "inch",
"length": 12.00,
"width": 7.10,
"height": 6.00
},
"insured_value": {
"currency": "usd",
"amount": 0.00
},
"label_messages": {
"reference1": null,
"reference2": null,
"reference3": null
},
"external_package_id": null
}
],
"total_weight": {
"value": 9.60,
"unit": "ounce"
},
"items": []
}
{
"rate_response": {
"rates": [
{
"rate_id": "se-5592488",
"rate_type": "shipment",
"carrier_id": "se-82785",
"shipping_amount": {
"currency": "usd",
"amount": 23.28
},
"insurance_amount": {
"currency": "usd",
"amount": 0.0
},
"confirmation_amount": {
"currency": "usd",
"amount": 0.0
},
"other_amount": {
"currency": "usd",
"amount": 0.0
},
"tax_amount": {
"currency": "usd",
"amount": 0.0
},
"zone": null,
"package_type": "package",
"delivery_days": null,
"guaranteed_service": false,
"estimated_delivery_date": null,
"carrier_delivery_days": null,
"ship_date": "2020-10-21T00:00:00Z",
"negotiated_rate": false,
"service_type": "USPS First Class Mail Intl",
"service_code": "usps_first_class_mail_international",
"trackable": false,
"carrier_code": "stamps_com",
"carrier_nickname": "Z - Test Stamps.com Account",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": []
},
{
"rate_id": "se-5592489",
"rate_type": "shipment",
"carrier_id": "se-82785",
"shipping_amount": {
"currency": "usd",
"amount": 53.34
},
"insurance_amount": {
"currency": "usd",
"amount": 0.0
},
"confirmation_amount": {
"currency": "usd",
"amount": 0.0
},
"other_amount": {
"currency": "usd",
"amount": 0.0
},
"tax_amount": {
"currency": "usd",
"amount": 0.0
},
"zone": null,
"package_type": "package",
"delivery_days": 10,
"guaranteed_service": false,
"estimated_delivery_date": "2020-10-31T00:00:00Z",
"carrier_delivery_days": "6 - 10",
"ship_date": "2020-10-21T00:00:00Z",
"negotiated_rate": false,
"service_type": "USPS Priority Mail Intl",
"service_code": "usps_priority_mail_international",
"trackable": false,
"carrier_code": "stamps_com",
"carrier_nickname": "Z - Test Stamps.com Account",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": []
},
{
"rate_id": "se-5592490",
"rate_type": "shipment",
"carrier_id": "se-82785",
"shipping_amount": {
"currency": "usd",
"amount": 71.6000
},
"insurance_amount": {
"currency": "usd",
"amount": 0.0
},
"confirmation_amount": {
"currency": "usd",
"amount": 0.0
},
"other_amount": {
"currency": "usd",
"amount": 0.0
},
"tax_amount": {
"currency": "usd",
"amount": 0.0
},
"zone": null,
"package_type": "medium_flat_rate_box",
"delivery_days": 10,
"guaranteed_service": false,
"estimated_delivery_date": "2020-10-31T00:00:00Z",
"carrier_delivery_days": "6 - 10",
"ship_date": "2020-10-21T00:00:00Z",
"negotiated_rate": false,
"service_type": "USPS Priority Mail Intl",
"service_code": "usps_priority_mail_international",
"trackable": false,
"carrier_code": "stamps_com",
"carrier_nickname": "Z - Test Stamps.com Account",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": []
}
],
"invalid_rates": [],
"rate_request_id": "se-702570",
"shipment_id": "se-6407542",
"created_at": "2020-10-21T15:10:10.0994241Z",
"status": "completed",
"errors": []
},
"shipment_id": "se-6407542",
"carrier_id": "se-82785",
"service_code": "usps_first_class_mail_international",
"external_shipment_id": null,
"ship_date": "2020-10-21T00:00:00Z",
"created_at": "2020-10-21T15:10:08.63Z",
"modified_at": "2020-10-21T15:10:08.567Z",
"shipment_status": "pending",
"ship_to": {
"name": "Amanda Miller",
"phone": "20 5555 5555",
"company_name": null,
"address_line1": "77 Netherpark Crescent",
"address_line2": "Suite 100",
"address_line3": null,
"city_locality": "London",
"state_province": "N/A",
"postal_code": "ABC 123",
"country_code": "GB",
"address_residential_indicator": "yes"
},
"ship_from": {
"name": "John Doe",
"phone": "111-111-1111",
"company_name": "Example Corp.",
"address_line1": "4009 Marathon Blvd",
"address_line2": "Suite 300",
"address_line3": null,
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "unknown"
},
"warehouse_id": null,
"return_to": {
"name": "John Doe",
"phone": "111-111-1111",
"company_name": "Example Corp.",
"address_line1": "4009 Marathon Blvd",
"address_line2": "Suite 300",
"address_line3": null,
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "unknown"
},
"confirmation": "none",
"customs": {
"contents": "merchandise",
"customs_items": [
{
"customs_item_id": "se-582249",
"description": "books",
"quantity": 2,
"value": 100.00,
"harmonized_tariff_code": "0901.21",
"country_of_origin": "US",
"unit_of_measure": null
}
],
"non_delivery": "treat_as_abandoned"
},
"external_order_id": null,
"order_source_code": 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,
"dry_ice": false,
"dry_ice_weight": null,
"freight_class": null,
"custom_field1": null,
"custom_field2": null,
"custom_field3": null,
"collect_on_delivery": null
},
"insurance_provider": "none",
"tags": [],
"packages": [
{
"package_code": "package",
"weight": {
"value": 9.60,
"unit": "ounce"
},
"dimensions": {
"unit": "inch",
"length": 12.00,
"width": 7.10,
"height": 6.00
},
"insured_value": {
"currency": "usd",
"amount": 0.00
},
"label_messages": {
"reference1": null,
"reference2": null,
"reference3": null
},
"external_package_id": null
}
],
"total_weight": {
"value": 9.60,
"unit": "ounce"
},
"items": []
}