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"?>
// <supplier-information>
// <supplier-id>:id</supplier-id>
// <status>approved</status>
// <name>SIM Company</name>
// <exported>true</exported>
// <supplier-information-addresses>
// <supplier-information-address>
// <kind>RTA</kind>
// <location-code>001</location-code>
// <street-address>59 Bank Avenue</street-address>
// <postal-code>15200</postal-code>
// <city>Pittsburgh</city>
// <state-region>PA</state-region>
// <bank-name>Bank Inc.</bank-name>
// <bank-account-number>9999325</bank-account-number>
// <currency>
// <code>USD</code>
// </currency>
// </supplier-information-address>
// <supplier-information-address>
// <kind>RTA</kind>
// <location-code>002</location-code>
// <street-address>71 Sample Street</street-address>
// <postal-code>19100</postal-code>
// <city>Philadelphia</city>
// <state-region>PA</state-region>
// <bank-name>Cash Co.</bank-name>
// <bank-account-number>8888325</bank-account-number>
// <currency>
// <code>USD</code>
// </currency>
// </supplier-information-address>
// </supplier-information-addresses>
// </supplier-information>
//
xml = CkXmlW_Create();
CkXmlW_putTag(xml,L"supplier-information");
CkXmlW_UpdateChildContent(xml,L"supplier-id",L":id");
CkXmlW_UpdateChildContent(xml,L"status",L"approved");
CkXmlW_UpdateChildContent(xml,L"name",L"SIM Company");
CkXmlW_UpdateChildContent(xml,L"exported",L"true");
CkXmlW_UpdateChildContent(xml,L"supplier-information-addresses|supplier-information-address|kind",L"RTA");
CkXmlW_UpdateChildContentInt(xml,L"supplier-information-addresses|supplier-information-address|location-code",001);
CkXmlW_UpdateChildContent(xml,L"supplier-information-addresses|supplier-information-address|street-address",L"59 Bank Avenue");
CkXmlW_UpdateChildContentInt(xml,L"supplier-information-addresses|supplier-information-address|postal-code",15200);
CkXmlW_UpdateChildContent(xml,L"supplier-information-addresses|supplier-information-address|city",L"Pittsburgh");
CkXmlW_UpdateChildContent(xml,L"supplier-information-addresses|supplier-information-address|state-region",L"PA");
CkXmlW_UpdateChildContent(xml,L"supplier-information-addresses|supplier-information-address|bank-name",L"Bank Inc.");
CkXmlW_UpdateChildContentInt(xml,L"supplier-information-addresses|supplier-information-address|bank-account-number",9999325);
CkXmlW_UpdateChildContent(xml,L"supplier-information-addresses|supplier-information-address|currency|code",L"USD");
CkXmlW_UpdateChildContent(xml,L"supplier-information-addresses|supplier-information-address[1]|kind",L"RTA");
CkXmlW_UpdateChildContentInt(xml,L"supplier-information-addresses|supplier-information-address[1]|location-code",002);
CkXmlW_UpdateChildContent(xml,L"supplier-information-addresses|supplier-information-address[1]|street-address",L"71 Sample Street");
CkXmlW_UpdateChildContentInt(xml,L"supplier-information-addresses|supplier-information-address[1]|postal-code",19100);
CkXmlW_UpdateChildContent(xml,L"supplier-information-addresses|supplier-information-address[1]|city",L"Philadelphia");
CkXmlW_UpdateChildContent(xml,L"supplier-information-addresses|supplier-information-address[1]|state-region",L"PA");
CkXmlW_UpdateChildContent(xml,L"supplier-information-addresses|supplier-information-address[1]|bank-name",L"Cash Co.");
CkXmlW_UpdateChildContentInt(xml,L"supplier-information-addresses|supplier-information-address[1]|bank-account-number",8888325);
CkXmlW_UpdateChildContent(xml,L"supplier-information-addresses|supplier-information-address[1]|currency|code",L"USD");
// 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/supplier_information/",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 '<supplier-information>
<supplier-id>:id</supplier-id>
<status>approved</status>
<name>SIM Company</name>
<exported>true</exported>
<supplier-information-addresses>
<supplier-information-address>
<kind>RTA</kind>
<location-code>001</location-code>
<street-address>59 Bank Avenue</street-address>
<postal-code>15200</postal-code>
<city>Pittsburgh</city>
<state-region>PA</state-region>
<bank-name>Bank Inc.</bank-name>
<bank-account-number>9999325</bank-account-number>
<currency>
<code>USD</code>
</currency>
</supplier-information-address>
<supplier-information-address>
<kind>RTA</kind>
<location-code>002</location-code>
<street-address>71 Sample Street</street-address>
<postal-code>19100</postal-code>
<city>Philadelphia</city>
<state-region>PA</state-region>
<bank-name>Cash Co.</bank-name>
<bank-account-number>8888325</bank-account-number>
<currency>
<code>USD</code>
</currency>
</supplier-information-address>
</supplier-information-addresses>
</supplier-information>'
https://domain.com/supplier_information/
Postman Collection Item JSON
{
"name": "Create SIM Record against existing Supplier",
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "<supplier-information>\n <supplier-id>:id</supplier-id>\n <status>approved</status>\n <name>SIM Company</name>\n <exported>true</exported>\n <supplier-information-addresses>\n <supplier-information-address>\n <kind>RTA</kind>\n <location-code>001</location-code>\n <street-address>59 Bank Avenue</street-address>\n <postal-code>15200</postal-code>\n <city>Pittsburgh</city>\n <state-region>PA</state-region>\n <bank-name>Bank Inc.</bank-name>\n <bank-account-number>9999325</bank-account-number>\n <currency>\n <code>USD</code>\n </currency>\n </supplier-information-address>\n <supplier-information-address>\n <kind>RTA</kind>\n <location-code>002</location-code>\n <street-address>71 Sample Street</street-address>\n <postal-code>19100</postal-code>\n <city>Philadelphia</city>\n <state-region>PA</state-region>\n <bank-name>Cash Co.</bank-name>\n <bank-account-number>8888325</bank-account-number>\n <currency>\n <code>USD</code>\n </currency>\n </supplier-information-address>\n </supplier-information-addresses>\n</supplier-information>",
"options": {
"raw": {
"language": "xml"
}
}
},
"url": {
"raw": "{{URL}}/supplier_information/",
"host": [
"{{URL}}"
],
"path": [
"supplier_information",
""
]
},
"description": "This API is used for creating shell SIM records before importing legacy Suppliers. Status of SIM will be \"approved\" and exported flag will be marked as true."
},
"response": [
]
}