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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Business Central web services Query param instead of header param

(0) ShareShare
ReportReport
Posted on by 5

Heya

trying to connect to the web services via javascript. Having a really hard time succeeding. Keeps giving me a cors error. Wonder - Is it possible to connect to it with a query param instead of a header param? My experience is, that it is a lot easier. Example: 

localhost:endpoint/username=xxxxx&password=&&&&&&

Currently I'm doing as follows (but i keep getting 401 even though I'm certain the credentials are correct.):

    <script>
  async function getUser() {
        try {
            const response = await fetch("">xxxxx.dv.local:7048/.../xxxxxxx", {
            method: 'GET',
            mode: 'no-cors',
            headers: {
                accept: 'application/json',
                'Authorization': 'Basic '+btoa('xxxxxx:xxxxxxx.')
            },
            });

            if (!response.ok) {
            throw new Error(`Error! status: ${response.status}`);
            }

            const result = await response.json();
            console.log(result)
            return result;
        } catch (err) {
            console.log(err);
        }
        }

        getUser();
    </script>

I have the same question (0)
  • Salomon Profile Picture
    5 on at

    Not Cors but 401 Unathorized.

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    You should probably switch to Oauth instead of basic authentication.

    Here are some links for you:

    docs.microsoft.com/.../authenticate-web-services-using-oauth

    docs.microsoft.com/.../web-services-authentication

  • Suggested answer
    Jeffrey Bulanadi Profile Picture
    9,128 Super User 2026 Season 1 on at

    Hi Salomon,

    This is vulnerable to web attacks as you exposed the credentials thru url.

    Going back to your requirements, Microsoft recommends to use the OAuth 2.0 authentication method. Below links is much easier to understand as it shows an actual procedure how to do it.

    robertostefanettinavblog.com/.../

    www.kauffmann.nl/.../

    https://yzhums.com/20690/

    If you find this useful please give it a like or verify the answer. By this way you can help other members know that the topic has been answered. Have a nice day. Thank you.

    Cheers,

  • Suggested answer
    YUN ZHU Profile Picture
    101,995 Super User 2026 Season 1 on at

    Hi, This seems to be an authentication issue.
    Although Microsoft recommends Oauth, it can still be used until BC21.

    You can test it in PostMan and then turn to Code.

    pastedimage1659313936981v1.png

    Hope this helps.

    Thanks.

    ZHU

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Hi,

    Its not recommended to use URL with credentials, you can try OAuth.

    Thanks.

  • Salomon Profile Picture
    5 on at

    Tried it in postman but can strangely only get it to work with NTLM authentication. This does not provide a code snippet that is functional in Javascript.

  • Salomon Profile Picture
    5 on at

    Hey Jeffrey

    Not too worrid about exposing the credentials as it is an on-premise application. However i will look into switching to Oath2 if possible for a localhosted BC365.

  • Salomon Profile Picture
    5 on at

    pastedimage1659358874930v1.png

    It seems i can only authenticate via NTLM. This does not provide a javascript code snippet that is functional. Am not completely sure why this is the case.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,050 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,351 Super User 2026 Season 1

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 1,200 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans