web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Can't set a lookup fie...
Power Apps
Unanswered

Can't set a lookup field value using Dataverse REST API

(0) ShareShare
ReportReport
Posted on by 24

Hello,
I'm facing an issue while trying to set a lookup field using guid. At a certain trigger I create a contact and then create a lead (I'm using an entity created by myself, not the Dynamics table) to which I would like to bind the contact. I'm trying to set the contact using the lookup field's logic name:

"new_contatto@odata.bind" : "/contacts([guid])"

This is he error I'm getting:
 
Error identified in Payload provided by the user for Entity :'new_leads', For more information on this error please follow this help link https://go.microsoft.com/fwlink/?linkid=2195293 InnerException : Microsoft.OData.ODataException: An undeclared property 'new_contatto' which only has property annotations in the payload but no property value was found in the payload. [...]

I've even tried to use the relationship name instead of the field's name as suggeste in this topic https://stackoverflow.com/questions/43970292/an-undeclared-property-when-trying-to-create-record-via-web-api
but I'm getting the same error. Any help on how to overcome thsi issue?
Thanks.
I have the same question (0)
  • Devvj Profile Picture
    1,132 Super User 2024 Season 1 on at

    Hi @francesco9 
    I would highly suggest using the Dataverse REST builder tool (GitHub - GuidoPreite/DRB: Dataverse REST Builder), then you can build and test your queries and get the code out in various formats.

    It's also a part of the XRMToolbox if you familiar with that.

    -------------------------------------------------------------------------
    If this is the answer for your question, please mark the post as Solved.
    If this answer helps you in any way, please give it a like.

  • francesco9 Profile Picture
    24 on at

    Hi @Devvj,
    Thanks for you helpful reply, I didn't know this tool.
    It suggests me to indicate the field as "new_Contatto@odata.bind" (schema name) but I get the exact same error.

  • Devvj Profile Picture
    1,132 Super User 2024 Season 1 on at

    Hi @francesco9 
    Does it throw the same error if you try to run the query from inside the tool also?


  • francesco9 Profile Picture
    24 on at

    Yes it work! I'm executing the code from the Fetch tab:

    var record = {};
    record.new_name = "Test from REST Builder"; // Text
    record["new_Contatto@odata.bind"] = "/contacts(8cd8be33-0c40-ee11-bdf3-0022489b4543)"; // Lookup
    
    fetch(Xrm.Utility.getGlobalContext().getClientUrl() + "/api/data/v9.2/new_leads", {
    	method: "POST",
    	headers: {
    		"OData-MaxVersion": "4.0",
    		"OData-Version": "4.0",
    		"Content-Type": "application/json; charset=utf-8",
    		"Accept": "application/json",
    		"Prefer": "odata.include-annotations=*"
    	},
    	body: JSON.stringify(record)
    }).then(
    	function success(response) {
    		if (response.ok) {
    			var uri = response.headers.get("OData-EntityId");
    			var regExp = /\(([^)]+)\)/;
    			var matches = regExp.exec(uri);
    			var newId = matches[1];
    			console.log(newId);
    		} else {
    			return response.json().then((json) => { throw json.error; });
    		}
    	}
    ).catch(function (error) {
    	console.log(error.message);
    });

     

    Since I'm using a Zapier HTTP Request action, how can I convert this code to a request?
    I tried setting the exact same headers but I get this slightly diferent error:

    Error identified in Payload provided by the user for Entity :'new_leads', For more information on this error please follow this help link https://go.microsoft.com/fwlink/?linkid=2195293 ----> InnerException : Microsoft.OData.ODataException: The navigation property 'new_Contatto' has a property annotation 'odata.bind_contacts'. Navigation links in request payloads can only have the 'odata.bind' property annotation.



  • Devvj Profile Picture
    1,132 Super User 2024 Season 1 on at

    You can try to run the Associate-function after you created your lead, and se if that works out, just provide the guids, relationship name (should be something like "new_new_contatto_Contactid_contact" and the correct schema names in the code below:

    // NOTE: Associate Request in Xrm.WebApi supports multiple children, you can add them inside the relatedEntities array
    var associateRequest = {
    	target: { entityType: "contact", id: "11111111-1111-1111-1111-111111111111" },
    	relatedEntities: [
    			{ entityType: "new_contatto", id: "11111111-1111-1111-1111-111111111111" }
    	],
    	relationship: "new_new_contatto_Contactid_contact",
    	getMetadata: function () { return { boundParameter: null, parameterTypes: {}, operationType: 2, operationName: "Associate" }; }
    };
    
    Xrm.WebApi.execute(associateRequest).then(
    	function success(response) {
    		if (response.ok) {
    			console.log("Success");
    		}
    	}
    ).catch(function (error) {
    	console.log(error.message);
    });


    -------------------------------------------------------------------------
    If this is the answer for your question, please mark the post as Solved.
    If this answer helps you in any way, please give it a like.


  • francesco9 Profile Picture
    24 on at

    How can I run the function in Zapier? I can't import Xrm or any npm library, so I have to make a POST. Ho do I structure the URI and body?

  • Devvj Profile Picture
    1,132 Super User 2024 Season 1 on at

    @francesco9 
    I unfortunatly dont have experiance with the Zapier platform, but found some documentation on how to run custom code.

    Devvj_0-1693402153369.png

     

    And try to run this code:

    var record = {};
    record["new_Contatto@odata.bind"] = "/contacts(8cd8be33-0c40-ee11-bdf3-0022489b4543)"; // Lookup
    
    var req = new XMLHttpRequest();
    req.open("POST", "<PUT YOUR ENVIRONMENT URL HERE>/api/data/v9.2/new_leads", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Prefer", "odata.include-annotations=*");
    req.onreadystatechange = function () {
    	if (this.readyState === 4) {
    		req.onreadystatechange = null;
    		if (this.status === 204) {
    			var uri = req.getResponseHeader("OData-EntityId");
    			var regExp = /\(([^)]+)\)/;
    			var matches = regExp.exec(uri);
    			var newId = matches[1];
    			console.log(newId);
    		} else {
    			console.log(this.responseText);
    		}
    	}
    };
    req.send(JSON.stringify(record));

     

    Be sure to replace the "<PUT YOUR ENVIRONMENT URL HERE>" with the right environment url

    -------------------------------------------------------------------------
    If this is the answer for your question, please mark the post as Solved.
    If this answer helps you in any way, please give it a like.

  • francesco9 Profile Picture
    24 on at

    Thanks, I tried this code but "XMLHttpRequest" is not defined since it is a browser object. I have no clue on how to  overcome this issue.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 529 Most Valuable Professional

#2
Haque Profile Picture

Haque 230

#3
Kalathiya Profile Picture

Kalathiya 217 Super User 2026 Season 1

Last 30 days Overall leaderboard