Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

portal webapi: create connection record

(0) ShareShare
ReportReport
Posted on by 5

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"))
	}
});
}

  • snowflake1974 Profile Picture
    5 on at
    RE: portal webapi: create connection record

    Fantastic Guido, I did exactly as you said this morning using CRM restbuilder in my 2011 CRM and it worked and I am successfully able to create a connection.

  • Verified answer
    Guido Preite Profile Picture
    54,077 Moderator on at
    RE: portal webapi: create connection record

    the syntax will be something like this:

    var record = {};
    record["record1roleid@odata.bind"] = "/connectionroles(00000000-0000-0000-0000-0000000000000)"; // Lookup
    record["record1id_contact@odata.bind"] = "/contacts(00000000-0000-0000-0000-000000000000)"; // Lookup
    record["record2id_opportunity@odata.bind"] = "/opportunities(00000000-0000-0000-0000-000000000000)"; // Lookup
    
    webapi.safeAjax({
    	type: "POST",
    	contentType: "application/json",
    	url: "/_api/connections",
    	data: JSON.stringify(record),
    	success: function (data, textStatus, xhr) {
    		var newId = xhr.getResponseHeader("entityid");
    		console.log(newId);
    	},
    	error: function (xhr, textStatus, errorThrown) {
    		console.log(xhr);
    	}
    });

    to generate this kind of Web API you can use my tool Dataverse REST Builder

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,206 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,968 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans