Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Unicode C++ Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
Jira
Lightspeed
MYOB
Magento
Mailgun
Mastercard

MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(Unicode C++) Shippo Create Shipment Object

Create a Shipment object to retrieve rates. It represents a request to ship a given package from the sender to the recipient address.

For more information, see https://goshippo.com/docs/shipping-labels/

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Solaris C/C++

MinGW C/C++

#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>

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

    CkHttpW http;
    bool success;

    // Implements the following CURL command:

    // curl https://api.goshippo.com/shipments/  \
    //     -H "Authorization: ShippoToken <API_TOKEN>" \
    //     -H "Content-Type: application/json"  \
    //     -d '{
    //        "address_from":{
    //           "name":"Mr. Hippo",
    //           "street1":"215 Clayton St.",
    //           "city":"San Francisco",
    //           "state":"CA",
    //           "zip":"94117",
    //           "country":"US"
    //        },
    //        "address_to":{
    //           "name":"Mrs. Hippo",
    //           "street1":"965 Mission St.",
    //           "city":"San Francisco",
    //           "state":"CA",
    //           "zip":"94105",
    //           "country":"US"
    //        },
    //        "parcels":[{
    //           "length":"5",
    //           "width":"5",
    //           "height":"5",
    //           "distance_unit":"in",
    //           "weight":"2",
    //           "mass_unit":"lb"
    //        }],
    //        "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.

    // {
    //   "address_from": {
    //     "name": "Mr. Hippo",
    //     "street1": "215 Clayton St.",
    //     "city": "San Francisco",
    //     "state": "CA",
    //     "zip": "94117",
    //     "country": "US"
    //   },
    //   "address_to": {
    //     "name": "Mrs. Hippo",
    //     "street1": "965 Mission St.",
    //     "city": "San Francisco",
    //     "state": "CA",
    //     "zip": "94105",
    //     "country": "US"
    //   },
    //   "parcels": [
    //     {
    //       "length": "5",
    //       "width": "5",
    //       "height": "5",
    //       "distance_unit": "in",
    //       "weight": "2",
    //       "mass_unit": "lb"
    //     }
    //   ],
    //   "async": false
    // }

    CkJsonObjectW json;
    json.UpdateString(L"address_from.name",L"Mr. Hippo");
    json.UpdateString(L"address_from.street1",L"215 Clayton St.");
    json.UpdateString(L"address_from.city",L"San Francisco");
    json.UpdateString(L"address_from.state",L"CA");
    json.UpdateString(L"address_from.zip",L"94117");
    json.UpdateString(L"address_from.country",L"US");
    json.UpdateString(L"address_to.name",L"Mrs. Hippo");
    json.UpdateString(L"address_to.street1",L"965 Mission St.");
    json.UpdateString(L"address_to.city",L"San Francisco");
    json.UpdateString(L"address_to.state",L"CA");
    json.UpdateString(L"address_to.zip",L"94105");
    json.UpdateString(L"address_to.country",L"US");
    json.UpdateString(L"parcels[0].length",L"5");
    json.UpdateString(L"parcels[0].width",L"5");
    json.UpdateString(L"parcels[0].height",L"5");
    json.UpdateString(L"parcels[0].distance_unit",L"in");
    json.UpdateString(L"parcels[0].weight",L"2");
    json.UpdateString(L"parcels[0].mass_unit",L"lb");
    json.UpdateBool(L"async",false);

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

    CkHttpResponseW *resp = http.PostJson3(L"https://api.goshippo.com/shipments/",L"application/json",json);
    if (http.get_LastMethodSuccess() == 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");
        delete resp;
        return;
    }

    delete resp;

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

    // {
    //   "carrier_accounts": [
    //   ],
    //   "object_created": "2019-06-28T17:45:20.441Z",
    //   "object_updated": "2019-06-28T17:45:20.511Z",
    //   "object_id": "17b01795a4884d8a9002ccc17c9d09d1",
    //   "object_owner": "admin@chilkatsoft.com",
    //   "status": "SUCCESS",
    //   "address_from": {
    //     "object_id": "427489906b604f498f7bd2429ab7d9a1",
    //     "is_complete": true,
    //     "name": "Mr. Hippo",
    //     "company": "",
    //     "street_no": "",
    //     "street1": "215 Clayton St.",
    //     "validation_results": {},
    //     "street2": "",
    //     "street3": "",
    //     "city": "San Francisco",
    //     "state": "CA",
    //     "zip": "94117",
    //     "country": "US",
    //     "phone": "",
    //     "email": "",
    //     "is_residential": null,
    //     "test": true
    //   },
    //   "address_to": {
    //     "object_id": "3d7166269a2844b7842ef9ace942ec7c",
    //     "is_complete": true,
    //     "name": "Mrs. Hippo",
    //     "company": "",
    //     "street_no": "",
    //     "street1": "965 Mission St.",
    //     "validation_results": {},
    //     "street2": "",
    //     "street3": "",
    //     "city": "San Francisco",
    //     "state": "CA",
    //     "zip": "94105",
    //     "country": "US",
    //     "phone": "",
    //     "email": "",
    //     "is_residential": null,
    //     "test": true
    //   },
    //   "parcels": [
    //     {
    //       "object_state": "VALID",
    //       "object_created": "2019-06-28T17:45:20.411Z",
    //       "object_updated": "2019-06-28T17:45:20.455Z",
    //       "object_id": "5af766ff15684a4186b0e3c833348fac",
    //       "object_owner": "admin@chilkatsoft.com",
    //       "template": null,
    //       "extra": {},
    //       "length": "5.0000",
    //       "width": "5.0000",
    //       "height": "5.0000",
    //       "distance_unit": "in",
    //       "weight": "2.0000",
    //       "mass_unit": "lb",
    //       "value_amount": null,
    //       "value_currency": null,
    //       "metadata": "",
    //       "line_items": [
    //       ],
    //       "test": true
    //     }
    //   ],
    //   "shipment_date": "2019-06-28T17:45:20.511Z",
    //   "address_return": {
    //     "object_id": "427489906b604f498f7bd2429ab7d9a1",
    //     "is_complete": true,
    //     "name": "Mr. Hippo",
    //     "company": "",
    //     "street_no": "",
    //     "street1": "215 Clayton St.",
    //     "validation_results": {},
    //     "street2": "",
    //     "street3": "",
    //     "city": "San Francisco",
    //     "state": "CA",
    //     "zip": "94117",
    //     "country": "US",
    //     "phone": "",
    //     "email": "",
    //     "is_residential": null,
    //     "test": true
    //   },
    //   "alternate_address_to": null,
    //   "customs_declaration": null,
    //   "extra": {},
    //   "rates": [
    //     {
    //       "object_created": "2019-06-28T17:45:20.789Z",
    //       "object_id": "dd7556c284e8444294d2ab7099e662d2",
    //       "object_owner": "admin@chilkatsoft.com",
    //       "shipment": "17b01795a4884d8a9002ccc17c9d09d1",
    //       "attributes": [
    //         "FASTEST"
    //       ],
    //       "amount": "22.78",
    //       "currency": "USD",
    //       "amount_local": "22.78",
    //       "currency_local": "USD",
    //       "provider": "USPS",
    //       "provider_image_75": "https://shippo-static.s3.amazonaws.com/providers/75/USPS.png",
    //       "provider_image_200": "https://shippo-static.s3.amazonaws.com/providers/200/USPS.png",
    //       "servicelevel": {
    //         "name": "Priority Mail Express",
    //         "token": "usps_priority_express",
    //         "terms": ""
    //       },
    //       "estimated_days": 2,
    //       "arrives_by": null,
    //       "duration_terms": "Overnight delivery to most U.S. locations.",
    //       "messages": [
    //       ],
    //       "carrier_account": "1f3dc340ad6c4991ad61f14fa3e4b82e",
    //       "test": true,
    //       "zone": "1"
    //     },
    //     {
    //       "object_created": "2019-06-28T17:45:20.786Z",
    //       "object_id": "ec11cc297e2f4583986097f6d409e5c6",
    //       "object_owner": "admin@chilkatsoft.com",
    //       "shipment": "17b01795a4884d8a9002ccc17c9d09d1",
    //       "attributes": [
    //         "BESTVALUE",
    //         "CHEAPEST",
    //         "FASTEST"
    //       ],
    //       "amount": "6.95",
    //       "currency": "USD",
    //       "amount_local": "6.95",
    //       "currency_local": "USD",
    //       "provider": "USPS",
    //       "provider_image_75": "https://shippo-static.s3.amazonaws.com/providers/75/USPS.png",
    //       "provider_image_200": "https://shippo-static.s3.amazonaws.com/providers/200/USPS.png",
    //       "servicelevel": {
    //         "name": "Priority Mail",
    //         "token": "usps_priority",
    //         "terms": ""
    //       },
    //       "estimated_days": 2,
    //       "arrives_by": null,
    //       "duration_terms": "Delivery within 1, 2, or 3 days based on where your package started and where it’s being sent.",
    //       "messages": [
    //       ],
    //       "carrier_account": "1f3dc340ad6c4991ad61f14fa3e4b82e",
    //       "test": true,
    //       "zone": "1"
    //     },
    //     {
    //       "object_created": "2019-06-28T17:45:20.785Z",
    //       "object_id": "d256586f539f4c93a2f02cc11f4942ac",
    //       "object_owner": "admin@chilkatsoft.com",
    //       "shipment": "17b01795a4884d8a9002ccc17c9d09d1",
    //       "attributes": [
    //       ],
    //       "amount": "7.32",
    //       "currency": "USD",
    //       "amount_local": "7.32",
    //       "currency_local": "USD",
    //       "provider": "USPS",
    //       "provider_image_75": "https://shippo-static.s3.amazonaws.com/providers/75/USPS.png",
    //       "provider_image_200": "https://shippo-static.s3.amazonaws.com/providers/200/USPS.png",
    //       "servicelevel": {
    //         "name": "Parcel Select",
    //         "token": "usps_parcel_select",
    //         "terms": ""
    //       },
    //       "estimated_days": 7,
    //       "arrives_by": null,
    //       "duration_terms": "Delivery in 2 to 8 days.",
    //       "messages": [
    //       ],
    //       "carrier_account": "1f3dc340ad6c4991ad61f14fa3e4b82e",
    //       "test": true,
    //       "zone": "1"
    //     }
    //   ],
    //   "messages": [
    //     {
    //       "source": "DHLExpress",
    //       "code": "",
    //       "text": "Shippo's DHL Express master account doesn't support shipments to inside of the US"
    //     }
    //   ],
    //   "metadata": "",
    //   "test": true,
    //   "order": null
    // }

    // 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 *object_state = 0;
    const wchar_t *template = 0;
    const wchar_t *length = 0;
    const wchar_t *width = 0;
    const wchar_t *height = 0;
    const wchar_t *distance_unit = 0;
    const wchar_t *weight = 0;
    const wchar_t *mass_unit = 0;
    const wchar_t *value_amount = 0;
    const wchar_t *value_currency = 0;
    int j;
    int count_j;
    const wchar_t *shipment = 0;
    const wchar_t *amount = 0;
    const wchar_t *currency = 0;
    const wchar_t *amount_local = 0;
    const wchar_t *currency_local = 0;
    const wchar_t *provider = 0;
    const wchar_t *provider_image_75 = 0;
    const wchar_t *provider_image_200 = 0;
    const wchar_t *servicelevelName = 0;
    const wchar_t *servicelevelToken = 0;
    const wchar_t *servicelevelTerms = 0;
    int estimated_days;
    const wchar_t *arrives_by = 0;
    const wchar_t *duration_terms = 0;
    const wchar_t *carrier_account = 0;
    const wchar_t *zone = 0;
    const wchar_t *strVal = 0;
    const wchar_t *source = 0;
    const wchar_t *code = 0;
    const wchar_t *text = 0;

    const wchar_t *object_created = jResp.stringOf(L"object_created");
    const wchar_t *object_updated = jResp.stringOf(L"object_updated");
    const wchar_t *object_id = jResp.stringOf(L"object_id");
    const wchar_t *object_owner = jResp.stringOf(L"object_owner");
    const wchar_t *status = jResp.stringOf(L"status");
    const wchar_t *address_fromObject_id = jResp.stringOf(L"address_from.object_id");
    bool address_fromIs_complete = jResp.BoolOf(L"address_from.is_complete");
    const wchar_t *address_fromName = jResp.stringOf(L"address_from.name");
    const wchar_t *address_fromCompany = jResp.stringOf(L"address_from.company");
    const wchar_t *address_fromStreet_no = jResp.stringOf(L"address_from.street_no");
    const wchar_t *address_fromStreet1 = jResp.stringOf(L"address_from.street1");
    const wchar_t *address_fromStreet2 = jResp.stringOf(L"address_from.street2");
    const wchar_t *address_fromStreet3 = jResp.stringOf(L"address_from.street3");
    const wchar_t *address_fromCity = jResp.stringOf(L"address_from.city");
    const wchar_t *address_fromState = jResp.stringOf(L"address_from.state");
    const wchar_t *address_fromZip = jResp.stringOf(L"address_from.zip");
    const wchar_t *address_fromCountry = jResp.stringOf(L"address_from.country");
    const wchar_t *address_fromPhone = jResp.stringOf(L"address_from.phone");
    const wchar_t *address_fromEmail = jResp.stringOf(L"address_from.email");
    const wchar_t *address_fromIs_residential = jResp.stringOf(L"address_from.is_residential");
    bool address_fromTest = jResp.BoolOf(L"address_from.test");
    const wchar_t *address_toObject_id = jResp.stringOf(L"address_to.object_id");
    bool address_toIs_complete = jResp.BoolOf(L"address_to.is_complete");
    const wchar_t *address_toName = jResp.stringOf(L"address_to.name");
    const wchar_t *address_toCompany = jResp.stringOf(L"address_to.company");
    const wchar_t *address_toStreet_no = jResp.stringOf(L"address_to.street_no");
    const wchar_t *address_toStreet1 = jResp.stringOf(L"address_to.street1");
    const wchar_t *address_toStreet2 = jResp.stringOf(L"address_to.street2");
    const wchar_t *address_toStreet3 = jResp.stringOf(L"address_to.street3");
    const wchar_t *address_toCity = jResp.stringOf(L"address_to.city");
    const wchar_t *address_toState = jResp.stringOf(L"address_to.state");
    const wchar_t *address_toZip = jResp.stringOf(L"address_to.zip");
    const wchar_t *address_toCountry = jResp.stringOf(L"address_to.country");
    const wchar_t *address_toPhone = jResp.stringOf(L"address_to.phone");
    const wchar_t *address_toEmail = jResp.stringOf(L"address_to.email");
    const wchar_t *address_toIs_residential = jResp.stringOf(L"address_to.is_residential");
    bool address_toTest = jResp.BoolOf(L"address_to.test");
    const wchar_t *shipment_date = jResp.stringOf(L"shipment_date");
    const wchar_t *address_returnObject_id = jResp.stringOf(L"address_return.object_id");
    bool address_returnIs_complete = jResp.BoolOf(L"address_return.is_complete");
    const wchar_t *address_returnName = jResp.stringOf(L"address_return.name");
    const wchar_t *address_returnCompany = jResp.stringOf(L"address_return.company");
    const wchar_t *address_returnStreet_no = jResp.stringOf(L"address_return.street_no");
    const wchar_t *address_returnStreet1 = jResp.stringOf(L"address_return.street1");
    const wchar_t *address_returnStreet2 = jResp.stringOf(L"address_return.street2");
    const wchar_t *address_returnStreet3 = jResp.stringOf(L"address_return.street3");
    const wchar_t *address_returnCity = jResp.stringOf(L"address_return.city");
    const wchar_t *address_returnState = jResp.stringOf(L"address_return.state");
    const wchar_t *address_returnZip = jResp.stringOf(L"address_return.zip");
    const wchar_t *address_returnCountry = jResp.stringOf(L"address_return.country");
    const wchar_t *address_returnPhone = jResp.stringOf(L"address_return.phone");
    const wchar_t *address_returnEmail = jResp.stringOf(L"address_return.email");
    const wchar_t *address_returnIs_residential = jResp.stringOf(L"address_return.is_residential");
    bool address_returnTest = jResp.BoolOf(L"address_return.test");
    const wchar_t *alternate_address_to = jResp.stringOf(L"alternate_address_to");
    const wchar_t *customs_declaration = jResp.stringOf(L"customs_declaration");
    const wchar_t *metadata = jResp.stringOf(L"metadata");
    bool test = jResp.BoolOf(L"test");
    const wchar_t *order = jResp.stringOf(L"order");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"carrier_accounts");
    while (i < count_i) {
        jResp.put_I(i);
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"parcels");
    while (i < count_i) {
        jResp.put_I(i);
        object_state = jResp.stringOf(L"parcels[i].object_state");
        object_created = jResp.stringOf(L"parcels[i].object_created");
        object_updated = jResp.stringOf(L"parcels[i].object_updated");
        object_id = jResp.stringOf(L"parcels[i].object_id");
        object_owner = jResp.stringOf(L"parcels[i].object_owner");
        template = jResp.stringOf(L"parcels[i].template");
        length = jResp.stringOf(L"parcels[i].length");
        width = jResp.stringOf(L"parcels[i].width");
        height = jResp.stringOf(L"parcels[i].height");
        distance_unit = jResp.stringOf(L"parcels[i].distance_unit");
        weight = jResp.stringOf(L"parcels[i].weight");
        mass_unit = jResp.stringOf(L"parcels[i].mass_unit");
        value_amount = jResp.stringOf(L"parcels[i].value_amount");
        value_currency = jResp.stringOf(L"parcels[i].value_currency");
        metadata = jResp.stringOf(L"parcels[i].metadata");
        test = jResp.BoolOf(L"parcels[i].test");
        j = 0;
        count_j = jResp.SizeOfArray(L"parcels[i].line_items");
        while (j < count_j) {
            jResp.put_J(j);
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"rates");
    while (i < count_i) {
        jResp.put_I(i);
        object_created = jResp.stringOf(L"rates[i].object_created");
        object_id = jResp.stringOf(L"rates[i].object_id");
        object_owner = jResp.stringOf(L"rates[i].object_owner");
        shipment = jResp.stringOf(L"rates[i].shipment");
        amount = jResp.stringOf(L"rates[i].amount");
        currency = jResp.stringOf(L"rates[i].currency");
        amount_local = jResp.stringOf(L"rates[i].amount_local");
        currency_local = jResp.stringOf(L"rates[i].currency_local");
        provider = jResp.stringOf(L"rates[i].provider");
        provider_image_75 = jResp.stringOf(L"rates[i].provider_image_75");
        provider_image_200 = jResp.stringOf(L"rates[i].provider_image_200");
        servicelevelName = jResp.stringOf(L"rates[i].servicelevel.name");
        servicelevelToken = jResp.stringOf(L"rates[i].servicelevel.token");
        servicelevelTerms = jResp.stringOf(L"rates[i].servicelevel.terms");
        estimated_days = jResp.IntOf(L"rates[i].estimated_days");
        arrives_by = jResp.stringOf(L"rates[i].arrives_by");
        duration_terms = jResp.stringOf(L"rates[i].duration_terms");
        carrier_account = jResp.stringOf(L"rates[i].carrier_account");
        test = jResp.BoolOf(L"rates[i].test");
        zone = jResp.stringOf(L"rates[i].zone");
        j = 0;
        count_j = jResp.SizeOfArray(L"rates[i].attributes");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf(L"rates[i].attributes[j]");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"rates[i].messages");
        while (j < count_j) {
            jResp.put_J(j);
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"messages");
    while (i < count_i) {
        jResp.put_I(i);
        source = jResp.stringOf(L"messages[i].source");
        code = jResp.stringOf(L"messages[i].code");
        text = jResp.stringOf(L"messages[i].text");
        i = i + 1;
    }
    }

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.