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

Classic ASP Example

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
set rest = Server.CreateObject("Chilkat_9_5_0.Rest")

'  URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/accounts
bTls = 1
port = 443
bAutoReconnect = 1
success = rest.Connect("my-dynamics-domain.api.crm.dynamics.com",port,bTls,bAutoReconnect)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( "ConnectFailReason: " & rest.ConnectFailReason) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"

End If

set json = Server.CreateObject("Chilkat_9_5_0.JsonObject")
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")

set sbRequestBody = Server.CreateObject("Chilkat_9_5_0.StringBuilder")
success = json.EmitSb(sbRequestBody)
set sbResponseBody = Server.CreateObject("Chilkat_9_5_0.StringBuilder")
success = rest.FullRequestSb("POST","/api/data/v9.0/accounts",sbRequestBody,sbResponseBody)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"

End If

respStatusCode = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Response Status Code = " & respStatusCode) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( "Response Header:") & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( rest.ResponseHeader) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( "Response Body:") & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( sbResponseBody.GetAsString()) & "</pre>"

End If


%>
</body>
</html>