Sample code for 30+ languages & platforms
Unicode C++

SugarCRM Create a Record List

See more SugarCRM Examples

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

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkRestW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkRestW rest;

    success = rest.Connect(L"your.site.domain",443,true,true);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

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

    // The following code creates the JSON request body.
    // The JSON created by this code is shown below.
    CkJsonObjectW jsonReq;
    jsonReq.UpdateString(L"records[0]",L"f16760a4-3a52-f77d-1522-5703ca28925f");
    jsonReq.UpdateString(L"records[1]",L"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"
    //   ]
    // }

    CkStringBuilderW sbReq;
    jsonReq.EmitSb(sbReq);

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

    CkStringBuilderW sbJson;
    success = rest.FullRequestSb(L"POST",L"/rest/v10/Accounts/record_list",sbReq,sbJson);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    if (rest.get_ResponseStatusCode() != 200) {
        wprintf(L"Received error response code: %d\n",rest.get_ResponseStatusCode());
        wprintf(L"Response body:\n");
        wprintf(L"%s\n",sbJson.getAsString());
        return;
    }

    CkJsonObjectW json;
    json.LoadSb(sbJson);

    // The following code parses the JSON response.
    // A sample JSON response is shown below the sample code.
    const wchar_t *id = 0;
    const wchar_t *assigned_user_id = 0;
    const wchar_t *module_name = 0;
    const wchar_t *date_modified = 0;
    int i;
    int count_i;
    const wchar_t *strVal = 0;

    id = json.stringOf(L"id");
    assigned_user_id = json.stringOf(L"assigned_user_id");
    module_name = json.stringOf(L"module_name");
    date_modified = json.stringOf(L"date_modified");
    i = 0;
    count_i = json.SizeOfArray(L"records");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf(L"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"
    // }

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