Chilkat Online Tools

C / ShipEngine Walkthrough / Get a specific carrier

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jResp;
    int respStatusCode;
    const char *service_code;
    const char *name;
    BOOL domestic;
    BOOL international;
    BOOL is_multi_package_supported;
    const char *package_id;
    const char *package_code;
    const char *description;
    const char *default_value;
    const char *carrier_id;
    const char *carrier_code;
    const char *account_number;
    BOOL requires_funded_amount;
    const char *balance;
    const char *nickname;
    const char *friendly_name;
    BOOL primary;
    BOOL has_multi_package_supporting_services;
    BOOL supports_label_messages;
    int i;
    int count_i;

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

    http = CkHttp_Create();

    CkHttp_SetRequestHeader(http,"API-Key","{{API_KEY}}");

    sbResponseBody = CkStringBuilder_Create();
    success = CkHttp_QuickGetSb(http,"https://api.shipengine.com/v1/carriers/se-963358",sbResponseBody);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObject_Create();
    CkJsonObject_LoadSb(jResp,sbResponseBody);
    CkJsonObject_putEmitCompact(jResp,FALSE);

    printf("Response Body:\n");
    printf("%s\n",CkJsonObject_emit(jResp));

    respStatusCode = CkHttp_getLastStatus(http);
    printf("Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        printf("Response Header:\n");
        printf("%s\n",CkHttp_lastHeader(http));
        printf("Failed.\n");
        CkHttp_Dispose(http);
        CkStringBuilder_Dispose(sbResponseBody);
        CkJsonObject_Dispose(jResp);
        return;
    }

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

    // {
    //   "carrier_id": "se-121861",
    //   "carrier_code": "stamps_com",
    //   "account_number": "test_account_121861",
    //   "requires_funded_amount": true,
    //   "balance": 8343.36,
    //   "nickname": "ShipEngine Test Account - Stamps.com",
    //   "friendly_name": "Stamps.com",
    //   "primary": false,
    //   "has_multi_package_supporting_services": false,
    //   "supports_label_messages": true,
    //   "services": [
    //     {
    //       "carrier_id": "se-121861",
    //       "carrier_code": "stamps_com",
    //       "service_code": "usps_first_class_mail",
    //       "name": "USPS First Class Mail",
    //       "domestic": true,
    //       "international": false,
    //       "is_multi_package_supported": false
    //     },
    //     {
    //       "carrier_id": "se-121861",
    //       "carrier_code": "stamps_com",
    //       "service_code": "usps_media_mail",
    //       "name": "USPS Media Mail",
    //       "domestic": true,
    //       "international": false,
    //       "is_multi_package_supported": false
    //     },
    //     {
    //       "carrier_id": "se-121861",
    //       "carrier_code": "stamps_com",
    //       "service_code": "usps_parcel_select",
    //       "name": "USPS Parcel Select Ground",
    //       "domestic": true,
    //       "international": false,
    //       "is_multi_package_supported": false
    //     },
    //     {
    //       "carrier_id": "se-121861",
    //       "carrier_code": "stamps_com",
    //       "service_code": "usps_priority_mail",
    //       "name": "USPS Priority Mail",
    //       "domestic": true,
    //       "international": false,
    //       "is_multi_package_supported": false
    //     },
    //     {
    //       "carrier_id": "se-121861",
    //       "carrier_code": "stamps_com",
    //       "service_code": "usps_priority_mail_express",
    //       "name": "USPS Priority Mail Express",
    //       "domestic": true,
    //       "international": false,
    //       "is_multi_package_supported": false
    //     },
    //     {
    //       "carrier_id": "se-121861",
    //       "carrier_code": "stamps_com",
    //       "service_code": "usps_first_class_mail_international",
    //       "name": "USPS First Class Mail Intl",
    //       "domestic": false,
    //       "international": true,
    //       "is_multi_package_supported": false
    //     },
    //     {
    //       "carrier_id": "se-121861",
    //       "carrier_code": "stamps_com",
    //       "service_code": "usps_priority_mail_international",
    //       "name": "USPS Priority Mail Intl",
    //       "domestic": false,
    //       "international": true,
    //       "is_multi_package_supported": false
    //     },
    //     {
    //       "carrier_id": "se-121861",
    //       "carrier_code": "stamps_com",
    //       "service_code": "usps_priority_mail_express_international",
    //       "name": "USPS Priority Mail Express Intl",
    //       "domestic": false,
    //       "international": true,
    //       "is_multi_package_supported": false
    //     }
    //   ],
    //   "packages": [
    //     {
    //       "package_id": null,
    //       "package_code": "cubic",
    //       "name": "Cubic",
    //       "description": "Cubic"
    //     },
    //     {
    //       "package_id": null,
    //       "package_code": "flat_rate_envelope",
    //       "name": "Flat Rate Envelope",
    //       "description": "USPS flat rate envelope. A special cardboard envelope provided by the USPS that clearly indicates \"Flat Rate\"."
    //     },
    //     {
    //       "package_id": null,
    //       "package_code": "flat_rate_legal_envelope",
    //       "name": "Flat Rate Legal Envelope",
    //       "description": "Flat Rate Legal Envelope"
    //     },
    //     {
    //       "package_id": null,
    //       "package_code": "flat_rate_padded_envelope",
    //       "name": "Flat Rate Padded Envelope",
    //       "description": "Flat Rate Padded Envelope"
    //     },
    //     {
    //       "package_id": null,
    //       "package_code": "large_envelope_or_flat",
    //       "name": "Large Envelope or Flat",
    //       "description": "Large envelope or flat. Has one dimension that is between 11 1/2\" and 15\" long, 6 1/18\" and 12\" high, or 1/4\" and 3/4\" thick."
    //     },
    //     {
    //       "package_id": null,
    //       "package_code": "large_flat_rate_box",
    //       "name": "Large Flat Rate Box",
    //       "description": "Large Flat Rate Box"
    //     },
    //     {
    //       "package_id": null,
    //       "package_code": "large_package",
    //       "name": "Large Package (any side > 12\")",
    //       "description": "Large package. Longest side plus the distance around the thickest part is over 84\" and less than or equal to 108\"."
    //     },
    //     {
    //       "package_id": null,
    //       "package_code": "letter",
    //       "name": "Letter",
    //       "description": "Letter"
    //     },
    //     {
    //       "package_id": null,
    //       "package_code": "medium_flat_rate_box",
    //       "name": "Medium Flat Rate Box",
    //       "description": "USPS flat rate box. A special 11\" x 8 1/2\" x 5 1/2\" or 14\" x 3.5\" x 12\" USPS box that clearly indicates \"Flat Rate Box\""
    //     },
    //     {
    //       "package_id": null,
    //       "package_code": "package",
    //       "name": "Package",
    //       "description": "Package. Longest side plus the distance around the thickest part is less than or equal to 84\""
    //     },
    //     {
    //       "package_id": null,
    //       "package_code": "regional_rate_box_a",
    //       "name": "Regional Rate Box A",
    //       "description": "Regional Rate Box A"
    //     },
    //     {
    //       "package_id": null,
    //       "package_code": "regional_rate_box_b",
    //       "name": "Regional Rate Box B",
    //       "description": "Regional Rate Box B"
    //     },
    //     {
    //       "package_id": null,
    //       "package_code": "small_flat_rate_box",
    //       "name": "Small Flat Rate Box",
    //       "description": "Small Flat Rate Box"
    //     },
    //     {
    //       "package_id": null,
    //       "package_code": "thick_envelope",
    //       "name": "Thick Envelope",
    //       "description": "Thick envelope. Envelopes or flats greater than 3/4\" at the thickest point."
    //     }
    //   ],
    //   "options": [
    //     {
    //       "name": "non_machinable",
    //       "default_value": "false",
    //       "description": ""
    //     }
    //   ]
    // }

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    carrier_id = CkJsonObject_stringOf(jResp,"carrier_id");
    carrier_code = CkJsonObject_stringOf(jResp,"carrier_code");
    account_number = CkJsonObject_stringOf(jResp,"account_number");
    requires_funded_amount = CkJsonObject_BoolOf(jResp,"requires_funded_amount");
    balance = CkJsonObject_stringOf(jResp,"balance");
    nickname = CkJsonObject_stringOf(jResp,"nickname");
    friendly_name = CkJsonObject_stringOf(jResp,"friendly_name");
    primary = CkJsonObject_BoolOf(jResp,"primary");
    has_multi_package_supporting_services = CkJsonObject_BoolOf(jResp,"has_multi_package_supporting_services");
    supports_label_messages = CkJsonObject_BoolOf(jResp,"supports_label_messages");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"services");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        carrier_id = CkJsonObject_stringOf(jResp,"services[i].carrier_id");
        carrier_code = CkJsonObject_stringOf(jResp,"services[i].carrier_code");
        service_code = CkJsonObject_stringOf(jResp,"services[i].service_code");
        name = CkJsonObject_stringOf(jResp,"services[i].name");
        domestic = CkJsonObject_BoolOf(jResp,"services[i].domestic");
        international = CkJsonObject_BoolOf(jResp,"services[i].international");
        is_multi_package_supported = CkJsonObject_BoolOf(jResp,"services[i].is_multi_package_supported");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"packages");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        package_id = CkJsonObject_stringOf(jResp,"packages[i].package_id");
        package_code = CkJsonObject_stringOf(jResp,"packages[i].package_code");
        name = CkJsonObject_stringOf(jResp,"packages[i].name");
        description = CkJsonObject_stringOf(jResp,"packages[i].description");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"options");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        name = CkJsonObject_stringOf(jResp,"options[i].name");
        default_value = CkJsonObject_stringOf(jResp,"options[i].default_value");
        description = CkJsonObject_stringOf(jResp,"options[i].description");
        i = i + 1;
    }



    CkHttp_Dispose(http);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jResp);

    }

Curl Command

curl -X GET
	-H "API-Key: {{API_KEY}}"
https://api.shipengine.com/v1/carriers/se-963358

Postman Collection Item JSON

{
  "name": "Get a specific carrier",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "let response = pm.response.json();",
          "",
          "if (response) {",
          "    const template = `",
          "        <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css\">",
          "        <link rel=\"stylesheet\" href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css\">",
          "        ",
          "        <img alt=\"{{nickname}}\" class=\"w-25 ml-5 mb-5 float-right\"",
          "        src=\"https://www.shipengine.com/docs/img/logos/carriers/{{carrier_code}}.svg\">",
          "",
          "        <h1>{{nickname}}</h1>",
          "        <table class=\"table w-50 mt-2\">",
          "            <tr>",
          "                <th>Carrier ID:</th>",
          "                <td>{{carrier_id}}</td>",
          "            </tr>",
          "            <tr>",
          "                <th>Carrier Code:</th>",
          "                <td>",
          "                    <samp>{{carrier_code}}</samp>",
          "                </td>",
          "            </tr>",
          "            <tr>",
          "                <th>Account Number</th>",
          "                <td>{{account_number}}</td>",
          "            </tr>",
          "        </table>",
          "        ",
          "        <div class=\"container-fluid\">",
          "            <div class=\"row\">",
          "                <div class=\"col-lg-4 mt-4\">",
          "                    <h2>Services Offered</h2>",
          "                    <ul style=\"list-style: circle inside\">",
          "                        {{#each services}}",
          "                            <li>{{name}}</li>",
          "                        {{/each}}",
          "                    </ul>",
          "                </div>",
          "                <div class=\"col-lg-4 mt-4\">",
          "                    <h2>Package Types</h2>",
          "                    <ul style=\"list-style: circle inside\">",
          "                        {{#each packages}}",
          "                            <li>{{name}}</li>",
          "                        {{/each}}",
          "                    </ul>",
          "                </div>",
          "                <div class=\"col-lg-4 mt-4\">",
          "                    <h2>Options</h2>",
          "                    <ul style=\"list-style: circle inside\">",
          "                        {{#each options}}",
          "                            <li>{{name}}</li>",
          "                        {{/each}}",
          "                    </ul>",
          "                </div>",
          "            </div>",
          "        </div>",
          "    `;",
          "    ",
          "    pm.visualizer.set(template, response);",
          "}"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.shipengine.com/v1/carriers/{{stamps_com}}",
      "protocol": "https",
      "host": [
        "api",
        "shipengine",
        "com"
      ],
      "path": [
        "v1",
        "carriers",
        "{{stamps_com}}"
      ]
    },
    "description": "You can get all the information about a specific carrier if you already know its `carrier_id`."
  },
  "response": [
    {
      "name": "Get a specific carrier",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.shipengine.com/v1/carriers/{{stamps_com}}",
          "protocol": "https",
          "host": [
            "api",
            "shipengine",
            "com"
          ],
          "path": [
            "v1",
            "carriers",
            "{{stamps_com}}"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Mon, 16 Sep 2019 20:58:56 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json; charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "5628"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Access-Control-Allow-Origin",
          "value": "https://www.shipengine.com"
        },
        {
          "key": "Vary",
          "value": "Origin"
        },
        {
          "key": "x-shipengine-requestid",
          "value": "123c7951-2ec5-40b9-8004-f5b23f4c2c5f"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"carrier_id\": \"se-121861\",\n    \"carrier_code\": \"stamps_com\",\n    \"account_number\": \"test_account_121861\",\n    \"requires_funded_amount\": true,\n    \"balance\": 8343.36,\n    \"nickname\": \"ShipEngine Test Account - Stamps.com\",\n    \"friendly_name\": \"Stamps.com\",\n    \"primary\": false,\n    \"has_multi_package_supporting_services\": false,\n    \"supports_label_messages\": true,\n    \"services\": [\n        {\n            \"carrier_id\": \"se-121861\",\n            \"carrier_code\": \"stamps_com\",\n            \"service_code\": \"usps_first_class_mail\",\n            \"name\": \"USPS First Class Mail\",\n            \"domestic\": true,\n            \"international\": false,\n            \"is_multi_package_supported\": false\n        },\n        {\n            \"carrier_id\": \"se-121861\",\n            \"carrier_code\": \"stamps_com\",\n            \"service_code\": \"usps_media_mail\",\n            \"name\": \"USPS Media Mail\",\n            \"domestic\": true,\n            \"international\": false,\n            \"is_multi_package_supported\": false\n        },\n        {\n            \"carrier_id\": \"se-121861\",\n            \"carrier_code\": \"stamps_com\",\n            \"service_code\": \"usps_parcel_select\",\n            \"name\": \"USPS Parcel Select Ground\",\n            \"domestic\": true,\n            \"international\": false,\n            \"is_multi_package_supported\": false\n        },\n        {\n            \"carrier_id\": \"se-121861\",\n            \"carrier_code\": \"stamps_com\",\n            \"service_code\": \"usps_priority_mail\",\n            \"name\": \"USPS Priority Mail\",\n            \"domestic\": true,\n            \"international\": false,\n            \"is_multi_package_supported\": false\n        },\n        {\n            \"carrier_id\": \"se-121861\",\n            \"carrier_code\": \"stamps_com\",\n            \"service_code\": \"usps_priority_mail_express\",\n            \"name\": \"USPS Priority Mail Express\",\n            \"domestic\": true,\n            \"international\": false,\n            \"is_multi_package_supported\": false\n        },\n        {\n            \"carrier_id\": \"se-121861\",\n            \"carrier_code\": \"stamps_com\",\n            \"service_code\": \"usps_first_class_mail_international\",\n            \"name\": \"USPS First Class Mail Intl\",\n            \"domestic\": false,\n            \"international\": true,\n            \"is_multi_package_supported\": false\n        },\n        {\n            \"carrier_id\": \"se-121861\",\n            \"carrier_code\": \"stamps_com\",\n            \"service_code\": \"usps_priority_mail_international\",\n            \"name\": \"USPS Priority Mail Intl\",\n            \"domestic\": false,\n            \"international\": true,\n            \"is_multi_package_supported\": false\n        },\n        {\n            \"carrier_id\": \"se-121861\",\n            \"carrier_code\": \"stamps_com\",\n            \"service_code\": \"usps_priority_mail_express_international\",\n            \"name\": \"USPS Priority Mail Express Intl\",\n            \"domestic\": false,\n            \"international\": true,\n            \"is_multi_package_supported\": false\n        }\n    ],\n    \"packages\": [\n        {\n            \"package_id\": null,\n            \"package_code\": \"cubic\",\n            \"name\": \"Cubic\",\n            \"description\": \"Cubic\"\n        },\n        {\n            \"package_id\": null,\n            \"package_code\": \"flat_rate_envelope\",\n            \"name\": \"Flat Rate Envelope\",\n            \"description\": \"USPS flat rate envelope. A special cardboard envelope provided by the USPS that clearly indicates \\\"Flat Rate\\\".\"\n        },\n        {\n            \"package_id\": null,\n            \"package_code\": \"flat_rate_legal_envelope\",\n            \"name\": \"Flat Rate Legal Envelope\",\n            \"description\": \"Flat Rate Legal Envelope\"\n        },\n        {\n            \"package_id\": null,\n            \"package_code\": \"flat_rate_padded_envelope\",\n            \"name\": \"Flat Rate Padded Envelope\",\n            \"description\": \"Flat Rate Padded Envelope\"\n        },\n        {\n            \"package_id\": null,\n            \"package_code\": \"large_envelope_or_flat\",\n            \"name\": \"Large Envelope or Flat\",\n            \"description\": \"Large envelope or flat. Has one dimension that is between 11 1/2\\\" and 15\\\" long, 6 1/18\\\" and 12\\\" high, or 1/4\\\" and 3/4\\\" thick.\"\n        },\n        {\n            \"package_id\": null,\n            \"package_code\": \"large_flat_rate_box\",\n            \"name\": \"Large Flat Rate Box\",\n            \"description\": \"Large Flat Rate Box\"\n        },\n        {\n            \"package_id\": null,\n            \"package_code\": \"large_package\",\n            \"name\": \"Large Package (any side > 12\\\")\",\n            \"description\": \"Large package. Longest side plus the distance around the thickest part is over 84\\\" and less than or equal to 108\\\".\"\n        },\n        {\n            \"package_id\": null,\n            \"package_code\": \"letter\",\n            \"name\": \"Letter\",\n            \"description\": \"Letter\"\n        },\n        {\n            \"package_id\": null,\n            \"package_code\": \"medium_flat_rate_box\",\n            \"name\": \"Medium Flat Rate Box\",\n            \"description\": \"USPS flat rate box. A special 11\\\" x 8 1/2\\\" x 5 1/2\\\" or 14\\\" x 3.5\\\" x 12\\\" USPS box that clearly indicates \\\"Flat Rate Box\\\"\"\n        },\n        {\n            \"package_id\": null,\n            \"package_code\": \"package\",\n            \"name\": \"Package\",\n            \"description\": \"Package. Longest side plus the distance around the thickest part is less than or equal to 84\\\"\"\n        },\n        {\n            \"package_id\": null,\n            \"package_code\": \"regional_rate_box_a\",\n            \"name\": \"Regional Rate Box A\",\n            \"description\": \"Regional Rate Box A\"\n        },\n        {\n            \"package_id\": null,\n            \"package_code\": \"regional_rate_box_b\",\n            \"name\": \"Regional Rate Box B\",\n            \"description\": \"Regional Rate Box B\"\n        },\n        {\n            \"package_id\": null,\n            \"package_code\": \"small_flat_rate_box\",\n            \"name\": \"Small Flat Rate Box\",\n            \"description\": \"Small Flat Rate Box\"\n        },\n        {\n            \"package_id\": null,\n            \"package_code\": \"thick_envelope\",\n            \"name\": \"Thick Envelope\",\n            \"description\": \"Thick envelope. Envelopes or flats greater than 3/4\\\" at the thickest point.\"\n        }\n    ],\n    \"options\": [\n        {\n            \"name\": \"non_machinable\",\n            \"default_value\": \"false\",\n            \"description\": \"\"\n        }\n    ]\n}"
    }
  ]
}