Parcel Insurance
tip
Setup Billing First
To setup 3rd-party shipping insurance, you must add billing information to your account.
Go to Billing
Enable Shipsurance
Shipsurance is included by default, you just need to enable it! Here are the steps to do so!
- Log into the ShipEngine Portal.
- Select Carrier Management.
- Select the Insurance tab.
- Toggle 3rd Party Insurance to on and follow the on-screen instructions.
Adding Insurance Funds
You may need to auto fund your account from time to time. For example, if you don't normally ship items over $100, and may want to add funds to insurance rather than keeping the account funded.
Warning
This request costs money!
There is no test mode for adding funds to insurance, you will be charged.
PATCH /v1/insurance/shipsurance/add_funds
PATCH /v1/insurance/shipsurance/add_funds HTTP/1.1
Host: api.shipengine.com
API-Key: __YOUR_API_KEY_HERE__
Content-Type: application/json
{
"currency": "usd",
"amount": 10.0
}
curl -iX PATCH https://api.shipengine.com/v1/insurance/shipsurance/add_funds \
-H 'API-Key: __YOUR_API_KEY_HERE__' \
-H 'Content-Type: application/json' \
-d '{
"currency": "usd",
"amount": 10.0
}'
$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 `"currency`": `"usd`",`n `"amount`": 10.0`n}"
$response = Invoke-RestMethod 'https://api.shipengine.com/v1/insurance/shipsurance/add_funds' -Method 'PATCH' -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({"currency":"usd","amount":10});
var requestOptions = {
method: 'PATCH',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.shipengine.com/v1/insurance/shipsurance/add_funds", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
var request = require('request');
var options = {
'method': 'PATCH',
'url': 'https://api.shipengine.com/v1/insurance/shipsurance/add_funds',
'headers': {
'Host': 'api.shipengine.com',
'API-Key': '__YOUR_API_KEY_HERE__',
'Content-Type': 'application/json'
},
body: JSON.stringify({"currency":"usd","amount":10})
};
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/insurance/shipsurance/add_funds",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS =>"{\n \"currency\": \"usd\",\n \"amount\": 10.0\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/insurance/shipsurance/add_funds"
payload = "{\n \"currency\": \"usd\",\n \"amount\": 10.0\n}"
headers = {
'Host': 'api.shipengine.com',
'API-Key': '__YOUR_API_KEY_HERE__',
'Content-Type': 'application/json'
}
response = requests.request("PATCH", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
require "uri"
require "net/http"
url = URI("https://api.shipengine.com/v1/insurance/shipsurance/add_funds")
https = Net::HTTP.new(url.host, url.port);
https.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Host"] = "api.shipengine.com"
request["API-Key"] = "__YOUR_API_KEY_HERE__"
request["Content-Type"] = "application/json"
request.body = "{\n \"currency\": \"usd\",\n \"amount\": 10.0\n}"
response = https.request(request)
puts response.read_body
var client = new RestClient("https://api.shipengine.com/v1/insurance/shipsurance/add_funds");
client.Timeout = -1;
var request = new RestRequest(Method.PATCH);
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 \"currency\": \"usd\",\n \"amount\": 10.0\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 \"currency\": \"usd\",\n \"amount\": 10.0\n}");
Request request = new Request.Builder()
.url("https://api.shipengine.com/v1/insurance/shipsurance/add_funds")
.method("PATCH", 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/insurance/shipsurance/add_funds"
method := "PATCH"
payload := strings.NewReader("{\n \"currency\": \"usd\",\n \"amount\": 10.0\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/insurance/shipsurance/add_funds"]
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 \"currency\": \"usd\",\n \"amount\": 10.0\n}" dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postData];
[request setHTTPMethod:@"PATCH"];
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 \"currency\": \"usd\",\n \"amount\": 10.0\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.shipengine.com/v1/insurance/shipsurance/add_funds")!,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 = "PATCH"
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()
Shipengine responds with an object showing the new balance in your account.
{
"balance": {
"currency": "usd",
"amount": 50.00
}
}
{
"balance": {
"currency": "usd",
"amount": 50.00
}
}
Tip
Auto Funding
We recommend that you auto fund your insurance account. By auto funding, you won't receive insufficient balance alerts. You can auto fund for as little as $10 when it falls below the minimum.
Check Your Insurance Balance
GET /v1/insurance/shipsurance/balance
Example Request
GET /v1/insurance/shipsurance/balance HTTP/1.1
Host: app.shipengine.com
curl -iX GET https://app.shipengine.com/v1/insurance/shipsurance/balance \
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Host", "app.shipengine.com")
$response = Invoke-RestMethod 'https://app.shipengine.com/v1/insurance/shipsurance/balance' -Method 'GET' -Headers $headers -Body $body
$response | ConvertTo-Json
var myHeaders = new Headers();
myHeaders.append("Host", "app.shipengine.com");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://app.shipengine.com/v1/insurance/shipsurance/balance", 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://app.shipengine.com/v1/insurance/shipsurance/balance',
'headers': {
'Host': 'app.shipengine.com'
}
};
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://app.shipengine.com/v1/insurance/shipsurance/balance",
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: app.shipengine.com"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
url = "https://app.shipengine.com/v1/insurance/shipsurance/balance"
payload = {}
headers = {
'Host': 'app.shipengine.com'
}
response = requests.request("GET", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
require "uri"
require "net/http"
url = URI("https://app.shipengine.com/v1/insurance/shipsurance/balance")
https = Net::HTTP.new(url.host, url.port);
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Host"] = "app.shipengine.com"
response = https.request(request)
puts response.read_body
var client = new RestClient("https://app.shipengine.com/v1/insurance/shipsurance/balance");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Host", "app.shipengine.com");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
Request request = new Request.Builder()
.url("https://app.shipengine.com/v1/insurance/shipsurance/balance")
.method("GET", null)
.addHeader("Host", "app.shipengine.com")
.build();
Response response = client.newCall(request).execute();
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://app.shipengine.com/v1/insurance/shipsurance/balance"
method := "GET"
client := &http.Client {
}
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
}
req.Header.Add("Host", "app.shipengine.com")
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://app.shipengine.com/v1/insurance/shipsurance/balance"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
NSDictionary *headers = @{
@"Host": @"app.shipengine.com"
};
[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://app.shipengine.com/v1/insurance/shipsurance/balance")!,timeoutInterval: Double.infinity)
request.addValue("app.shipengine.com", forHTTPHeaderField: "Host")
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()
Example Response
{
"balance": {
"currency": "usd",
"amount": 50.00
}
}
{
"balance": {
"currency": "usd",
"amount": 50.00
}
}
Adding Insurance to a Shipment
When creating a label, you can declare the package value to ensure reimbursement if the package is lost or damaged in the mail stream. Start by setting the insurance_provider
field to one of the following values:
Insurance Provider | Description |
---|---|
none (default) |
The package will not be insured. Some carriers may still offer reimbursement up to a certain value. |
shipsurance |
Purchase insurance from Shipsurance. You need to setup your billing info first. |
carrier |
Get increased reimbursement coverage from the carrier based on the declared value of the package. |
third_party |
The package is insured by a third-party insurance service, outside of ShipEngine. |
POST /v1/labels
In addition to the insurance_provider
field, you will also need to set the insured_value
of each package in the shipment. For example:
{
"insurance_provider": "shipsurance",
"packages": [
{
"insured_value": {
"currency": "usd",
"amount": 200.0
}
}]
}
{
"insurance_provider": "shipsurance",
"packages": [
{
"insured_value": {
"currency": "usd",
"amount": 200.0
}
}]
}
Example Request
POST /v1/labels HTTP/1.1
Host: api.shipengine.com
API-Key: __YOUR_API_KEY_HERE__
Content-Type: application/json
{
"shipment": {
"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"
},
"ship_from": {
"company_name": "Example Corp.",
"name": "John Doe",
"phone": "111-111-1111",
"address_line1": "4009 Marathon Blvd",
"address_line2": "Suite 300",
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "no"
},
"confirmation": "none",
"insurance_provider": "shipsurance",
"packages": [
{
"weight": {
"value": 1.0,
"unit": "ounce"
},
"insured_value": {
"currency": "usd",
"amount": 200.0
}
}
]
}
}
curl -iX POST https://api.shipengine.com/v1/labels \
-H 'API-Key: __YOUR_API_KEY_HERE__' \
-H 'Content-Type: application/json' \
-d '{
"shipment": {
"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"
},
"ship_from": {
"company_name": "Example Corp.",
"name": "John Doe",
"phone": "111-111-1111",
"address_line1": "4009 Marathon Blvd",
"address_line2": "Suite 300",
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "no"
},
"confirmation": "none",
"insurance_provider": "shipsurance",
"packages": [
{
"weight": {
"value": 1.0,
"unit": "ounce"
},
"insured_value": {
"currency": "usd",
"amount": 200.0
}
}
]
}
}'
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Host", "api.shipengine.com")
$headers.Add("API-Key", "__YOUR_API_KEY_HERE__")
$headers.Add("Content-Type", "application/json")
$body = "{`n `"shipment`": {`n `"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 `"ship_from`": {`n `"company_name`": `"Example Corp.`",`n `"name`": `"John Doe`",`n `"phone`": `"111-111-1111`",`n `"address_line1`": `"4009 Marathon Blvd`",`n `"address_line2`": `"Suite 300`",`n `"city_locality`": `"Austin`",`n `"state_province`": `"TX`",`n `"postal_code`": `"78756`",`n `"country_code`": `"US`",`n `"address_residential_indicator`": `"no`"`n },`n `"confirmation`": `"none`",`n `"insurance_provider`": `"shipsurance`",`n `"packages`": [`n {`n `"weight`": {`n `"value`": 1.0,`n `"unit`": `"ounce`"`n },`n `"insured_value`": {`n `"currency`": `"usd`",`n `"amount`": 200.0`n }`n }`n ]`n }`n}"
$response = Invoke-RestMethod 'https://api.shipengine.com/v1/labels' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
var myHeaders = new Headers();
myHeaders.append("Host", "api.shipengine.com");
myHeaders.append("API-Key", "__YOUR_API_KEY_HERE__");
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({"shipment":{"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"},"ship_from":{"company_name":"Example Corp.","name":"John Doe","phone":"111-111-1111","address_line1":"4009 Marathon Blvd","address_line2":"Suite 300","city_locality":"Austin","state_province":"TX","postal_code":"78756","country_code":"US","address_residential_indicator":"no"},"confirmation":"none","insurance_provider":"shipsurance","packages":[{"weight":{"value":1,"unit":"ounce"},"insured_value":{"currency":"usd","amount":200}}]}});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.shipengine.com/v1/labels", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://api.shipengine.com/v1/labels',
'headers': {
'Host': 'api.shipengine.com',
'API-Key': '__YOUR_API_KEY_HERE__',
'Content-Type': 'application/json'
},
body: JSON.stringify({"shipment":{"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"},"ship_from":{"company_name":"Example Corp.","name":"John Doe","phone":"111-111-1111","address_line1":"4009 Marathon Blvd","address_line2":"Suite 300","city_locality":"Austin","state_province":"TX","postal_code":"78756","country_code":"US","address_residential_indicator":"no"},"confirmation":"none","insurance_provider":"shipsurance","packages":[{"weight":{"value":1,"unit":"ounce"},"insured_value":{"currency":"usd","amount":200}}]}})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.shipengine.com/v1/labels",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"{\n \"shipment\": {\n \"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 \"ship_from\": {\n \"company_name\": \"Example Corp.\",\n \"name\": \"John Doe\",\n \"phone\": \"111-111-1111\",\n \"address_line1\": \"4009 Marathon Blvd\",\n \"address_line2\": \"Suite 300\",\n \"city_locality\": \"Austin\",\n \"state_province\": \"TX\",\n \"postal_code\": \"78756\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"confirmation\": \"none\",\n \"insurance_provider\": \"shipsurance\",\n \"packages\": [\n {\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n },\n \"insured_value\": {\n \"currency\": \"usd\",\n \"amount\": 200.0\n }\n }\n ]\n }\n}",
CURLOPT_HTTPHEADER => array(
"Host: api.shipengine.com",
"API-Key: __YOUR_API_KEY_HERE__",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
url = "https://api.shipengine.com/v1/labels"
payload = "{\n \"shipment\": {\n \"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 \"ship_from\": {\n \"company_name\": \"Example Corp.\",\n \"name\": \"John Doe\",\n \"phone\": \"111-111-1111\",\n \"address_line1\": \"4009 Marathon Blvd\",\n \"address_line2\": \"Suite 300\",\n \"city_locality\": \"Austin\",\n \"state_province\": \"TX\",\n \"postal_code\": \"78756\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"confirmation\": \"none\",\n \"insurance_provider\": \"shipsurance\",\n \"packages\": [\n {\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n },\n \"insured_value\": {\n \"currency\": \"usd\",\n \"amount\": 200.0\n }\n }\n ]\n }\n}"
headers = {
'Host': 'api.shipengine.com',
'API-Key': '__YOUR_API_KEY_HERE__',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
require "uri"
require "net/http"
url = URI("https://api.shipengine.com/v1/labels")
https = Net::HTTP.new(url.host, url.port);
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Host"] = "api.shipengine.com"
request["API-Key"] = "__YOUR_API_KEY_HERE__"
request["Content-Type"] = "application/json"
request.body = "{\n \"shipment\": {\n \"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 \"ship_from\": {\n \"company_name\": \"Example Corp.\",\n \"name\": \"John Doe\",\n \"phone\": \"111-111-1111\",\n \"address_line1\": \"4009 Marathon Blvd\",\n \"address_line2\": \"Suite 300\",\n \"city_locality\": \"Austin\",\n \"state_province\": \"TX\",\n \"postal_code\": \"78756\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"confirmation\": \"none\",\n \"insurance_provider\": \"shipsurance\",\n \"packages\": [\n {\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n },\n \"insured_value\": {\n \"currency\": \"usd\",\n \"amount\": 200.0\n }\n }\n ]\n }\n}"
response = https.request(request)
puts response.read_body
var client = new RestClient("https://api.shipengine.com/v1/labels");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Host", "api.shipengine.com");
request.AddHeader("API-Key", "__YOUR_API_KEY_HERE__");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n \"shipment\": {\n \"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 \"ship_from\": {\n \"company_name\": \"Example Corp.\",\n \"name\": \"John Doe\",\n \"phone\": \"111-111-1111\",\n \"address_line1\": \"4009 Marathon Blvd\",\n \"address_line2\": \"Suite 300\",\n \"city_locality\": \"Austin\",\n \"state_province\": \"TX\",\n \"postal_code\": \"78756\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"confirmation\": \"none\",\n \"insurance_provider\": \"shipsurance\",\n \"packages\": [\n {\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n },\n \"insured_value\": {\n \"currency\": \"usd\",\n \"amount\": 200.0\n }\n }\n ]\n }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n \"shipment\": {\n \"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 \"ship_from\": {\n \"company_name\": \"Example Corp.\",\n \"name\": \"John Doe\",\n \"phone\": \"111-111-1111\",\n \"address_line1\": \"4009 Marathon Blvd\",\n \"address_line2\": \"Suite 300\",\n \"city_locality\": \"Austin\",\n \"state_province\": \"TX\",\n \"postal_code\": \"78756\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"confirmation\": \"none\",\n \"insurance_provider\": \"shipsurance\",\n \"packages\": [\n {\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n },\n \"insured_value\": {\n \"currency\": \"usd\",\n \"amount\": 200.0\n }\n }\n ]\n }\n}");
Request request = new Request.Builder()
.url("https://api.shipengine.com/v1/labels")
.method("POST", body)
.addHeader("Host", "api.shipengine.com")
.addHeader("API-Key", "__YOUR_API_KEY_HERE__")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.shipengine.com/v1/labels"
method := "POST"
payload := strings.NewReader("{\n \"shipment\": {\n \"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 \"ship_from\": {\n \"company_name\": \"Example Corp.\",\n \"name\": \"John Doe\",\n \"phone\": \"111-111-1111\",\n \"address_line1\": \"4009 Marathon Blvd\",\n \"address_line2\": \"Suite 300\",\n \"city_locality\": \"Austin\",\n \"state_province\": \"TX\",\n \"postal_code\": \"78756\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"confirmation\": \"none\",\n \"insurance_provider\": \"shipsurance\",\n \"packages\": [\n {\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n },\n \"insured_value\": {\n \"currency\": \"usd\",\n \"amount\": 200.0\n }\n }\n ]\n }\n}")
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
}
req.Header.Add("Host", "api.shipengine.com")
req.Header.Add("API-Key", "__YOUR_API_KEY_HERE__")
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
#import <Foundation/Foundation.h>
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.shipengine.com/v1/labels"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
NSDictionary *headers = @{
@"Host": @"api.shipengine.com",
@"API-Key": @"__YOUR_API_KEY_HERE__",
@"Content-Type": @"application/json"
};
[request setAllHTTPHeaderFields:headers];
NSData *postData = [[NSData alloc] initWithData:[@"{\n \"shipment\": {\n \"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 \"ship_from\": {\n \"company_name\": \"Example Corp.\",\n \"name\": \"John Doe\",\n \"phone\": \"111-111-1111\",\n \"address_line1\": \"4009 Marathon Blvd\",\n \"address_line2\": \"Suite 300\",\n \"city_locality\": \"Austin\",\n \"state_province\": \"TX\",\n \"postal_code\": \"78756\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"confirmation\": \"none\",\n \"insurance_provider\": \"shipsurance\",\n \"packages\": [\n {\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n },\n \"insured_value\": {\n \"currency\": \"usd\",\n \"amount\": 200.0\n }\n }\n ]\n }\n}" dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postData];
[request setHTTPMethod:@"POST"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSError *parseError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
NSLog(@"%@",responseDictionary);
dispatch_semaphore_signal(sema);
}
}];
[dataTask resume];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
import Foundation
var semaphore = DispatchSemaphore (value: 0)
let parameters = "{\n \"shipment\": {\n \"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 \"ship_from\": {\n \"company_name\": \"Example Corp.\",\n \"name\": \"John Doe\",\n \"phone\": \"111-111-1111\",\n \"address_line1\": \"4009 Marathon Blvd\",\n \"address_line2\": \"Suite 300\",\n \"city_locality\": \"Austin\",\n \"state_province\": \"TX\",\n \"postal_code\": \"78756\",\n \"country_code\": \"US\",\n \"address_residential_indicator\": \"no\"\n },\n \"confirmation\": \"none\",\n \"insurance_provider\": \"shipsurance\",\n \"packages\": [\n {\n \"weight\": {\n \"value\": 1.0,\n \"unit\": \"ounce\"\n },\n \"insured_value\": {\n \"currency\": \"usd\",\n \"amount\": 200.0\n }\n }\n ]\n }\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.shipengine.com/v1/labels")!,timeoutInterval: Double.infinity)
request.addValue("api.shipengine.com", forHTTPHeaderField: "Host")
request.addValue("__YOUR_API_KEY_HERE__", forHTTPHeaderField: "API-Key")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
return
}
print(String(data: data, encoding: .utf8)!)
semaphore.signal()
}
task.resume()
semaphore.wait()
Example Response
{
"label_id": "se-test-41817394",
"status": "processing",
"shipment_id": "se-41817394",
"ship_date": "2017-04-03T00:00:00Z",
"created_at": "2017-04-03T17:30:19.9541821Z",
"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-0",
"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": {
"pdf": "https://api.shipengine.com/v1/downloads/1/s_Tqsu9euEKub6Acc_9UIg/testlabel-2128732.pdf",
"png": "https://api.shipengine.com/v1/downloads/1/s_Tqsu9euEKub6Acc_9UIg/testlabel-2128732.png",
"zpl": "https://api.shipengine.com/v1/downloads/1/s_Tqsu9euEKub6Acc_9UIg/testlabel-2128732.zpl",
"href": "https://api.shipengine.com/v1/downloads/1/s_Tqsu9euEKub6Acc_9UIg/testlabel-2128732.pdf"
},
"form_download": null,
"insurance_claim": {
"href": "https://www.dsiins.com/extclaims/Default.asp?cid=shipengine&psid=0&shipmentid=0"
}
}
{
"label_id": "se-test-41817394",
"status": "processing",
"shipment_id": "se-41817394",
"ship_date": "2017-04-03T00:00:00Z",
"created_at": "2017-04-03T17:30:19.9541821Z",
"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-0",
"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": {
"pdf": "https://api.shipengine.com/v1/downloads/1/s_Tqsu9euEKub6Acc_9UIg/testlabel-2128732.pdf",
"png": "https://api.shipengine.com/v1/downloads/1/s_Tqsu9euEKub6Acc_9UIg/testlabel-2128732.png",
"zpl": "https://api.shipengine.com/v1/downloads/1/s_Tqsu9euEKub6Acc_9UIg/testlabel-2128732.zpl",
"href": "https://api.shipengine.com/v1/downloads/1/s_Tqsu9euEKub6Acc_9UIg/testlabel-2128732.pdf"
},
"form_download": null,
"insurance_claim": {
"href": "https://www.dsiins.com/extclaims/Default.asp?cid=shipengine&psid=0&shipmentid=0"
}
}