Sample code for 30+ languages & platforms
Dart

Shippo POST to Transaction Endpoint

See more Shippo Examples

Demonstrates how to POST to the Transaction endpoint with your Rate object_id to purchase your international shipping label.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // This example assumes the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  final http = CkHttp();

  // Implements the following CURL command:

  // curl https://api.goshippo.com/transactions \
  //     -H "Authorization: ShippoToken <API_TOKEN>" \
  //     -d rate="ec6143e746094bcab1bdc4c17600dabf"
  //     -d label_file_type="PDF"
  //     -d async=false

  final req = CkHttpRequest();
  req.httpVerb = 'POST';
  req.path = '/transactions';
  req.contentType = 'application/x-www-form-urlencoded';
  req.addParam('rate', 'ec6143e746094bcab1bdc4c17600dabf');
  req.addParam('label_file_type', 'PDF');
  req.addParam('async', 'false');

  req.addHeader('Authorization', 'ShippoToken <API_TOKEN>');

  final resp = CkHttpResponse();
  try {
    http.httpReq('https://api.goshippo.com/transactions', req, resp);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final sbResponseBody = CkStringBuilder();
  resp.getBodySb(sbResponseBody);
  final jResp = CkJsonObject();
  jResp.loadSb(sbResponseBody);
  jResp.emitCompact = false;

  print('Response Body:');
  print(jResp.emit());

  final respStatusCode = resp.statusCode;
  print('Response Status Code = $respStatusCode');
  if (respStatusCode >= 400) {
    print('Response Header:');
    print(resp.header);
    print('Failed.');
    return;
  }

  // Sample JSON response:
  // (Sample code for parsing the JSON response is shown below)

  // {
  //   "object_state": "VALID",
  //   "status": "SUCCESS",
  //   "object_created": "2013-12-27T19:14:48.273Z",
  //   "object_updated": "2013-12-27T19:14:48.273Z",
  //   "object_id": "64bba01845ef40d29374032599f22588",
  //   "object_owner": "shippotle@goshippo.com",
  //   "was_test": false,
  //   "rate": {
  //     "object_id": "cf6fea899f1848b494d9568e8266e076",
  //     "amount": "5.50",
  //     "currency": "USD",
  //     "amount_local": "5.50",
  //     "currency_local": "USD",
  //     "provider": "USPS",
  //     "servicelevel_name": "Priority Mail",
  //     "servicelevel_token": "usps_priority",
  //     "carrier_account": "078870331023437cb917f5187429b093"
  //   },
  //   "tracking_number": "ZW70QJC",
  //   "tracking_status": {
  //     "object_created": "2013-12-27T23:17:41.411Z",
  //     "object_id": "a21b3d6831c14ceaba6730179ce6e784",
  //     "status": "UNKNOWN",
  //     "status_details": "",
  //     "status_date": "2013-12-28T12:04:04.214Z"
  //   },
  //   "tracking_url_provider": "https://tools.usps.com/go/TrackConfirmAction.action?tLabels=ZW70QJC",
  //   "eta": "2013-12-30T12:00:00.000Z",
  //   "label_url": "https://shippo-delivery.s3.amazonaws.com/96.pdf?Signature=PEdWrp0mFWAGwJp7FW3b%2FeA2eyY%3D&Expires=1385930652&AWSAccessKeyId=AKIAJTHP3LLFMYAWALIA",
  //   "commercial_invoice_url": "",
  //   "metadata": "",
  //   "messages": [
  //   ]
  // }

  // Sample code for parsing the JSON response...
  // Use the following online tool to generate parsing code from sample JSON:
  // Generate Parsing Code from JSON

  final objectState = jResp.stringOf('object_state');
  final status = jResp.stringOf('status');
  final objectCreated = jResp.stringOf('object_created');
  final objectUpdated = jResp.stringOf('object_updated');
  final objectId = jResp.stringOf('object_id');
  final objectOwner = jResp.stringOf('object_owner');
  final rateObjectId = jResp.stringOf('rate.object_id');
  final rateAmount = jResp.stringOf('rate.amount');
  final rateCurrency = jResp.stringOf('rate.currency');
  final rateAmountLocal = jResp.stringOf('rate.amount_local');
  final rateCurrencyLocal = jResp.stringOf('rate.currency_local');
  final rateProvider = jResp.stringOf('rate.provider');
  final rateServicelevelName = jResp.stringOf('rate.servicelevel_name');
  final rateServicelevelToken = jResp.stringOf('rate.servicelevel_token');
  final rateCarrierAccount = jResp.stringOf('rate.carrier_account');
  final trackingNumber = jResp.stringOf('tracking_number');
  final trackingStatusObjectCreated = jResp.stringOf('tracking_status.object_created');
  final trackingStatusObjectId = jResp.stringOf('tracking_status.object_id');
  final trackingStatusStatus = jResp.stringOf('tracking_status.status');
  final trackingStatusStatusDetails = jResp.stringOf('tracking_status.status_details');
  final trackingStatusStatusDate = jResp.stringOf('tracking_status.status_date');
  final trackingUrlProvider = jResp.stringOf('tracking_url_provider');
  final eta = jResp.stringOf('eta');
  final labelUrl = jResp.stringOf('label_url');
  final commercialInvoiceUrl = jResp.stringOf('commercial_invoice_url');
  final metadata = jResp.stringOf('metadata');
  var i = 0;
  final countI = jResp.sizeOfArray('messages');
  while (i < countI) {
    jResp.i = i;
    i++;
  }
}