Sample code for 30+ languages & platforms
Unicode C++

Shippo Create a New Manifest

See more Shippo Examples

Demonstrates how to create a manifest for your shipments.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    CkHttpW http;

    // Implements the following CURL command:

    // curl https://api.goshippo.com/manifests/
    //     -H "Authorization: ShippoToken shippo_test_831a7a042784f523b95db65444e6e084b636764b" \
    //     -H "Content-Type: application/json"  \
    //     -d '{
    //           "carrier_account": "b741b99f95e841639b54272834bc478c",
    //           "shipment_date": "2014-05-16T23:59:59Z",
    //           "address_from": "28828839a2b04e208ac2aa4945fbca9a",
    //           "transactions": [
    //             "64bba01845ef40d29374032599f22588", 
    //             "c169aa586a844cc49da00d0272b590e1"
    //             ],
    //           "async": false
    //         }'

    // Use this online tool to generate code from sample JSON:
    // Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "carrier_account": "b741b99f95e841639b54272834bc478c",
    //   "shipment_date": "2014-05-16T23:59:59Z",
    //   "address_from": "28828839a2b04e208ac2aa4945fbca9a",
    //   "transactions": [
    //     "64bba01845ef40d29374032599f22588",
    //     "c169aa586a844cc49da00d0272b590e1"
    //   ],
    //   "async": false
    // }

    CkJsonObjectW json;
    json.UpdateString(L"carrier_account",L"b741b99f95e841639b54272834bc478c");
    json.UpdateString(L"shipment_date",L"2014-05-16T23:59:59Z");
    json.UpdateString(L"address_from",L"28828839a2b04e208ac2aa4945fbca9a");
    json.UpdateString(L"transactions[0]",L"64bba01845ef40d29374032599f22588");
    json.UpdateString(L"transactions[1]",L"c169aa586a844cc49da00d0272b590e1");
    json.UpdateBool(L"async",false);

    http.SetRequestHeader(L"Authorization",L"ShippoToken shippo_test_831a7a042784f523b95db65444e6e084b636764b");
    http.SetRequestHeader(L"Content-Type",L"application/json");

    CkHttpResponseW resp;
    success = http.HttpJson(L"POST",L"https://api.goshippo.com/manifests/",json,L"application/json",resp);
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkStringBuilderW sbResponseBody;
    resp.GetBodySb(sbResponseBody);
    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",jResp.emit());

    int respStatusCode = resp.get_StatusCode();
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",resp.header());
        wprintf(L"Failed.\n");
        return;
    }

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

    // {
    //   "address_from": "28828839a2b04e208ac2aa4945fbca9a",
    //   "carrier_account": "b741b99f95e841639b54272834bc478c",
    //   "documents": [
    //     "https://shippo-delivery.s3.amazonaws.com/0fadebf6f60c4aca95fa01bcc59c79ae.pdf?Signature=tlQU3RECwdHUQJQadwqg5bAzGFQ%3D&Expires=1402803835&AWSAccessKeyId=AKIAJTHP3LLFMYAWALIA"
    //   ],
    //   "object_created": "2014-05-16T03:43:52.765Z",
    //   "object_id": "0fadebf6f60c4aca95fa01bcc59c79ae",
    //   "object_owner": "mrhippo@goshippo.com",
    //   "object_updated": "2014-05-16T03:43:55.445Z",
    //   "shipment_date": "2014-05-16T23:59:59Z",
    //   "status": "SUCCESS",
    //   "transactions": [
    //     "64bba01845ef40d29374032599f22588",
    //     "c169aa586a844cc49da00d0272b590e1"
    //   ]
    // }

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    // See this example explaining how this memory should be used: const char * functions.

    const wchar_t *strVal = 0;

    const wchar_t *address_from = jResp.stringOf(L"address_from");
    const wchar_t *carrier_account = jResp.stringOf(L"carrier_account");
    const wchar_t *object_created = jResp.stringOf(L"object_created");
    const wchar_t *object_id = jResp.stringOf(L"object_id");
    const wchar_t *object_owner = jResp.stringOf(L"object_owner");
    const wchar_t *object_updated = jResp.stringOf(L"object_updated");
    const wchar_t *shipment_date = jResp.stringOf(L"shipment_date");
    const wchar_t *status = jResp.stringOf(L"status");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"documents");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"documents[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"transactions");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"transactions[i]");
        i = i + 1;
    }
    }