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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Dataverse API PATCH lo...
Power Apps
Unanswered

Dataverse API PATCH lookup column

(0) ShareShare
ReportReport
Posted on by 22

I want to use PATCH API of Dataverse to update lookup column. I am getting 200 OK response but the lookup column value not getting updated. Here is the sample request:

 

URL: {{dataverse_url}}/Employees(7af4aca9-734c-ed11-bba2-0022489935a6)/Country

BODY:

{
"@odata.countryid":"{{dataverse_url}}/countries(c8046381-6c4c-ed11-bba2-0022489935a6)"
}

 

* {{dataverse_url}} -> your dataverse url
* Country is lookup column in Employees table
* Countries is table used in lookup
* countryid is unique identifier

 

Thanks,

KD

 

I have the same question (0)
  • Fubar Profile Picture
    8,365 Super User 2025 Season 2 on at

    Main issue is probably the format of the bind - if you were doing it via XMLHTTP it would something more like ... (below updates a contact Lookup on the account table)

    var entity = {};
    entity["new_secondarycontact@odata.bind"] = "/contacts(95bd7961-e7f8-ea11-a815-000d3a799a0d)";
    
    var req = new XMLHttpRequest();
    req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/accounts(95bd7961-e7f8-ea11-a815-000d3a799a77)", 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.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
    req.onreadystatechange = function() {
     if (this.readyState === 4) {
     req.onreadystatechange = null;
     if (this.status === 204) {
     //Success - No Return Data - Do Something
     } else {
     // error 
     }
     }
    };
    req.send(JSON.stringify(entity));

     

  • Guido Preite Profile Picture
    1,488 Super User 2024 Season 1 on at

    the name of lookup fields is not always the logical name, you can use my tool Dataverse REST Builder to find the exact syntax for your environment.

  • kunald_gmeet Profile Picture
    22 on at

    @Fubar - It's working properly for updating other columns, only problem i am facing is with lookup column. trying to do this using POSTMAN and not using XMLHTTP.

     

    Thanks,

    KD

  • Fubar Profile Picture
    8,365 Super User 2025 Season 2 on at

    Provided example so you could see that the Structure of your query, the bind in particular, is not correct for a Lookup (is different to normal text fields etc). you need to change the "@OData.countryid" keyword.

  • kunald_gmeet Profile Picture
    22 on at

    Ok, can you please help with correct syntax for a lookup field PATCH ? I am using the one I shared.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard