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
Microsoft Calendar
PayPal
Peoplevox

QuickBooks
Shopify
Stripe
SugarCRM
Twitter
VoiceBase
Walmart
Xero
eBay
effectconnect

 

 

 

(C) SugarCRM Create a Record List

Create a record list in Sugar consisting of a set of ids.

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_CkRest.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    HCkJsonObject jsonReq;
    HCkStringBuilder sbReq;
    HCkStringBuilder sbJson;
    HCkJsonObject json;
    const char *id;
    const char *assigned_user_id;
    const char *module_name;
    const char *date_modified;
    int i;
    int count_i;
    const char *strVal;

    rest = CkRest_Create();

    success = CkRest_Connect(rest,"your.site.domain",443,TRUE,TRUE);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        return;
    }

    CkRest_AddHeader(rest,"Cache-Control","no-cache");
    CkRest_AddHeader(rest,"OAuth-Token","<access_token>");

    // The following code creates the JSON request body.
    // The JSON created by this code is shown below.
    jsonReq = CkJsonObject_Create();
    CkJsonObject_UpdateString(jsonReq,"records[0]","f16760a4-3a52-f77d-1522-5703ca28925f");
    CkJsonObject_UpdateString(jsonReq,"records[1]","ec409fbb-2b22-4f32-7fa1-5703caf78dc3");

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

    // {
    //   "records": [
    //     "f16760a4-3a52-f77d-1522-5703ca28925f",
    //     "ec409fbb-2b22-4f32-7fa1-5703caf78dc3"
    //   ]
    // }

    sbReq = CkStringBuilder_Create();
    CkJsonObject_EmitSb(jsonReq,sbReq);

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

    sbJson = CkStringBuilder_Create();
    success = CkRest_FullRequestSb(rest,"POST","/rest/v10/Accounts/record_list",sbReq,sbJson);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkJsonObject_Dispose(jsonReq);
        CkStringBuilder_Dispose(sbReq);
        CkStringBuilder_Dispose(sbJson);
        return;
    }

    if (CkRest_getResponseStatusCode(rest) != 200) {
        printf("Received error response code: %d\n",CkRest_getResponseStatusCode(rest));
        printf("Response body:\n");
        printf("%s\n",CkStringBuilder_getAsString(sbJson));
        CkRest_Dispose(rest);
        CkJsonObject_Dispose(jsonReq);
        CkStringBuilder_Dispose(sbReq);
        CkStringBuilder_Dispose(sbJson);
        return;
    }

    json = CkJsonObject_Create();
    CkJsonObject_LoadSb(json,sbJson);

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

    id = CkJsonObject_stringOf(json,"id");
    assigned_user_id = CkJsonObject_stringOf(json,"assigned_user_id");
    module_name = CkJsonObject_stringOf(json,"module_name");
    date_modified = CkJsonObject_stringOf(json,"date_modified");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(json,"records");
    while (i < count_i) {
        CkJsonObject_putI(json,i);
        strVal = CkJsonObject_stringOf(json,"records[i]");
        i = i + 1;
    }

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

    // {
    //   "id": "ef963176-4845-bc55-b03e-570430b4173c",
    //   "assigned_user_id": "1",
    //   "module_name": "Accounts",
    //   "records": [
    //     "f16760a4-3a52-f77d-1522-5703ca28925f",
    //     "ec409fbb-2b22-4f32-7fa1-5703caf78dc3"
    //   ],
    //   "date_modified": "2016-04-05 21:39:19"
    // }

    printf("Example Completed.\n");


    CkRest_Dispose(rest);
    CkJsonObject_Dispose(jsonReq);
    CkStringBuilder_Dispose(sbReq);
    CkStringBuilder_Dispose(sbJson);
    CkJsonObject_Dispose(json);

    }

 

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