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 an Order by purchaseOrderId

Gets the XML data for an order by purchaseOrderId.

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;

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

    // Demonstrates how to get the XML for a particular order by purchaseOrderId

    // Sends the following GET request:
    // GET https://marketplace.walmartapis.com/v3/orders/{purchaseOrderId}

    sbUrl = CkStringBuilder_Create();
    success = CkStringBuilder_Append(sbUrl,"https://marketplace.walmartapis.com/v3/orders/{purchaseOrderId}");
    numReplaced = CkStringBuilder_Replace(sbUrl,"{purchaseOrderId}","1111691995111");

    requestMethod = "GET";

    // First we need to generate a signature for the 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_SetRequestHeader(http,"WM_CONSUMER.CHANNEL.TYPE","WALMART_CHANNEL_TYPE");

    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;
    }

    // Show the XML response:
    printf("%s\n",CkXml_getXml(xml));
    printf("Success.\n");


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

    }

 

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