Xojo Plugin Dynamics CRM: Create an Account

Back to Index

Creates a new account.

Documentation: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/create-entity-web-api

CURL Command

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
}'

Xojo Plugin Example

Dim rest As New Chilkat.Rest
Dim success As Boolean

//  URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/accounts
Dim bTls As Boolean
bTls = True
Dim port As Int32
port = 443
Dim bAutoReconnect As Boolean
bAutoReconnect = True
success = rest.Connect("my-dynamics-domain.api.crm.dynamics.com",port,bTls,bAutoReconnect)
If (success <> True) Then
    System.DebugLog("ConnectFailReason: " + Str(rest.ConnectFailReason))
    System.DebugLog(rest.LastErrorText)
    Return
End If

Dim json As New Chilkat.JsonObject
json.UpdateString("name","Sample Account")
json.UpdateBool("creditonhold",False)
json.UpdateNumber("address1_latitude","47.639583")
json.UpdateString("description","This is the description of the sample account")
json.UpdateNumber("revenue","5000000")
json.UpdateNumber("accountcategorycode","1")

rest.AddHeader("Content-Type","application/json; charset=utf-8")
rest.AddHeader("OData-Version","4.0")
rest.AddHeader("Accept","application/json")
rest.AddHeader("OData-MaxVersion","4.0")
rest.AddHeader("Authorization","Bearer DYNAMICS_CRM_ACCESS_TOKEN")

Dim sbRequestBody As New Chilkat.StringBuilder
json.EmitSb(sbRequestBody)
Dim sbResponseBody As New Chilkat.StringBuilder
success = rest.FullRequestSb("POST","/api/data/v9.0/accounts",sbRequestBody,sbResponseBody)
If (success <> True) Then
    System.DebugLog(rest.LastErrorText)
    Return
End If

Dim respStatusCode As Int32
respStatusCode = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
    System.DebugLog("Response Status Code = " + Str(respStatusCode))
    System.DebugLog("Response Header:")
    System.DebugLog(rest.ResponseHeader)
    System.DebugLog("Response Body:")
    System.DebugLog(sbResponseBody.GetAsString())
    Return
End If