Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

Performing updates using alternate key in Dynamics 365 WebAPI

Posted on by 25

Can anyone help , as I believe someone has already faced the issue I'm having.

I have a custom entity (alssc_anglesector) with an alternate key (alssc_name)

“alssc_ANGLESector@odata.bind”: “/alssc_anglesectors(alssc_name=’Air’)”, “

alssc_ANGLESector@odata.bind”: “/alssc_anglesectors(alssc_name=’Water Auth/Company’)”,

when I create an account and use the first bind with “Air” it works fine, while when using the second “Auth/Company” I got the response

“message”: “Bad Request – Error in query syntax.”, “type”: “Microsoft.OData.ODataException”, “stacktrace”: ” at Microsoft.OData.UriParser.ODataPathParser.ExtractSegmentIdentifierAndParenthesisExpression(String segmentText, String& identifier, String& parenthesisExpression)

I have also tried to encode it

"alssc_ANGLESector@odata.bind": "/alssc_anglesectors(alssc_name=\u0027Water Auth\u002FCompany\u0027)",

but he end result was the same.

I’m not being able to overcome this, Any ideias / suggestions ?

Could it be a Bug in D365 API WebApi ?

Best regards, Manuel

  • Verified answer
    RE: Performing updates using alternate key in Dynamics 365 WebAPI

    Hi!

    The request is unsupported: 

    Unicode characters in key value

    If the data within a field that is used in an alternate key will contain one of the following characters <,>,*,%,&,:,/,\\ then update or upsert (PATCH) actions will not work.

    If you only need uniqueness then this approach will work, but if you need to use these keys as part of data integration then it is best to create the key on fields that won't have data with these characters.

    https://docs.microsoft.com/en-us/powerapps/maker/common-data-service/define-alternate-keys-reference-records#unicode-characters-in-key-value

  • mesteves Profile Picture
    mesteves 25 on at
    RE: Performing updates using alternate key in Dynamics 365 WebAPI

    Hi Bipin Kumar

    Thanks for the suggestion. The same reply is returned...

    "alssc_AcmeSector@odata.bind""/alssc_Acmesectors(alssc_name='Water%20Auth%2FCompany')",
    "innererror": {
                "message""Bad Request - Error in query syntax.",
                "type""Microsoft.OData.ODataException",
                "stacktrace""   at Microsoft.OData.UriParser.ODataPathParser.ExtractSegmentIdentifierAndParenthesisExpression
    I'll customize the entities with one extra column (code) and will  go that way... but this seems to be some sort of bug in the Api....
    Thanks,
    Manuel
  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Performing updates using alternate key in Dynamics 365 WebAPI

    Hi,

    Can you try below syntax and see if it works.

    Water%20Auth%2FCompany

    If found helpful, Please mark my answer verified.

  • mesteves Profile Picture
    mesteves 25 on at
    RE: Performing updates using alternate key in Dynamics 365 WebAPI

    Thanks Aditya ,

    However in a integration scenario with external applications, it harder to do it by Id, we would need to know all the possible values for the Id's.

    Thanks anyway, it's an option to keep open :) 

  • Suggested answer
    Aditya Profile Picture
    Aditya 260 on at
    RE: Performing updates using alternate key in Dynamics 365 WebAPI

    Hi Mesteves,

    I am not sure how alternate keys are assigned in D365

    but I know that @odata.bind can be used for the record id as shown below :-

         var data={         "alssc_anglesectorid@odata.bind": "/alssc_anglesectors(" + result[_alssc_anglesectorid_value] + ")"}

    or

    newObj["alssc_anglesectorid@odata.bind"] = "/alssc_anglesectors(" + result["_alssc_anglesectorid_value"] + ")";

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Performing updates using alternate key in Dynamics 365 WebAPI

    Manuel,

    The best way is to open a ticket with Microsoft and ask for support - mbs.microsoft.com/.../CRMSupport

  • mesteves Profile Picture
    mesteves 25 on at
    RE: Performing updates using alternate key in Dynamics 365 WebAPI

    Thanks a33ik,

    I have tried, and the result is the same :( 

    "alssc_ANGLESector@odata.bind": "/alssc_anglesectors(alssc_name='Water Auth%2fCompany')",
    "message": "Bad Request - Error in query syntax.",

    I'm starting to really believe that is a webApi issue. How can I have someone from MSFT to take a look and confirm this problem ? 

    Best regards, 

    Manuel

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Performing updates using alternate key in Dynamics 365 WebAPI

    Hello,

    Try to replace 

    ’Water Auth/Company’

    with 

    ’Water Auth%2fCompany’

    according to following post - https://stackoverflow.com/questions/43139878/webapi-with-backslash-2f-in-id-parameter-causes-404-not-found

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans