Chilkat Online Tools

unicodeCpp / Zoho CRM REST APIs / Products

Back to Collection Items

#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
#include <CkHttpResponseW.h>

void ChilkatSample(void)
    {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttpW http;
    bool success;

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "data": [
    //     {
    //       "Owner": {
    //         "id": "{{user-id}}"
    //       },
    //       "Handler": {
    //         "id": "{{user-id}}"
    //       },
    //       "Vendor_Name": {
    //         "id": "{{vendor-id}}"
    //       },
    //       "Product_Category": "Software",
    //       "Qty_in_Demand": 1237.89,
    //       "Description": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.",
    //       "Commission_Rate": 1237.67,
    //       "Product_Name": "Product_Name",
    //       "Quantity_In_Stock": 12792,
    //       "Sales_Start_Date": "2018-01-25",
    //       "Tax": [
    //         "Sales Tax"
    //       ],
    //       "Support_Start_Date": "2018-01-25",
    //       "Product_Active": true,
    //       "Usage_Unit": "Caton",
    //       "Product_Code": "Product_Code",
    //       "Qty_Ordered": 1237.89,
    //       "Manufacturer": "LexPon Inc.",
    //       "Qty_in_Stock": 1237.89,
    //       "Support_Expiry_Date": "2018-01-25",
    //       "Sales_End_Date": "2018-01-25",
    //       "Unit_Price": 1237.67,
    //       "Taxable": true,
    //       "Reorder_Level": 1237.89
    //     }
    //   ]
    // }

    CkJsonObjectW json;
    json.UpdateString(L"data[0].Owner.id",L"{{user-id}}");
    json.UpdateString(L"data[0].Handler.id",L"{{user-id}}");
    json.UpdateString(L"data[0].Vendor_Name.id",L"{{vendor-id}}");
    json.UpdateString(L"data[0].Product_Category",L"Software");
    json.UpdateNumber(L"data[0].Qty_in_Demand",L"1237.89");
    json.UpdateString(L"data[0].Description",L"Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.");
    json.UpdateNumber(L"data[0].Commission_Rate",L"1237.67");
    json.UpdateString(L"data[0].Product_Name",L"Product_Name");
    json.UpdateInt(L"data[0].Quantity_In_Stock",12792);
    json.UpdateString(L"data[0].Sales_Start_Date",L"2018-01-25");
    json.UpdateString(L"data[0].Tax[0]",L"Sales Tax");
    json.UpdateString(L"data[0].Support_Start_Date",L"2018-01-25");
    json.UpdateBool(L"data[0].Product_Active",true);
    json.UpdateString(L"data[0].Usage_Unit",L"Caton");
    json.UpdateString(L"data[0].Product_Code",L"Product_Code");
    json.UpdateNumber(L"data[0].Qty_Ordered",L"1237.89");
    json.UpdateString(L"data[0].Manufacturer",L"LexPon Inc.");
    json.UpdateNumber(L"data[0].Qty_in_Stock",L"1237.89");
    json.UpdateString(L"data[0].Support_Expiry_Date",L"2018-01-25");
    json.UpdateString(L"data[0].Sales_End_Date",L"2018-01-25");
    json.UpdateNumber(L"data[0].Unit_Price",L"1237.67");
    json.UpdateBool(L"data[0].Taxable",true);
    json.UpdateNumber(L"data[0].Reorder_Level",L"1237.89");

    http.SetRequestHeader(L"Authorization",L"{{authorization-token}}");
    http.SetRequestHeader(L"Content-Type",L"application/json");

    CkStringBuilderW sbRequestBody;
    json.EmitSb(sbRequestBody);

    CkHttpResponseW *resp = http.PTextSb(L"PUT",L"https://domain.com/crm/v2.1/Products/{{record-id}}",sbRequestBody,L"utf-8",L"application/json",false,false);
    if (http.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    wprintf(L"%d\n",resp->get_StatusCode());
    wprintf(L"%s\n",resp->bodyStr());
    delete resp;
    }

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "Authorization: {{authorization-token}}"
	-H "Content-Type: application/json"
	-d '{
  "data": [
    {
      "Owner": {
        "id": "{{user-id}}"
      },
      "Handler": {
        "id": "{{user-id}}"
      },
      "Vendor_Name": {
        "id": "{{vendor-id}}"
      },
      "Product_Category": "Software",
      "Qty_in_Demand": 1237.89,
      "Description": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.",
      "Commission_Rate": 1237.67,
      "Product_Name": "Product_Name",
      "Quantity_In_Stock": 12792,
      "Sales_Start_Date": "2018-01-25",
      "Tax": [
        "Sales Tax"
      ],
      "Support_Start_Date": "2018-01-25",
      "Product_Active": true,
      "Usage_Unit": "Caton",
      "Product_Code": "Product_Code",
      "Qty_Ordered": 1237.89,
      "Manufacturer": "LexPon Inc.",
      "Qty_in_Stock": 1237.89,
      "Support_Expiry_Date": "2018-01-25",
      "Sales_End_Date": "2018-01-25",
      "Unit_Price": 1237.67,
      "Taxable": true,
      "Reorder_Level": 1237.89
    }
  ]
}'
https://domain.com/crm/v2.1/Products/{{record-id}}

Postman Collection Item JSON

{
  "name": "Products",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Authorization",
        "value": "{{authorization-token}}"
      },
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"data\": [\n    {\n      \"Owner\": {\n        \"id\": \"{{user-id}}\"\n      },\n      \"Handler\": {\n        \"id\": \"{{user-id}}\"\n      },\n      \"Vendor_Name\": {\n        \"id\": \"{{vendor-id}}\"\n      },\n      \"Product_Category\": \"Software\",\n      \"Qty_in_Demand\": 1237.89,\n      \"Description\": \"Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.\",\n      \"Commission_Rate\": 1237.67,\n      \"Product_Name\": \"Product_Name\",\n      \"Quantity_In_Stock\": 12792,\n      \"Sales_Start_Date\": \"2018-01-25\",\n      \"Tax\": [\n        \"Sales Tax\"\n      ],\n      \"Support_Start_Date\": \"2018-01-25\",\n      \"Product_Active\": true,\n      \"Usage_Unit\": \"Caton\",\n      \"Product_Code\": \"Product_Code\",\n      \"Qty_Ordered\": 1237.89,\n      \"Manufacturer\": \"LexPon Inc.\",\n      \"Qty_in_Stock\": 1237.89,\n      \"Support_Expiry_Date\": \"2018-01-25\",\n      \"Sales_End_Date\": \"2018-01-25\",\n      \"Unit_Price\": 1237.67,\n      \"Taxable\": true,\n      \"Reorder_Level\": 1237.89\n    }\n  ]\n}"
    },
    "url": {
      "raw": "{{api-domain}}/crm/v2.1/Products/{{record-id}}",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "v2.1",
        "Products",
        "{{record-id}}"
      ]
    },
    "description": "To update existing entities in the module."
  },
  "response": [
  ]
}