Hi
I am trying to create a contact record using web api. I have a customer lookup field called parent account on the contact entity. I want to specify this field in web api using the alternate key (have define emailaddress1 as alternate key on account). I am using the following code but getting error that parent account field is not defined. Any ideas?
function createOperationUsingWebAPI() {
var clientUrl = Xrm.Page.context.getClientUrl();
var req = new XMLHttpRequest()
req.open("POST", encodeURI(clientUrl + "/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 () {
var accountUri = this.getResponseHeader("OData-EntityId");
};
var body = JSON.stringify({
"firstname": "Test",
"lastname": "WEB API",
"new_parentaccount@odata.bind":"/accounts(emailaddress1='someone_i@example.com')"
});
req.send(body);
}
Thanks