I want to create a record in connections entity using portal webapi. I have setup all the necessary permissions , site settings but just not sure how I can pass an entityrefrence in the post. In the plugin my code is :
Entity connection = new Entity();
connection.LogicalName = "connection";
connection.Attributes.Add("record1id", new EntityReference("Contact", "contact_guid_here"));
connection.Attributes.Add("record2id", new EntityReference("Opportunity", "opportnity_guid_here"));
// to fill both the connection role lookups, uncomment the below line
//connection.Attributes.Add("record2roleid", new EntityReference("connectionrole", new Guid(connRoleId)));
connection.Attributes.Add("record1roleid", new EntityReference("connectionrole", new Guid("connectioRole_guid_here")));
service.Create(connection);
In portal I am trying to do something like this but keeps getting 500 error.
function createcontact(){
var dataObject={
"record1id":"18060257-90d2-ec11-a7b6-00224894367a",
"record2id":"68500f21-3318-4412-8931-70259e7f8462"
};
webapi.safeAjax({
type: "POST",
url: "/_api/connections",
contentType:"application/json",
data: JSON.stringify(dataObject),
success: function(res, status, xhr) {
//print id of newly created entity record
console.log("entityID: " xhr.getResponseHeader("entityid"))
}
});
}