Hi,
If you are using JavaScript, you can use something similar to the following code:
function createContact()
{
var serverURL = Xrm.Page.context.getClientUrl();
var contact = {};
contact["firstname"] = "John";
contact["lastname"] = "Smith";
contact["emailaddress1"] = "john.smith@contoso.com";
var req = new XMLHttpRequest();
req.open("POST", crmServerUrl + "/api/data/v8.0/contacts", true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null;
if (this.status == 204) {
var contactUrl = this.getResponseHeader("OData-EntityId");
} else {
var error = JSON.parse(this.response).error;
alert(error.message);
}
}
};
req.send(JSON.stringify(contact));
}
If you are using Azure, and you want to do this using C#, see the following code sample from Microsoft:
msdn.microsoft.com/.../mt779074.aspx
You can also see this article by scalable solutions how to add authentication to the code above.
scaleablesolutions.com/web-api-authentication-from-javascript
Hope this helps.