Skip to main content

Notifications

Business Central forum
Suggested answer

ODATA API set empty value to GUID field

Posted on by Microsoft Employee

Hello, I am a programmer trying to communicate with the Dynamics 365 Business Central ODATA API.
Perhaps my question relates to the ODATA protocol itself, but I don't understand how I can set a blank value for a field.

docs.microsoft.com/.../dynamics_item_update

Let's say I have an Item that says 'Item Category Code'='DIV'.
On the website I can see it as https://prnt.sc/22l7aat.
In the ODATA API I can get it as https://prnt.sc/22l7nei.
I can also update the 'itemCategoryId' field with a different GUID using PATCH request and that will work.

But when I try to set 'itemCategoryId'='' (an empty string), I get an 'Invalid Request Body' error.
If I set 'itemCategoryId'='00000000-0000-0000-0000-000000000000' (the value which is displayed in API if I specify an empty value on the site) I get an error 'The Item Category does not exist. Identification fields and values: {00000000-0000-0000-0000-000000000000}'.
If I specify 'itemCategoryId'='_x0020_' (a special empty string character), it gets the same error as above.
If I don't specify 'itemCategoryId', then this field won't be modified, because it's a PATCH, not a PUT request.

What should I specify to put an empty value in 'itemCategoryId'?

Kind regards!

Categories:
  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: ODATA API set empty value to GUID field

    Just for the history: I opened an issue on github

    github.com/.../2154

    and they confirmed it was a bug and will fix it.

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,160 Most Valuable Professional on at
    RE: ODATA API set empty value to GUID field

    I cannot help woth PHP. In C# what I've suggested works and creates a Guid like "{00000000-0000-0000-0000-000000000000}"

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: ODATA API set empty value to GUID field

    No one knows the answer? Then can anyone advise me on who to approach with this question and who can help me with it?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: ODATA API set empty value to GUID field

    I am trying to update a record that has already been created. Now the record has a non-empty 'itemCategoryId' and I'm trying to assign an empty value.

  • Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,744 Moderator on at
    RE: ODATA API set empty value to GUID field

    What operation are you trying to do using the API. Updating or inserting a new Item record?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: ODATA API set empty value to GUID field

    I specifically want to specify an empty value. I use PHP.

    I tried 'itemCategoryId'='Guid.Empty' and got the error 'Invalid Request Body' again.
    'itemCategoryId'=null does not work also.
    'itemCategoryId'=false does not work also.
    'itemCategoryId'=0 does not work also.
    'itemCategoryId'='0' does not work also.
    'itemCategoryId'=-1 does not work also.
    'itemCategoryId'='-1' does not work also.
    'itemCategoryId'=' ' (one space) does not work also.
    'itemCategoryId'=' ' (one tab) does not work also.

    Did I write my question in the right place? Because I couldn't find any other way to communicate with API support.

  • Stefano Demiliani Profile Picture
    Stefano Demiliani 37,160 Most Valuable Professional on at
    RE: ODATA API set empty value to GUID field

    Normally if you don't want to specify a value for a non mandatory field, you can simply ignore it from the API JSON body you're passing.

    If you want to set a guid as empty, you can use (in C#) Guid yourFieldId = Guid.Empty;

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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,522 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,441 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans