Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Unicode C Web API Examples

Primary Categories

ABN AMRO
AWS Translate
Activix CRM
Adyen
Amazon MWS
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bitfinex v2 REST
Bluzone
CardConnect
ClickBank
Clickatell
Cloudfare
DocuSign
ETrade
Etsy
Facebook
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Hungary NAV Invoicing
IBM Text to Speech
Jira
MYOB
Magento

MercadoLibre
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Okta OAuth/OIDC
OneLogin OIDC
PayPal
Peoplevox
Populi
QuickBooks
Rabobank
SOAP finkok.com
Shippo
Shopify
SimpleTexting
Square
Stripe
SugarCRM
Trello
Twilio
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
WhatsApp
WooCommerce
Xero
Yousign
_Miscellaneous_
eBay
effectconnect

 

 

 

(Unicode C) Shopify Create a new product with multiple product variants

Create a new product with multiple product variants

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++

Win Mobile 5.0/Pocket PC 2003

Solaris C/C++

FreeBSD C/C++

OpenBSD C/C++

MinGW C/C++

#include <C_CkRestW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    HCkJsonObjectW jsonReq;
    HCkStringBuilderW sbReq;
    HCkStringBuilderW sbJson;
    HCkJsonObjectW json;
    int productId;
    const wchar_t *productTitle;
    const wchar_t *productBody_html;
    const wchar_t *productVendor;
    const wchar_t *productProduct_type;
    const wchar_t *productCreated_at;
    const wchar_t *productHandle;
    const wchar_t *productUpdated_at;
    const wchar_t *productPublished_at;
    BOOL productTemplate_suffix;
    const wchar_t *productPublished_scope;
    const wchar_t *productTags;
    BOOL productImage;
    int i;
    int count_i;
    int id;
    int product_id;
    const wchar_t *title;
    const wchar_t *price;
    const wchar_t *sku;
    int position;
    int grams;
    const wchar_t *inventory_policy;
    BOOL compare_at_price;
    const wchar_t *fulfillment_service;
    BOOL inventory_management;
    const wchar_t *option1;
    BOOL option2;
    BOOL option3;
    const wchar_t *created_at;
    const wchar_t *updated_at;
    BOOL taxable;
    BOOL barcode;
    BOOL image_id;
    int inventory_quantity;
    int weight;
    const wchar_t *weight_unit;
    int old_inventory_quantity;
    BOOL requires_shipping;
    const wchar_t *name;
    int j;
    int count_j;
    const wchar_t *strVal;

    rest = CkRestW_Create();

    CkRestW_SetAuthBasic(rest,L"SHOPIFY_PRIVATE_API_KEY",L"SHOPIFY_PRIVATE_API_KEY");

    success = CkRestW_Connect(rest,L"chilkat.myshopify.com",443,TRUE,TRUE);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    // The following code creates the JSON request body.
    // The JSON created by this code is shown below.
    jsonReq = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(jsonReq,L"product.title",L"Burton Custom Freestyle 151");
    CkJsonObjectW_UpdateString(jsonReq,L"product.body_html",L"<strong>Good snowboard!</strong>");
    CkJsonObjectW_UpdateString(jsonReq,L"product.vendor",L"Burton");
    CkJsonObjectW_UpdateString(jsonReq,L"product.product_type",L"Snowboard");
    CkJsonObjectW_UpdateString(jsonReq,L"product.variants[0].option1",L"First");
    CkJsonObjectW_UpdateString(jsonReq,L"product.variants[0].price",L"10.00");
    CkJsonObjectW_UpdateString(jsonReq,L"product.variants[0].sku",L"123");
    CkJsonObjectW_UpdateString(jsonReq,L"product.variants[1].option1",L"Second");
    CkJsonObjectW_UpdateString(jsonReq,L"product.variants[1].price",L"20.00");
    CkJsonObjectW_UpdateString(jsonReq,L"product.variants[1].sku",L"123");

    // The JSON request body created by the above code:

    // {
    //   "product": {
    //     "title": "Burton Custom Freestyle 151",
    //     "body_html": "<strong>Good snowboard!<\/strong>",
    //     "vendor": "Burton",
    //     "product_type": "Snowboard",
    //     "variants": [
    //       {
    //         "option1": "First",
    //         "price": "10.00",
    //         "sku": "123"
    //       },
    //       {
    //         "option1": "Second",
    //         "price": "20.00",
    //         "sku": "123"
    //       }
    //     ]
    //   }
    // }

    sbReq = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(jsonReq,sbReq);

    CkRestW_AddHeader(rest,L"Content-Type",L"application/json");

    sbJson = CkStringBuilderW_Create();
    success = CkRestW_FullRequestSb(rest,L"POST",L"/admin/products.json ",sbReq,sbJson);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkJsonObjectW_Dispose(jsonReq);
        CkStringBuilderW_Dispose(sbReq);
        CkStringBuilderW_Dispose(sbJson);
        return;
    }

    if (CkRestW_getResponseStatusCode(rest) != 201) {
        wprintf(L"Received error response code: %d\n",CkRestW_getResponseStatusCode(rest));
        wprintf(L"Response body:\n");
        wprintf(L"%s\n",CkStringBuilderW_getAsString(sbJson));
        CkRestW_Dispose(rest);
        CkJsonObjectW_Dispose(jsonReq);
        CkStringBuilderW_Dispose(sbReq);
        CkStringBuilderW_Dispose(sbJson);
        return;
    }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(json,sbJson);

    // The following code parses the JSON response.
    // A sample JSON response is shown below the sample code.

    productId = CkJsonObjectW_IntOf(json,L"product.id");
    productTitle = CkJsonObjectW_stringOf(json,L"product.title");
    productBody_html = CkJsonObjectW_stringOf(json,L"product.body_html");
    productVendor = CkJsonObjectW_stringOf(json,L"product.vendor");
    productProduct_type = CkJsonObjectW_stringOf(json,L"product.product_type");
    productCreated_at = CkJsonObjectW_stringOf(json,L"product.created_at");
    productHandle = CkJsonObjectW_stringOf(json,L"product.handle");
    productUpdated_at = CkJsonObjectW_stringOf(json,L"product.updated_at");
    productPublished_at = CkJsonObjectW_stringOf(json,L"product.published_at");
    productTemplate_suffix = CkJsonObjectW_IsNullOf(json,L"product.template_suffix");
    productPublished_scope = CkJsonObjectW_stringOf(json,L"product.published_scope");
    productTags = CkJsonObjectW_stringOf(json,L"product.tags");
    productImage = CkJsonObjectW_IsNullOf(json,L"product.image");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(json,L"product.variants");
    while (i < count_i) {
        CkJsonObjectW_putI(json,i);
        id = CkJsonObjectW_IntOf(json,L"product.variants[i].id");
        product_id = CkJsonObjectW_IntOf(json,L"product.variants[i].product_id");
        title = CkJsonObjectW_stringOf(json,L"product.variants[i].title");
        price = CkJsonObjectW_stringOf(json,L"product.variants[i].price");
        sku = CkJsonObjectW_stringOf(json,L"product.variants[i].sku");
        position = CkJsonObjectW_IntOf(json,L"product.variants[i].position");
        grams = CkJsonObjectW_IntOf(json,L"product.variants[i].grams");
        inventory_policy = CkJsonObjectW_stringOf(json,L"product.variants[i].inventory_policy");
        compare_at_price = CkJsonObjectW_IsNullOf(json,L"product.variants[i].compare_at_price");
        fulfillment_service = CkJsonObjectW_stringOf(json,L"product.variants[i].fulfillment_service");
        inventory_management = CkJsonObjectW_IsNullOf(json,L"product.variants[i].inventory_management");
        option1 = CkJsonObjectW_stringOf(json,L"product.variants[i].option1");
        option2 = CkJsonObjectW_IsNullOf(json,L"product.variants[i].option2");
        option3 = CkJsonObjectW_IsNullOf(json,L"product.variants[i].option3");
        created_at = CkJsonObjectW_stringOf(json,L"product.variants[i].created_at");
        updated_at = CkJsonObjectW_stringOf(json,L"product.variants[i].updated_at");
        taxable = CkJsonObjectW_BoolOf(json,L"product.variants[i].taxable");
        barcode = CkJsonObjectW_IsNullOf(json,L"product.variants[i].barcode");
        image_id = CkJsonObjectW_IsNullOf(json,L"product.variants[i].image_id");
        inventory_quantity = CkJsonObjectW_IntOf(json,L"product.variants[i].inventory_quantity");
        weight = CkJsonObjectW_IntOf(json,L"product.variants[i].weight");
        weight_unit = CkJsonObjectW_stringOf(json,L"product.variants[i].weight_unit");
        old_inventory_quantity = CkJsonObjectW_IntOf(json,L"product.variants[i].old_inventory_quantity");
        requires_shipping = CkJsonObjectW_BoolOf(json,L"product.variants[i].requires_shipping");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(json,L"product.options");
    while (i < count_i) {
        CkJsonObjectW_putI(json,i);
        id = CkJsonObjectW_IntOf(json,L"product.options[i].id");
        product_id = CkJsonObjectW_IntOf(json,L"product.options[i].product_id");
        name = CkJsonObjectW_stringOf(json,L"product.options[i].name");
        position = CkJsonObjectW_IntOf(json,L"product.options[i].position");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(json,L"product.options[i].values");
        while (j < count_j) {
            CkJsonObjectW_putJ(json,j);
            strVal = CkJsonObjectW_stringOf(json,L"product.options[i].values[j]");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(json,L"product.images");
    while (i < count_i) {
        CkJsonObjectW_putI(json,i);
        i = i + 1;
    }

    // A sample JSON response body that is parsed by the above code:

    // {
    //   "product": {
    //     "id": 1071559755,
    //     "title": "Burton Custom Freestyle 151",
    //     "body_html": "<strong>Good snowboard!<\/strong>",
    //     "vendor": "Burton",
    //     "product_type": "Snowboard",
    //     "created_at": "2017-09-22T14:48:54-04:00",
    //     "handle": "burton-custom-freestyle-151",
    //     "updated_at": "2017-09-22T14:48:55-04:00",
    //     "published_at": "2017-09-22T14:48:54-04:00",
    //     "template_suffix": null,
    //     "published_scope": "global",
    //     "tags": "",
    //     "variants": [
    //       {
    //         "id": 1070325225,
    //         "product_id": 1071559755,
    //         "title": "First",
    //         "price": "10.00",
    //         "sku": "123",
    //         "position": 1,
    //         "grams": 0,
    //         "inventory_policy": "deny",
    //         "compare_at_price": null,
    //         "fulfillment_service": "manual",
    //         "inventory_management": null,
    //         "option1": "First",
    //         "option2": null,
    //         "option3": null,
    //         "created_at": "2017-09-22T14:48:54-04:00",
    //         "updated_at": "2017-09-22T14:48:54-04:00",
    //         "taxable": true,
    //         "barcode": null,
    //         "image_id": null,
    //         "inventory_quantity": 1,
    //         "weight": 0.0,
    //         "weight_unit": "lb",
    //         "old_inventory_quantity": 1,
    //         "requires_shipping": true
    //       },
    //       {
    //         "id": 1070325226,
    //         "product_id": 1071559755,
    //         "title": "Second",
    //         "price": "20.00",
    //         "sku": "123",
    //         "position": 2,
    //         "grams": 0,
    //         "inventory_policy": "deny",
    //         "compare_at_price": null,
    //         "fulfillment_service": "manual",
    //         "inventory_management": null,
    //         "option1": "Second",
    //         "option2": null,
    //         "option3": null,
    //         "created_at": "2017-09-22T14:48:54-04:00",
    //         "updated_at": "2017-09-22T14:48:54-04:00",
    //         "taxable": true,
    //         "barcode": null,
    //         "image_id": null,
    //         "inventory_quantity": 1,
    //         "weight": 0.0,
    //         "weight_unit": "lb",
    //         "old_inventory_quantity": 1,
    //         "requires_shipping": true
    //       }
    //     ],
    //     "options": [
    //       {
    //         "id": 1022828915,
    //         "product_id": 1071559755,
    //         "name": "Title",
    //         "position": 1,
    //         "values": [
    //           "First",
    //           "Second"
    //         ]
    //       }
    //     ],
    //     "images": [
    //     ],
    //     "image": null
    //   }
    // }

    wprintf(L"Example Completed.\n");


    CkRestW_Dispose(rest);
    CkJsonObjectW_Dispose(jsonReq);
    CkStringBuilderW_Dispose(sbReq);
    CkStringBuilderW_Dispose(sbJson);
    CkJsonObjectW_Dispose(json);

    }

 

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