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
}'
integer li_rc
oleobject loo_Rest
integer li_Success
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_Json
oleobject loo_SbRequestBody
oleobject loo_SbResponseBody
integer li_RespStatusCode
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
destroy loo_Rest
MessageBox("Error","Connecting to COM object failed")
return
end if
// URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/accounts
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("my-dynamics-domain.api.crm.dynamics.com",li_Port,li_BTls,li_BAutoReconnect)
if li_Success <> 1 then
Write-Debug "ConnectFailReason: " + string(loo_Rest.ConnectFailReason)
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
return
end if
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")
loo_Json.UpdateString("name","Sample Account")
loo_Json.UpdateBool("creditonhold",0)
loo_Json.UpdateNumber("address1_latitude","47.639583")
loo_Json.UpdateString("description","This is the description of the sample account")
loo_Json.UpdateNumber("revenue","5000000")
loo_Json.UpdateNumber("accountcategorycode","1")
loo_Rest.AddHeader("Content-Type","application/json; charset=utf-8")
loo_Rest.AddHeader("OData-Version","4.0")
loo_Rest.AddHeader("Accept","application/json")
loo_Rest.AddHeader("OData-MaxVersion","4.0")
loo_Rest.AddHeader("Authorization","Bearer DYNAMICS_CRM_ACCESS_TOKEN")
loo_SbRequestBody = create oleobject
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")
loo_Json.EmitSb(loo_SbRequestBody)
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")
li_Success = loo_Rest.FullRequestSb("POST","/api/data/v9.0/accounts",loo_SbRequestBody,loo_SbResponseBody)
if li_Success <> 1 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_SbResponseBody
return
end if
li_RespStatusCode = loo_Rest.ResponseStatusCode
if li_RespStatusCode >= 400 then
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
Write-Debug "Response Header:"
Write-Debug loo_Rest.ResponseHeader
Write-Debug "Response Body:"
Write-Debug loo_SbResponseBody.GetAsString()
destroy loo_Rest
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_SbResponseBody
return
end if
destroy loo_Rest
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_SbResponseBody