Creates a new account.
curl -X POST https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/accounts \
-H "Accept: application/json" \
-H "Content-Type: application/json; charset=utf-8" \
-H "OData-MaxVersion: 4.0" \
-H "OData-Version: 4.0" \
-H "Authorization: Bearer DYNAMICS_CRM_ACCESS_TOKEN" \
-d '{
"name": "Sample Account",
"creditonhold": false,
"address1_latitude": 47.639583,
"description": "This is the description of the sample account",
"revenue": 5000000,
"accountcategorycode": 1
}'
#include <CkRestW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
CkRestW rest;
bool success;
// URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/accounts
bool bTls = true;
int port = 443;
bool bAutoReconnect = true;
success = rest.Connect(L"my-dynamics-domain.api.crm.dynamics.com",port,bTls,bAutoReconnect);
if (success != true) {
wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
wprintf(L"%s\n",rest.lastErrorText());
return;
}
CkJsonObjectW json;
json.UpdateString(L"name",L"Sample Account");
json.UpdateBool(L"creditonhold",false);
json.UpdateNumber(L"address1_latitude",L"47.639583");
json.UpdateString(L"description",L"This is the description of the sample account");
json.UpdateNumber(L"revenue",L"5000000");
json.UpdateNumber(L"accountcategorycode",L"1");
rest.AddHeader(L"Content-Type",L"application/json; charset=utf-8");
rest.AddHeader(L"OData-Version",L"4.0");
rest.AddHeader(L"Accept",L"application/json");
rest.AddHeader(L"OData-MaxVersion",L"4.0");
rest.AddHeader(L"Authorization",L"Bearer DYNAMICS_CRM_ACCESS_TOKEN");
CkStringBuilderW sbRequestBody;
json.EmitSb(sbRequestBody);
CkStringBuilderW sbResponseBody;
success = rest.FullRequestSb(L"POST",L"/api/data/v9.0/accounts",sbRequestBody,sbResponseBody);
if (success != true) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
int respStatusCode = rest.get_ResponseStatusCode();
if (respStatusCode >= 400) {
wprintf(L"Response Status Code = %d\n",respStatusCode);
wprintf(L"Response Header:\n");
wprintf(L"%s\n",rest.responseHeader());
wprintf(L"Response Body:\n");
wprintf(L"%s\n",sbResponseBody.getAsString());
return;
}
}