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 <C_CkRestW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
HCkRestW rest;
BOOL success;
BOOL bTls;
int port;
BOOL bAutoReconnect;
HCkJsonObjectW json;
HCkStringBuilderW sbRequestBody;
HCkStringBuilderW sbResponseBody;
int respStatusCode;
rest = CkRestW_Create();
// URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/accounts
bTls = TRUE;
port = 443;
bAutoReconnect = TRUE;
success = CkRestW_Connect(rest,L"my-dynamics-domain.api.crm.dynamics.com",port,bTls,bAutoReconnect);
if (success != TRUE) {
wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
return;
}
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"name",L"Sample Account");
CkJsonObjectW_UpdateBool(json,L"creditonhold",FALSE);
CkJsonObjectW_UpdateNumber(json,L"address1_latitude",L"47.639583");
CkJsonObjectW_UpdateString(json,L"description",L"This is the description of the sample account");
CkJsonObjectW_UpdateNumber(json,L"revenue",L"5000000");
CkJsonObjectW_UpdateNumber(json,L"accountcategorycode",L"1");
CkRestW_AddHeader(rest,L"Content-Type",L"application/json; charset=utf-8");
CkRestW_AddHeader(rest,L"OData-Version",L"4.0");
CkRestW_AddHeader(rest,L"Accept",L"application/json");
CkRestW_AddHeader(rest,L"OData-MaxVersion",L"4.0");
CkRestW_AddHeader(rest,L"Authorization",L"Bearer DYNAMICS_CRM_ACCESS_TOKEN");
sbRequestBody = CkStringBuilderW_Create();
CkJsonObjectW_EmitSb(json,sbRequestBody);
sbResponseBody = CkStringBuilderW_Create();
success = CkRestW_FullRequestSb(rest,L"POST",L"/api/data/v9.0/accounts",sbRequestBody,sbResponseBody);
if (success != TRUE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
respStatusCode = CkRestW_getResponseStatusCode(rest);
if (respStatusCode >= 400) {
wprintf(L"Response Status Code = %d\n",respStatusCode);
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkRestW_responseHeader(rest));
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody));
CkRestW_Dispose(rest);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
CkRestW_Dispose(rest);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
}