Rate Multiple Shipments
Info
Rate a Single Shipment
If you need to just rate a single shipment, see the Get Shipping Rates Quickstart.
With ShipEngine you're able to request rates for multiple shipments at once. Unlike in the Get Shipping Rates section, this process is asynchronous. If you subscribe to webhooks, you will receive a notification when the operation is complete.
You can then retrieve the rates and create a label
using the rate_id
.
Example Request
POST /v1/rates/bulk
This example requests rates for shipments that were previously created by passing the shipment_ids
property.
POST /v1/rates/bulk HTTP/1.1
Host: api.shipengine.com
API-Key: __YOUR_API_KEY_HERE__
Content-Type: application/json
{
"shipment_ids": [
"se-2127226",
"se-2127227"
],
"rate_options": {
"carrier_ids": [
"se-123890",
"se-121861"
]
}
}
curl -iX POST https://api.shipengine.com/v1/rates/bulk \
-H 'API-Key: __YOUR_API_KEY_HERE__' \
-H 'Content-Type: application/json' \
-d '{
"shipment_ids": [
"se-2127226",
"se-2127227"
],
"rate_options": {
"carrier_ids": [
"se-123890",
"se-121861"
]
}
}'
$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_ids`": [`n `"se-2127226`",`n `"se-2127227`"`n ],`n `"rate_options`": {`n `"carrier_ids`": [`n `"se-123890`",`n `"se-121861`"`n ]`n }`n}"
$response = Invoke-RestMethod 'https://api.shipengine.com/v1/rates/bulk' -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_ids":["se-2127226","se-2127227"],"rate_options":{"carrier_ids":["se-123890","se-121861"]}});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.shipengine.com/v1/rates/bulk", 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/bulk',
'headers': {
'Host': 'api.shipengine.com',
'API-Key': '__YOUR_API_KEY_HERE__',
'Content-Type': 'application/json'
},
body: JSON.stringify({"shipment_ids":["se-2127226","se-2127227"],"rate_options":{"carrier_ids":["se-123890","se-121861"]}})
};
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/bulk",
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_ids\": [\n \"se-2127226\",\n \"se-2127227\"\n ],\n \"rate_options\": {\n \"carrier_ids\": [\n \"se-123890\",\n \"se-121861\"\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/bulk"
payload = "{\n \"shipment_ids\": [\n \"se-2127226\",\n \"se-2127227\"\n ],\n \"rate_options\": {\n \"carrier_ids\": [\n \"se-123890\",\n \"se-121861\"\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/bulk")
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_ids\": [\n \"se-2127226\",\n \"se-2127227\"\n ],\n \"rate_options\": {\n \"carrier_ids\": [\n \"se-123890\",\n \"se-121861\"\n ]\n }\n}"
response = https.request(request)
puts response.read_body
var client = new RestClient("https://api.shipengine.com/v1/rates/bulk");
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_ids\": [\n \"se-2127226\",\n \"se-2127227\"\n ],\n \"rate_options\": {\n \"carrier_ids\": [\n \"se-123890\",\n \"se-121861\"\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_ids\": [\n \"se-2127226\",\n \"se-2127227\"\n ],\n \"rate_options\": {\n \"carrier_ids\": [\n \"se-123890\",\n \"se-121861\"\n ]\n }\n}");
Request request = new Request.Builder()
.url("https://api.shipengine.com/v1/rates/bulk")
.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/bulk"
method := "POST"
payload := strings.NewReader("{\n \"shipment_ids\": [\n \"se-2127226\",\n \"se-2127227\"\n ],\n \"rate_options\": {\n \"carrier_ids\": [\n \"se-123890\",\n \"se-121861\"\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/bulk"]
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_ids\": [\n \"se-2127226\",\n \"se-2127227\"\n ],\n \"rate_options\": {\n \"carrier_ids\": [\n \"se-123890\",\n \"se-121861\"\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_ids\": [\n \"se-2127226\",\n \"se-2127227\"\n ],\n \"rate_options\": {\n \"carrier_ids\": [\n \"se-123890\",\n \"se-121861\"\n ]\n }\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.shipengine.com/v1/rates/bulk")!,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()
This example includes the shipment information directly in the rate request rather than referencing an existing shipment.
In this case, ShipEngine will create a shipment for you and include a shipment_id
with the each rate when you
retrieve the rates.
POST /v1/rates/bulk HTTP/1.1
Host: api.shipengine.com
API-Key: __YOUR_API_KEY_HERE__
Content-Type: application/json
{
"rate_options": {
"carrier_ids": [
"se-123890",
"se-123890"
]
},
"shipments": [{
"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",
"packages": [{
"package_code": "package",
"weight": {
"value": 12,
"unit": "ounce"
}
}]
},
{
"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",
"packages": [{
"package_code": "package",
"weight": {
"value": 1,
"unit": "pound"
}
}]
},
{
"ship_to": {
"name": "Waffle HQ",
"company_name": "Waffle House",
"address_line1": "5986 Financial Drive",
"address_line2": null,
"address_line3": null,
"city_locality": "Norcross",
"state_province": "GA",
"postal_code": "30071",
"country_code": "US",
"phone": "111-111-1111"
},
"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",
"packages": [{
"package_code": "package",
"weight": {
"value": 1,
"unit": "ounce"
}
}]
},
{
"ship_to": {
"name": "Jony Ive",
"company_name": "Apple",
"address_line1": "1 Infinite Loop",
"address_line2": null,
"address_line3": null,
"city_locality": "Cupertino",
"state_province": "CA",
"postal_code": "95014",
"country_code": "US",
"phone": "408-996-1010"
},
"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",
"packages": [{
"package_code": "package",
"weight": {
"value": 1,
"unit": "ounce"
}
}]
},
{
"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",
"packages": [{
"package_code": "package",
"weight": {
"value": 1,
"unit": "ounce"
}
}]
}
]
}
curl -iX POST https://api.shipengine.com/v1/rates/bulk \
-H 'API-Key: __YOUR_API_KEY_HERE__' \
-H 'Content-Type: application/json' \
-d '{
"rate_options": {
"carrier_ids": [
"se-123890",
"se-123890"
]
},
"shipments": [{
"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",
"packages": [{
"package_code": "package",
"weight": {
"value": 12,
"unit": "ounce"
}
}]
},
{
"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",
"packages": [{
"package_code": "package",
"weight": {
"value": 1,
"unit": "pound"
}
}]
},
{
"ship_to": {
"name": "Waffle HQ",
"company_name": "Waffle House",
"address_line1": "5986 Financial Drive",
"address_line2": null,
"address_line3": null,
"city_locality": "Norcross",
"state_province": "GA",
"postal_code": "30071",
"country_code": "US",
"phone": "111-111-1111"
},
"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",
"packages": [{
"package_code": "package",
"weight": {
"value": 1,
"unit": "ounce"
}
}]
},
{
"ship_to": {
"name": "Jony Ive",
"company_name": "Apple",
"address_line1": "1 Infinite Loop",
"address_line2": null,
"address_line3": null,
"city_locality": "Cupertino",
"state_province": "CA",
"postal_code": "95014",
"country_code": "US",
"phone": "408-996-1010"
},
"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",
"packages": [{
"package_code": "package",
"weight": {
"value": 1,
"unit": "ounce"
}
}]
},
{
"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",
"packages": [{
"package_code": "package",
"weight": {
"value": 1,
"unit": "ounce"
}
}]
}
]
}'
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Host", "api.shipengine.com")
$headers.Add("API-Key", "__YOUR_API_KEY_HERE__")
$headers.Add("Content-Type", "application/json")
$body = "{`n `"rate_options`": {`n `"carrier_ids`": [`n `"se-123890`",`n `"se-123890`"`n ]`n },`n `"shipments`": [{`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 `"packages`": [{`n `"package_code`": `"package`",`n `"weight`": {`n `"value`": 12,`n `"unit`": `"ounce`"`n }`n }]`n },`n {`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 `"packages`": [{`n `"package_code`": `"package`",`n `"weight`": {`n `"value`": 1,`n `"unit`": `"pound`"`n }`n }]`n },`n {`n `"ship_to`": {`n `"name`": `"Waffle HQ`",`n `"company_name`": `"Waffle House`",`n `"address_line1`": `"5986 Financial Drive`",`n `"address_line2`": null,`n `"address_line3`": null,`n `"city_locality`": `"Norcross`",`n `"state_province`": `"GA`",`n `"postal_code`": `"30071`",`n `"country_code`": `"US`",`n `"phone`": `"111-111-1111`"`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 `"packages`": [{`n `"package_code`": `"package`",`n `"weight`": {`n `"value`": 1,`n `"unit`": `"ounce`"`n }`n }]`n },`n {`n `"ship_to`": {`n `"name`": `"Jony Ive`",`n `"company_name`": `"Apple`",`n `"address_line1`": `"1 Infinite Loop`",`n `"address_line2`": null,`n `"address_line3`": null,`n `"city_locality`": `"Cupertino`",`n `"state_province`": `"CA`",`n `"postal_code`": `"95014`",`n `"country_code`": `"US`",`n `"phone`": `"408-996-1010`"`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 `"packages`": [{`n `"package_code`": `"package`",`n `"weight`": {`n `"value`": 1,`n `"unit`": `"ounce`"`n }`n }]`n },`n {`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 `"packages`": [{`n `"package_code`": `"package`",`n `"weight`": {`n `"value`": 1,`n `"unit`": `"ounce`"`n }`n }]`n }`n ]`n}"
$response = Invoke-RestMethod 'https://api.shipengine.com/v1/rates/bulk' -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-123890","se-123890"]},"shipments":[{"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","packages":[{"package_code":"package","weight":{"value":12,"unit":"ounce"}}]},{"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","packages":[{"package_code":"package","weight":{"value":1,"unit":"pound"}}]},{"ship_to":{"name":"Waffle HQ","company_name":"Waffle House","address_line1":"5986 Financial Drive","address_line2":null,"address_line3":null,"city_locality":"Norcross","state_province":"GA","postal_code":"30071","country_code":"US","phone":"111-111-1111"},"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","packages":[{"package_code":"package","weight":{"value":1,"unit":"ounce"}}]},{"ship_to":{"name":"Jony Ive","company_name":"Apple","address_line1":"1 Infinite Loop","address_line2":null,"address_line3":null,"city_locality":"Cupertino","state_province":"CA","postal_code":"95014","country_code":"US","phone":"408-996-1010"},"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","packages":[{"package_code":"package","weight":{"value":1,"unit":"ounce"}}]},{"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","packages":[{"package_code":"package","weight":{"value":1,"unit":"ounce"}}]}]});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.shipengine.com/v1/rates/bulk", 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/bulk',
'headers': {
'Host': 'api.shipengine.com',
'API-Key': '__YOUR_API_KEY_HERE__',
'Content-Type': 'application/json'
},
body: JSON.stringify({"rate_options":{"carrier_ids":["se-123890","se-123890"]},"shipments":[{"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","packages":[{"package_code":"package","weight":{"value":12,"unit":"ounce"}}]},{"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","packages":[{"package_code":"package","weight":{"value":1,"unit":"pound"}}]},{"ship_to":{"name":"Waffle HQ","company_name":"Waffle House","address_line1":"5986 Financial Drive","address_line2":null,"address_line3":null,"city_locality":"Norcross","state_province":"GA","postal_code":"30071","country_code":"US","phone":"111-111-1111"},"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","packages":[{"package_code":"package","weight":{"value":1,"unit":"ounce"}}]},{"ship_to":{"name":"Jony Ive","company_name":"Apple","address_line1":"1 Infinite Loop","address_line2":null,"address_line3":null,"city_locality":"Cupertino","state_province":"CA","postal_code":"95014","country_code":"US","phone":"408-996-1010"},"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","packages":[{"package_code":"package","weight":{"value":1,"unit":"ounce"}}]},{"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","packages":[{"package_code":"package","weight":{"value":1,"unit":"ounce"}}]}]})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.shipengine.com/v1/rates/bulk",
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-123890\",\n \"se-123890\"\n ]\n },\n \"shipments\": [{\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 12,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"pound\"\n }\n }]\n },\n {\n \"ship_to\": {\n \"name\": \"Waffle HQ\",\n \"company_name\": \"Waffle House\",\n \"address_line1\": \"5986 Financial Drive\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"Norcross\",\n \"state_province\": \"GA\",\n \"postal_code\": \"30071\",\n \"country_code\": \"US\",\n \"phone\": \"111-111-1111\"\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\n \"ship_to\": {\n \"name\": \"Jony Ive\",\n \"company_name\": \"Apple\",\n \"address_line1\": \"1 Infinite Loop\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"Cupertino\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95014\",\n \"country_code\": \"US\",\n \"phone\": \"408-996-1010\"\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\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/bulk"
payload = "{\n \"rate_options\": {\n \"carrier_ids\": [\n \"se-123890\",\n \"se-123890\"\n ]\n },\n \"shipments\": [{\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 12,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"pound\"\n }\n }]\n },\n {\n \"ship_to\": {\n \"name\": \"Waffle HQ\",\n \"company_name\": \"Waffle House\",\n \"address_line1\": \"5986 Financial Drive\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"Norcross\",\n \"state_province\": \"GA\",\n \"postal_code\": \"30071\",\n \"country_code\": \"US\",\n \"phone\": \"111-111-1111\"\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\n \"ship_to\": {\n \"name\": \"Jony Ive\",\n \"company_name\": \"Apple\",\n \"address_line1\": \"1 Infinite Loop\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"Cupertino\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95014\",\n \"country_code\": \"US\",\n \"phone\": \"408-996-1010\"\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\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/bulk")
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-123890\",\n \"se-123890\"\n ]\n },\n \"shipments\": [{\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 12,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"pound\"\n }\n }]\n },\n {\n \"ship_to\": {\n \"name\": \"Waffle HQ\",\n \"company_name\": \"Waffle House\",\n \"address_line1\": \"5986 Financial Drive\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"Norcross\",\n \"state_province\": \"GA\",\n \"postal_code\": \"30071\",\n \"country_code\": \"US\",\n \"phone\": \"111-111-1111\"\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\n \"ship_to\": {\n \"name\": \"Jony Ive\",\n \"company_name\": \"Apple\",\n \"address_line1\": \"1 Infinite Loop\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"Cupertino\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95014\",\n \"country_code\": \"US\",\n \"phone\": \"408-996-1010\"\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n }\n ]\n}"
response = https.request(request)
puts response.read_body
var client = new RestClient("https://api.shipengine.com/v1/rates/bulk");
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-123890\",\n \"se-123890\"\n ]\n },\n \"shipments\": [{\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 12,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"pound\"\n }\n }]\n },\n {\n \"ship_to\": {\n \"name\": \"Waffle HQ\",\n \"company_name\": \"Waffle House\",\n \"address_line1\": \"5986 Financial Drive\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"Norcross\",\n \"state_province\": \"GA\",\n \"postal_code\": \"30071\",\n \"country_code\": \"US\",\n \"phone\": \"111-111-1111\"\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\n \"ship_to\": {\n \"name\": \"Jony Ive\",\n \"company_name\": \"Apple\",\n \"address_line1\": \"1 Infinite Loop\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"Cupertino\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95014\",\n \"country_code\": \"US\",\n \"phone\": \"408-996-1010\"\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\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-123890\",\n \"se-123890\"\n ]\n },\n \"shipments\": [{\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 12,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"pound\"\n }\n }]\n },\n {\n \"ship_to\": {\n \"name\": \"Waffle HQ\",\n \"company_name\": \"Waffle House\",\n \"address_line1\": \"5986 Financial Drive\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"Norcross\",\n \"state_province\": \"GA\",\n \"postal_code\": \"30071\",\n \"country_code\": \"US\",\n \"phone\": \"111-111-1111\"\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\n \"ship_to\": {\n \"name\": \"Jony Ive\",\n \"company_name\": \"Apple\",\n \"address_line1\": \"1 Infinite Loop\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"Cupertino\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95014\",\n \"country_code\": \"US\",\n \"phone\": \"408-996-1010\"\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n }\n ]\n}");
Request request = new Request.Builder()
.url("https://api.shipengine.com/v1/rates/bulk")
.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/bulk"
method := "POST"
payload := strings.NewReader("{\n \"rate_options\": {\n \"carrier_ids\": [\n \"se-123890\",\n \"se-123890\"\n ]\n },\n \"shipments\": [{\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 12,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"pound\"\n }\n }]\n },\n {\n \"ship_to\": {\n \"name\": \"Waffle HQ\",\n \"company_name\": \"Waffle House\",\n \"address_line1\": \"5986 Financial Drive\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"Norcross\",\n \"state_province\": \"GA\",\n \"postal_code\": \"30071\",\n \"country_code\": \"US\",\n \"phone\": \"111-111-1111\"\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\n \"ship_to\": {\n \"name\": \"Jony Ive\",\n \"company_name\": \"Apple\",\n \"address_line1\": \"1 Infinite Loop\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"Cupertino\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95014\",\n \"country_code\": \"US\",\n \"phone\": \"408-996-1010\"\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\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/bulk"]
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-123890\",\n \"se-123890\"\n ]\n },\n \"shipments\": [{\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 12,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"pound\"\n }\n }]\n },\n {\n \"ship_to\": {\n \"name\": \"Waffle HQ\",\n \"company_name\": \"Waffle House\",\n \"address_line1\": \"5986 Financial Drive\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"Norcross\",\n \"state_province\": \"GA\",\n \"postal_code\": \"30071\",\n \"country_code\": \"US\",\n \"phone\": \"111-111-1111\"\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\n \"ship_to\": {\n \"name\": \"Jony Ive\",\n \"company_name\": \"Apple\",\n \"address_line1\": \"1 Infinite Loop\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"Cupertino\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95014\",\n \"country_code\": \"US\",\n \"phone\": \"408-996-1010\"\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\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-123890\",\n \"se-123890\"\n ]\n },\n \"shipments\": [{\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 12,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"pound\"\n }\n }]\n },\n {\n \"ship_to\": {\n \"name\": \"Waffle HQ\",\n \"company_name\": \"Waffle House\",\n \"address_line1\": \"5986 Financial Drive\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"Norcross\",\n \"state_province\": \"GA\",\n \"postal_code\": \"30071\",\n \"country_code\": \"US\",\n \"phone\": \"111-111-1111\"\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\n \"ship_to\": {\n \"name\": \"Jony Ive\",\n \"company_name\": \"Apple\",\n \"address_line1\": \"1 Infinite Loop\",\n \"address_line2\": null,\n \"address_line3\": null,\n \"city_locality\": \"Cupertino\",\n \"state_province\": \"CA\",\n \"postal_code\": \"95014\",\n \"country_code\": \"US\",\n \"phone\": \"408-996-1010\"\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n },\n {\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 \"packages\": [{\n \"package_code\": \"package\",\n \"weight\": {\n \"value\": 1,\n \"unit\": \"ounce\"\n }\n }]\n }\n ]\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.shipengine.com/v1/rates/bulk")!,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
[
{
"rate_request_id": 501846,
"shipment_id": "se-2127226",
"status": "working",
"created_at": "2019-07-25T15:24:46.657Z"
},
{
"rate_request_id": 501847,
"shipment_id": "se-2127227",
"status": "working",
"created_at": "2019-07-25T15:24:46.657Z"
}
]
[
{
"rate_request_id": 501846,
"shipment_id": "se-2127226",
"status": "working",
"created_at": "2019-07-25T15:24:46.657Z"
},
{
"rate_request_id": 501847,
"shipment_id": "se-2127227",
"status": "working",
"created_at": "2019-07-25T15:24:46.657Z"
}
]
As we've done before in other examples, we have truncated the response to only show a single rate. When you run this command, you will notice that there are many more rates that exist.