Chilkat Online Tools

unicodeC / Coupa Postman Collection - OAuth - Master / Create Address

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkXmlW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkXmlW xml;
    HCkStringBuilderW sbRequestBody;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

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

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

    // <?xml version="1.0" encoding="utf-8"?>
    // <address>
    //     <name>address with cf</name>
    //     <location-code>CODETEST1</location-code>
    //     <street1>line address1</street1>
    //     <street2>line address2</street2>
    //     <city>Reno</city>
    //     <state>NV</state>
    //     <postal-code>08550-3423</postal-code>
    //     <active>true</active>
    //     <country>
    //         <code>US</code>
    //     </country>
    //     <custom-fields>
    //         <date type="dateTime">2021-11-07</date>
    //     </custom-fields>
    // </address>
    // 

    xml = CkXmlW_Create();
    CkXmlW_putTag(xml,L"address");
    CkXmlW_UpdateChildContent(xml,L"name",L"address with cf");
    CkXmlW_UpdateChildContent(xml,L"location-code",L"CODETEST1");
    CkXmlW_UpdateChildContent(xml,L"street1",L"line address1");
    CkXmlW_UpdateChildContent(xml,L"street2",L"line address2");
    CkXmlW_UpdateChildContent(xml,L"city",L"Reno");
    CkXmlW_UpdateChildContent(xml,L"state",L"NV");
    CkXmlW_UpdateChildContent(xml,L"postal-code",L"08550-3423");
    CkXmlW_UpdateChildContent(xml,L"active",L"true");
    CkXmlW_UpdateChildContent(xml,L"country|code",L"US");
    CkXmlW_UpdateAttrAt(xml,L"custom-fields|date",TRUE,L"type",L"dateTime");
    CkXmlW_UpdateChildContent(xml,L"custom-fields|date",L"2021-11-07");

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");

    sbRequestBody = CkStringBuilderW_Create();
    CkXmlW_GetXmlSb(xml,sbRequestBody);

    resp = CkHttpW_PTextSb(http,L"POST",L"https://domain.com/addresses?fields=[\"id\",\"name\",\"active\",\"street1\",\"street2\",\"city\",\"state\",\"postal_code\",\"location_code\",{\"country\":{}},{\"tax_registrations\":{}},{\"custom_fields\":{}}]",sbRequestBody,L"utf-8",L"application/xml",FALSE,FALSE);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkXmlW_Dispose(xml);
        CkStringBuilderW_Dispose(sbRequestBody);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkXmlW_Dispose(xml);
    CkStringBuilderW_Dispose(sbRequestBody);

    }

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '<address>
    <name>address with cf</name>
    <location-code>CODETEST1</location-code>
    <street1>line address1</street1>
    <street2>line address2</street2>
    <city>Reno</city>
    <state>NV</state>
    <postal-code>08550-3423</postal-code>
    <active>true</active>
    <country>
        <code>US</code>
    </country>
    <custom-fields>
        <date type="dateTime">2021-11-07</date>
    </custom-fields>
</address>'
https://domain.com/addresses?fields=["id","name","active","street1","street2","city","state","postal_code","location_code",{"country":{}},{"tax_registrations":{}},{"custom_fields":{}}]

Postman Collection Item JSON

{
  "name": "Create Address",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "<address>\n    <name>address with cf</name>\n    <location-code>CODETEST1</location-code>\n    <street1>line address1</street1>\n    <street2>line address2</street2>\n    <city>Reno</city>\n    <state>NV</state>\n    <postal-code>08550-3423</postal-code>\n    <active>true</active>\n    <country>\n        <code>US</code>\n    </country>\n    <custom-fields>\n        <date type=\"dateTime\">2021-11-07</date>\n    </custom-fields>\n</address>",
      "options": {
        "raw": {
          "language": "xml"
        }
      }
    },
    "url": {
      "raw": "{{URL}}/addresses?fields=[\"id\",\"name\",\"active\",\"street1\",\"street2\",\"city\",\"state\",\"postal_code\",\"location_code\",{\"country\":{}},{\"tax_registrations\":{}},{\"custom_fields\":{}}]",
      "host": [
        "{{URL}}"
      ],
      "path": [
        "addresses"
      ],
      "query": [
        {
          "key": "fields",
          "value": "[\"id\",\"name\",\"active\",\"street1\",\"street2\",\"city\",\"state\",\"postal_code\",\"location_code\",{\"country\":{}},{\"tax_registrations\":{}},{\"custom_fields\":{}}]"
        }
      ]
    }
  },
  "response": [
  ]
}