Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

Character # (hash #) in URL after api/ causes unexpected Authentication_InvalidCredentials error

Posted on by 9

Steps to reproduce

  1. Make a GET request to
    api.businesscentral.dynamics.com/.../companies
    (works)
  2. Add a url-encoded # anywhere after "api/"
    api.businesscentral.dynamics.com/.../c#ompanies
    fails with error code 'Authentication_InvalidCredentials'. Message 'The server has rejected the client credentials. CorrelationId: ...'
    (it worked before, so it is not due to invalid credentials)

Using a raw hash (not URL-encoded), results in an error: BadRequest_NotFound "Bad Request - Error in query syntax."

The response is the same for both custom APIs and the v2.0 API.


Why do I need a hash in the url?

We are trying to update the 'Manufacturer Code' field of an item. That field is not in the v2.0 Microsoft API, so we use a custom API, where an item is identified by the 'No' field. To update the manufacturer code of an item, I use OData and call:
PATCH api.businesscentral.dynamics.com/.../Items(No='...')

Many of our items contain # in their item number (No). 

Any help or alternative solution is welcome.

  • Verified answer
    Radio Fred Profile Picture
    Radio Fred 9 on at
    Character # (hash #) in URL after api/ causes unexpected Authentication_InvalidCredentials error
    We found a solution: Using OData batch requests does not result in the error described, and the field is updated correctly.
    Using OData transactional $batch requests - Business Central | Microsoft Learn

    The bug is still there, and batching is an extra step. So this is a workaround.
  • Radio Fred Profile Picture
    Radio Fred 9 on at
    RE: Character %23 (hash #) in URL after api/ causes unexpected Authentication_InvalidCredentials error

    Thank you for your suggestion Hasnain Ali.

    Unfortunately I get the Authentication_InvalidCredentials error after URL-encoding the hash with %23

  • Suggested answer
    Hasnain Ali Profile Picture
    Hasnain Ali 132 on at
    RE: Character %23 (hash #) in URL after api/ causes unexpected Authentication_InvalidCredentials error

    Hi,

    Have you tried Encoding your URL?

    You can use this if it helps:

    var

           TypeHelper: Codeunit "Type Helper";

    begin

          URLpath := TypeHelper.UrlEncode(URLpath);

    end;

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans