Skip to main content

Notifications

Announcements

No record found.

Supply chain | Supply Chain Management, Commerce
Answered

OData / Rest: Patching an entity containing a /

(0) ShareShare
ReportReport
Posted on by 15

Does anyone have any insight into patching an entity with a / in the primary key?  For example:

ProductNumber = Product1
.../data/ProductsV2(ProductNumber='Product1')
{ "ProductName" = "NewName" }

Works just fine.

However, ProductNumber = 105E11/74N does not work.

This URL of course does not work: .../data/ProductsV2(ProductNumber='105E11/74N')

However encoding the ProductNumber doesn't allow it to be found: .../data/ProductsV2(ProductNumber='105E11%2F74N')

404 not found:
{
"Message": "No HTTP resource was found that matches the request URI '.../data/ProductsV2(ProductNumber='105E11/74N')'. No route data was found for this request."
}

Any help would be very much appreciated.

Thanks,
Tom

  • Verified answer
    tomhundley Profile Picture
    tomhundley 15 on at
    RE: OData / Rest: Patching an entity containing a /

    SOLUTION: I got an answer back from Microsoft support on this issue.  Forward slashes, backslashes, and pluses must be double escaped in the URL.

    / is %252F

    \ is %255C (I didn't test this one)

    + is %252B

    Reference: docs.microsoft.com/.../whats-new-in-aspnet-web-api-22

    Example:

    Doesn't work: .../data/ProductsV2(ProductNumber='105E11/74N')

    Doesn't work: .../data/ProductsV2(ProductNumber='105E11%2F74N')

    Works: .../data/ProductsV2(ProductNumber='105E11%252F74N')

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,391 Super User 2024 Season 2 on at
    RE: OData / Rest: Patching an entity containing a /

    Hi Tom,

    Try to use a backslash '\' as escape character before the slash or the html number '\'

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: OData / Rest: Patching an entity containing a /

    Tom,

    I will move your thread to AX forum where you can get answer from subject matter experts.

  • tomhundley Profile Picture
    tomhundley 15 on at
    RE: OData / Rest: Patching an entity containing a /

    Ya, it's AX.  Now "D365 Supply Chain Management", to be specific.  Formally D365 Finance and Operations, formally ...

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: OData / Rest: Patching an entity containing a /

    Tom,

    I looked closer and it doesn't look like Dynamics CE endpoints. Is it AX or NAV?

  • tomhundley Profile Picture
    tomhundley 15 on at
    RE: OData / Rest: Patching an entity containing a /

    Hey Andrew.  That would certainly be an acceptable workaround.  Is there a way to get the Id from the GET request without customizing the entity?  I'm ok customizing it, but I was hoping for some out-of-the-box functionality.  A GET on ProductV2 (for all the entities, for that matter), don't include an Id, RecId, etc.  Hopefully, I'm missing something pretty simple.

    Thanks,

    Tom

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: OData / Rest: Patching an entity containing a /

    Tom,

    As a possible workaround you can retrieve id of the record using your key and use id with a Patch to update the record. I understand that it's 2 steps operation but it should work fine.

    On the other hand opening of the ticket should cause the fix to be developed.

  • tomhundley Profile Picture
    tomhundley 15 on at
    RE: OData / Rest: Patching an entity containing a /

    Filter works perfectly fine.  However, when using filter, an array is returned instead of a single element, and thus you cannot use PATCH or DELETE.  The only way to use those operations is by selecting the single resource via its primary key.  Thus, I'm stuck.  I've opened a support request with Microsoft and will update this when I figure it out.

  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: OData / Rest: Patching an entity containing a /

    Hi partner,

    Did you try "filter" condition in Odata or Rest api url?

    I tried in my instance with querying record name equals "name/2" and it worked correctly.

    1134.pastedimage1577088385733v1.png

    7750.pastedimage1577088426948v2.png

    If you use the URL to retrieve data directly, this "/" may be mistaken for a separator by the system.

    If you want to get data from an entity with some conditions like primary key or field, you could refer to web api.

    https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/query-data-web-api#filter-results

    Best Regards,

    Leo

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans