Visual Basic 6.0 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
}'

Visual Basic 6.0 Example

Dim rest As New ChilkatRest
Dim success As Long

'  URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/accounts
Dim bTls As Long
bTls = 1
Dim port As Long
port = 443
Dim bAutoReconnect As Long
bAutoReconnect = 1
success = rest.Connect("my-dynamics-domain.api.crm.dynamics.com",port,bTls,bAutoReconnect)
If (success <> 1) Then
    Debug.Print "ConnectFailReason: " & rest.ConnectFailReason
    Debug.Print rest.LastErrorText
    Exit Sub
End If

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

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

Dim sbRequestBody As New ChilkatStringBuilder
success = json.EmitSb(sbRequestBody)
Dim sbResponseBody As New ChilkatStringBuilder
success = rest.FullRequestSb("POST","/api/data/v9.0/accounts",sbRequestBody,sbResponseBody)
If (success <> 1) Then
    Debug.Print rest.LastErrorText
    Exit Sub
End If

Dim respStatusCode As Long
respStatusCode = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
    Debug.Print "Response Status Code = " & respStatusCode
    Debug.Print "Response Header:"
    Debug.Print rest.ResponseHeader
    Debug.Print "Response Body:"
    Debug.Print sbResponseBody.GetAsString()
    Exit Sub
End If