Chilkat Examples

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

C Web API Examples

Primary Categories

CardConnect
Facebook
GeoOp
Jira
PayPal
Peoplevox
QuickBooks

Shopify
Stripe
SugarCRM
Twitter
VoiceBase
Walmart
Xero
eBay
effectconnect

 

 

 

(C) Walmart - Get a FeedItem's Status

Demonstrates how to get a Walmart feedItem's status.

Note: This example requires Chilkat v9.5.0.67 or greater.

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_CkStringBuilder.h>
#include <C_CkAuthUtil.h>
#include <C_CkJsonObject.h>
#include <C_CkHttp.h>
#include <C_CkXml.h>

void ChilkatSample(void)
    {
    HCkStringBuilder sbUrl;
    BOOL success;
    int numReplaced;
    const char *requestMethod;
    HCkAuthUtil authUtil;
    const char *wmConsumerId;
    const char *wmPrivateKey;
    const char *jsonStr;
    HCkJsonObject json;
    HCkHttp http;
    const char *xmlStr;
    HCkXml xml;
    int numIngestionStatuses;
    int i;

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

    // Sends the following GET request:
    // GET https://marketplace.walmartapis.com/v2/feeds/feeditems/{feedId}?includeDetails={includeDetails}&limit={limit}

    sbUrl = CkStringBuilder_Create();
    success = CkStringBuilder_Append(sbUrl,"https://marketplace.walmartapis.com/v2/feeds/feeditems/{feedId}?includeDetails={includeDetails}&limit={limit}");
    numReplaced = CkStringBuilder_Replace(sbUrl,"{feedId}","AAAA7F0345E9403C91223F7139FFC341@AQsBAQA");
    numReplaced = CkStringBuilder_Replace(sbUrl,"{includeDetails}","true");
    numReplaced = CkStringBuilder_ReplaceI(sbUrl,"{limit}",3);

    requestMethod = "GET";

    // First we need to generate a signature for our request.
    // The signature needs to be re-generated for each new Walmart HTTP request.
    authUtil = CkAuthUtil_Create();

    wmConsumerId = "WALMART_CONSUMER_ID";
    wmPrivateKey = "WALMART_PRIVATE_KEY";
    jsonStr = CkAuthUtil_walmartSignature(authUtil,CkStringBuilder_getAsString(sbUrl),wmConsumerId,wmPrivateKey,requestMethod);
    if (CkAuthUtil_getLastMethodSuccess(authUtil) != TRUE) {
        printf("%s\n",CkAuthUtil_lastErrorText(authUtil));
        CkStringBuilder_Dispose(sbUrl);
        CkAuthUtil_Dispose(authUtil);
        return;
    }

    // The JSON returned by WalmartSignature contains the values to be used in the following
    // header fields: WM_SEC.AUTH_SIGNATURE, WM_SEC.TIMESTAMP, and WM_QOS.CORRELATION_ID
    json = CkJsonObject_Create();
    CkJsonObject_Load(json,jsonStr);

    http = CkHttp_Create();
    CkHttp_SetRequestHeader(http,"WM_SVC.NAME","Walmart Marketplace");
    CkHttp_SetRequestHeader(http,"WM_QOS.CORRELATION_ID",CkJsonObject_stringOf(json,"correlation_id"));
    CkHttp_SetRequestHeader(http,"WM_SEC.TIMESTAMP",CkJsonObject_stringOf(json,"timestamp"));
    CkHttp_SetRequestHeader(http,"WM_SEC.AUTH_SIGNATURE",CkJsonObject_stringOf(json,"signature"));
    CkHttp_SetRequestHeader(http,"WM_CONSUMER.ID",wmConsumerId);
    CkHttp_putAccept(http,"application/xml");

    // Note: Do not explicitly set the "Host" header.  Chilkat will set it automatically.

    xmlStr = CkHttp_quickGetStr(http,CkStringBuilder_getAsString(sbUrl));
    if (CkHttp_getLastMethodSuccess(http) != TRUE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkStringBuilder_Dispose(sbUrl);
        CkAuthUtil_Dispose(authUtil);
        CkJsonObject_Dispose(json);
        CkHttp_Dispose(http);
        return;
    }

    xml = CkXml_Create();
    CkXml_LoadXml(xml,xmlStr);

    // A successful response should have a 200 response status
    if (CkHttp_getLastStatus(http) != 200) {
        printf("%s\n",CkXml_getXml(xml));
        printf("Response Status Code: %d\n",CkHttp_getLastStatus(http));
        printf("Failed.\n");
        CkStringBuilder_Dispose(sbUrl);
        CkAuthUtil_Dispose(authUtil);
        CkJsonObject_Dispose(json);
        CkHttp_Dispose(http);
        CkXml_Dispose(xml);
        return;
    }

    // A sample XML response is shown below..
    printf("%s\n",CkXml_getXml(xml));
    printf("--\n");

    // To iterate over the ingestion statuses:
    numIngestionStatuses = CkXml_NumChildrenAt(xml,"ns2:elements|ns2:itemDetails");
    i = 0;
    while (i < numIngestionStatuses) {
        CkXml_putI(xml,i);

        printf("sku: %s\n",CkXml_getChildContent(xml,"ns2:elements|ns2:itemDetails|ns2:itemIngestionStatus[i]|ns2:sku"));
        printf("status: %s\n",CkXml_getChildContent(xml,"ns2:elements|ns2:itemDetails|ns2:itemIngestionStatus[i]|ns2:ingestionStatus"));
        printf("--\n");

        i = i + 1;
    }

    printf("Success.\n");

    // ---------------------------------------
    // Sample XML response
    // ---------------------------------------

    // <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    // <ns2:ItemStatusDetail xmlns:ns2="http://walmart.com/">
    //     <ns2:meta>
    //         <ns2:feedId>AAAAF0345E9403C91223F7139FFC341@AQsBAQA</ns2:feedId>
    //         <ns2:feedStatus>PROCESSED</ns2:feedStatus>
    //         <ns2:ingestionErrors />
    //         <ns2:itemsReceived>130088</ns2:itemsReceived>
    //         <ns2:itemsSucceeded>113154</ns2:itemsSucceeded>
    //         <ns2:itemsFailed>16934</ns2:itemsFailed>
    //         <ns2:itemsProcessing>0</ns2:itemsProcessing>
    //         <ns2:limit>3</ns2:limit>
    //         <ns2:totalCount>3</ns2:totalCount>
    //         <ns2:nextCursor>includeDetails=true&amp;limit=3&amp;skuOffset=ENC%28%2F8D%2FyDen1ByXGA7EsWkArA%3D%3D%29</ns2:nextCursor>
    //     </ns2:meta>
    //     <ns2:elements>
    //         <ns2:itemDetails>
    //             <ns2:itemIngestionStatus>
    //                 <ns2:martId>0</ns2:martId>
    //                 <ns2:sku>0000~0~00141</ns2:sku>
    //                 <ns2:index>0</ns2:index>
    //                 <ns2:ingestionStatus>DATA_ERROR</ns2:ingestionStatus>
    //                 <ns2:ingestionErrors>
    //                     <ns2:ingestionError>
    //                         <ns2:type>DATA_ERROR</ns2:type>
    //                         <ns2:code>PIVI_021</ns2:code>
    //                         <ns2:description>No item found with the given SKU.</ns2:description>
    //                     </ns2:ingestionError>
    //                 </ns2:ingestionErrors>
    //             </ns2:itemIngestionStatus>
    //             <ns2:itemIngestionStatus>
    //                 <ns2:martId>0</ns2:martId>
    //                 <ns2:sku>0000~0~03472</ns2:sku>
    //                 <ns2:index>1</ns2:index>
    //                 <ns2:ingestionStatus>SUCCESS</ns2:ingestionStatus>
    //                 <ns2:ingestionErrors />
    //             </ns2:itemIngestionStatus>
    //             <ns2:itemIngestionStatus>
    //                 <ns2:martId>0</ns2:martId>
    //                 <ns2:sku>0000~0~08540</ns2:sku>
    //                 <ns2:index>2</ns2:index>
    //                 <ns2:ingestionStatus>SUCCESS</ns2:ingestionStatus>
    //                 <ns2:ingestionErrors />
    //             </ns2:itemIngestionStatus>
    //         </ns2:itemDetails>
    //     </ns2:elements>
    // </ns2:ItemStatusDetail>


    CkStringBuilder_Dispose(sbUrl);
    CkAuthUtil_Dispose(authUtil);
    CkJsonObject_Dispose(json);
    CkHttp_Dispose(http);
    CkXml_Dispose(xml);

    }

 

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