Since you are creating a new contact, why do you have the contact id in the Json? Do you need it?
Take a look at the code below to create new contact using Web Api:
var entity = {};
entity["parentcustomerid_account@odata.bind"] = "/accounts(12345678-1234-1234-1234-123456780124)";
entity.lastname = "TestLast";
entity.firstname = "TestFirst";
entity.emailaddress1 = "johndoe@testmail.com";
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/contacts", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
var uri = this.getResponseHeader("OData-EntityId");
var regExp = /\(([^)]+)\)/;
var matches = regExp.exec(uri);
var newEntityId = matches[1];
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
You can use CRM Rest Builder to generate code as above:
github.com/.../CRMRESTBuilder
Hope this helps.