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 Add a metafield to an existing product

Add a metafield to an existing product

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;
    int productImageId;
    int productImageProduct_id;
    int productImagePosition;
    const wchar_t *productImageCreated_at;
    const wchar_t *productImageUpdated_at;
    int productImageWidth;
    int productImageHeight;
    const wchar_t *productImageSrc;
    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;
    const wchar_t *inventory_management;
    const wchar_t *option1;
    BOOL option2;
    BOOL option3;
    const wchar_t *created_at;
    const wchar_t *updated_at;
    BOOL taxable;
    const wchar_t *barcode;
    int 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;
    int width;
    int height;
    const wchar_t *src;
    int intVal;

    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_UpdateNumber(jsonReq,L"product.id",L"632910392");
    CkJsonObjectW_UpdateString(jsonReq,L"product.metafields[0].key",L"new");
    CkJsonObjectW_UpdateString(jsonReq,L"product.metafields[0].value",L"newvalue");
    CkJsonObjectW_UpdateString(jsonReq,L"product.metafields[0].value_type",L"string");
    CkJsonObjectW_UpdateString(jsonReq,L"product.metafields[0].namespace",L"global");

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

    // {
    //   "product": {
    //     "id": 632910392,
    //     "metafields": [
    //       {
    //         "key": "new",
    //         "value": "newvalue",
    //         "value_type": "string",
    //         "namespace": "global"
    //       }
    //     ]
    //   }
    // }

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

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

    sbJson = CkStringBuilderW_Create();
    success = CkRestW_FullRequestSb(rest,L"PUT",L"/admin/products/#{id}.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) != 200) {
        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");
    productImageId = CkJsonObjectW_IntOf(json,L"product.image.id");
    productImageProduct_id = CkJsonObjectW_IntOf(json,L"product.image.product_id");
    productImagePosition = CkJsonObjectW_IntOf(json,L"product.image.position");
    productImageCreated_at = CkJsonObjectW_stringOf(json,L"product.image.created_at");
    productImageUpdated_at = CkJsonObjectW_stringOf(json,L"product.image.updated_at");
    productImageWidth = CkJsonObjectW_IntOf(json,L"product.image.width");
    productImageHeight = CkJsonObjectW_IntOf(json,L"product.image.height");
    productImageSrc = CkJsonObjectW_stringOf(json,L"product.image.src");
    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_stringOf(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_stringOf(json,L"product.variants[i].barcode");
        image_id = CkJsonObjectW_IntOf(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);
        id = CkJsonObjectW_IntOf(json,L"product.images[i].id");
        product_id = CkJsonObjectW_IntOf(json,L"product.images[i].product_id");
        position = CkJsonObjectW_IntOf(json,L"product.images[i].position");
        created_at = CkJsonObjectW_stringOf(json,L"product.images[i].created_at");
        updated_at = CkJsonObjectW_stringOf(json,L"product.images[i].updated_at");
        width = CkJsonObjectW_IntOf(json,L"product.images[i].width");
        height = CkJsonObjectW_IntOf(json,L"product.images[i].height");
        src = CkJsonObjectW_stringOf(json,L"product.images[i].src");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(json,L"product.images[i].variant_ids");
        while (j < count_j) {
            CkJsonObjectW_putJ(json,j);
            intVal = CkJsonObjectW_IntOf(json,L"product.images[i].variant_ids[j]");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(json,L"image.product.variant_ids");
    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": 632910392,
    //     "title": "IPod Nano - 8GB",
    //     "body_html": "<p>It's the small iPod with one very big idea: Video. Now the world's most popular music player, available in 4GB and 8GB models, lets you enjoy TV shows, movies, video podcasts, and more. The larger, brighter display means amazing picture quality. In six eye-catching colors, iPod nano is stunning all around. And with models starting at just $149, little speaks volumes.<\/p>",
    //     "vendor": "Apple",
    //     "product_type": "Cult Products",
    //     "created_at": "2017-09-22T14:08:02-04:00",
    //     "handle": "ipod-nano",
    //     "updated_at": "2017-09-22T14:48:57-04:00",
    //     "published_at": "2007-12-31T19:00:00-05:00",
    //     "template_suffix": null,
    //     "published_scope": "web",
    //     "tags": "Emotive, Flash Memory, MP3, Music",
    //     "variants": [
    //       {
    //         "id": 808950810,
    //         "product_id": 632910392,
    //         "title": "Pink",
    //         "price": "199.00",
    //         "sku": "IPOD2008PINK",
    //         "position": 1,
    //         "grams": 567,
    //         "inventory_policy": "continue",
    //         "compare_at_price": null,
    //         "fulfillment_service": "manual",
    //         "inventory_management": "shopify",
    //         "option1": "Pink",
    //         "option2": null,
    //         "option3": null,
    //         "created_at": "2017-09-22T14:08:02-04:00",
    //         "updated_at": "2017-09-22T14:48:57-04:00",
    //         "taxable": true,
    //         "barcode": "1234_pink",
    //         "image_id": 562641783,
    //         "inventory_quantity": 10,
    //         "weight": 1.25,
    //         "weight_unit": "lb",
    //         "old_inventory_quantity": 10,
    //         "requires_shipping": true
    //       },
    //       {
    //         "id": 49148385,
    //         "product_id": 632910392,
    //         "title": "Red",
    //         "price": "199.00",
    //         "sku": "IPOD2008RED",
    //         "position": 2,
    //         "grams": 567,
    //         "inventory_policy": "continue",
    //         "compare_at_price": null,
    //         "fulfillment_service": "manual",
    //         "inventory_management": "shopify",
    //         "option1": "Red",
    //         "option2": null,
    //         "option3": null,
    //         "created_at": "2017-09-22T14:08:02-04:00",
    //         "updated_at": "2017-09-22T14:08:02-04:00",
    //         "taxable": true,
    //         "barcode": "1234_red",
    //         "image_id": null,
    //         "inventory_quantity": 20,
    //         "weight": 1.25,
    //         "weight_unit": "lb",
    //         "old_inventory_quantity": 20,
    //         "requires_shipping": true
    //       },
    //       {
    //         "id": 39072856,
    //         "product_id": 632910392,
    //         "title": "Green",
    //         "price": "199.00",
    //         "sku": "IPOD2008GREEN",
    //         "position": 3,
    //         "grams": 567,
    //         "inventory_policy": "continue",
    //         "compare_at_price": null,
    //         "fulfillment_service": "manual",
    //         "inventory_management": "shopify",
    //         "option1": "Green",
    //         "option2": null,
    //         "option3": null,
    //         "created_at": "2017-09-22T14:08:02-04:00",
    //         "updated_at": "2017-09-22T14:08:02-04:00",
    //         "taxable": true,
    //         "barcode": "1234_green",
    //         "image_id": null,
    //         "inventory_quantity": 30,
    //         "weight": 1.25,
    //         "weight_unit": "lb",
    //         "old_inventory_quantity": 30,
    //         "requires_shipping": true
    //       },
    //       {
    //         "id": 457924702,
    //         "product_id": 632910392,
    //         "title": "Black",
    //         "price": "199.00",
    //         "sku": "IPOD2008BLACK",
    //         "position": 4,
    //         "grams": 567,
    //         "inventory_policy": "continue",
    //         "compare_at_price": null,
    //         "fulfillment_service": "manual",
    //         "inventory_management": "shopify",
    //         "option1": "Black",
    //         "option2": null,
    //         "option3": null,
    //         "created_at": "2017-09-22T14:08:02-04:00",
    //         "updated_at": "2017-09-22T14:08:02-04:00",
    //         "taxable": true,
    //         "barcode": "1234_black",
    //         "image_id": null,
    //         "inventory_quantity": 40,
    //         "weight": 1.25,
    //         "weight_unit": "lb",
    //         "old_inventory_quantity": 40,
    //         "requires_shipping": true
    //       }
    //     ],
    //     "options": [
    //       {
    //         "id": 594680422,
    //         "product_id": 632910392,
    //         "name": "Color",
    //         "position": 1,
    //         "values": [
    //           "Pink",
    //           "Red",
    //           "Green",
    //           "Black"
    //         ]
    //       }
    //     ],
    //     "images": [
    //       {
    //         "id": 850703190,
    //         "product_id": 632910392,
    //         "position": 1,
    //         "created_at": "2017-09-22T14:08:02-04:00",
    //         "updated_at": "2017-09-22T14:08:02-04:00",
    //         "width": 123,
    //         "height": 456,
    //         "src": "https:\/\/cdn.shopify.com\/s\/files\/1\/0006\/9093\/3842\/products\/ipod-nano.png?v=1506103682",
    //         "variant_ids": [
    //         ]
    //       },
    //       {
    //         "id": 562641783,
    //         "product_id": 632910392,
    //         "position": 2,
    //         "created_at": "2017-09-22T14:08:02-04:00",
    //         "updated_at": "2017-09-22T14:08:02-04:00",
    //         "width": 123,
    //         "height": 456,
    //         "src": "https:\/\/cdn.shopify.com\/s\/files\/1\/0006\/9093\/3842\/products\/ipod-nano-2.png?v=1506103682",
    //         "variant_ids": [
    //           808950810
    //         ]
    //       }
    //     ],
    //     "image": {
    //       "id": 850703190,
    //       "product_id": 632910392,
    //       "position": 1,
    //       "created_at": "2017-09-22T14:08:02-04:00",
    //       "updated_at": "2017-09-22T14:08:02-04:00",
    //       "width": 123,
    //       "height": 456,
    //       "src": "https:\/\/cdn.shopify.com\/s\/files\/1\/0006\/9093\/3842\/products\/ipod-nano.png?v=1506103682",
    //       "variant_ids": [
    //       ]
    //     }
    //   }
    // }

    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.