Creates a new contact for a specific account. In this example, the account is Fourth Coffee, where the accountid = b6a19cdd-88df-e311-b8e5-6c3be5a8b200. Success is indicated by a 204 response status code with an empty response body.
curl -X POST https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/contacts \
-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 '{
"fullname": "Gabby Cannata",
"firstname": "Gabby",
"lastname": "Cannata",
"emailaddress1": "gabby@fourthcoffee.com",
"address1_line1": "Carrera 1c No 10-01",
"address1_city": "Bogota",
"address1_country": "Colombia",
"telephone1": "408-233-1939",
"jobtitle": "Purchasing Assistant",
"parentcustomerid_account@odata.bind": "/accounts(b6a19cdd-88df-e311-b8e5-6c3be5a8b200)"
}'
<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/contacts
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("fullname","Gabby Cannata")
success = json.UpdateString("firstname","Gabby")
success = json.UpdateString("lastname","Cannata")
success = json.UpdateString("emailaddress1","gabby@fourthcoffee.com")
success = json.UpdateString("address1_line1","Carrera 1c No 10-01")
success = json.UpdateString("address1_city","Bogota")
success = json.UpdateString("address1_country","Colombia")
success = json.UpdateString("telephone1","408-233-1939")
success = json.UpdateString("jobtitle","Purchasing Assistant")
success = json.UpdateString("""parentcustomerid_account@odata.bind""","/accounts(b6a19cdd-88df-e311-b8e5-6c3be5a8b200)")
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/contacts",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>