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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Using a x-www-form-urlencoded Rest API with Business central (to get token)

(1) ShareShare
ReportReport
Posted on by 60

Hi everyone,

I'm trying to develop a function with AL that permits to Post a url encoded content.
pastedimage1612980029302v1.png

It works fine with postman. The following procedure that I've started developping doesn't work :

procedure GetToken() ResponseText: text;

    Var
        client: HttpClient;
        cont: HttpContent;
        header: HttpHeaders;
        response: HttpResponseMessage;
        Jobject: JsonObject;
        tmpString: Text;
        TypeHelper: Codeunit "Type Helper";
        granttype: text;
        clienid: text;
        username: text;
        password: text;
    Begin
        granttype := 'xxxxx';
        clienid := 'xxxxxx';
        username := 'xxxxxxxxx';
        password := 'xxxxxxxxxxxxx';
        Jobject.Add('grant_type', TypeHelper.UrlEncode(granttype));
        Jobject.Add('client_id', TypeHelper.UrlEncode(clienid));
        Jobject.Add('username', TypeHelper.UrlEncode(username));
        Jobject.Add('password', TypeHelper.UrlEncode(password));
        Jobject.WriteTo(tmpString);
        cont.WriteFrom(tmpString);
        cont.ReadAs(tmpString);

        cont.GetHeaders(header);
        header.Add('charset', 'UTF-8');
        header.Remove('Content-Type');
        header.Add('Content-Type', 'application/x-www-form-urlencoded');

        client.Post('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', cont, response);
        response.Content.ReadAs(ResponseText);

    end;

Can someone help me please?
I get this response everytime :

{
"error": "invalid_request",
"error_description": "Missing form parameter: grant_type"
}

Ps : it doesn't work even without encoding the parameters.

Thanks in advance

I have the same question (0)
  • Suggested answer
    Marco Mels Profile Picture
    Microsoft Employee on at

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

    Thanks.

  • Community Member Profile Picture
    on at

    @Brahim Nasr I am facing the same issue have you got any solution for the same?

  • RickTweedle Profile Picture
    5 on at

    Did you get this resolved? I'm having the same issue re "missing parameter grant_type" when trying to get an access token in AL code.

    I've also tried sending as json, and form-data.. both return the same error.

    I've noticed that postman only seems to work if send as form-data, if i convert it to application/json and send the details as raw json data i get the same "missing parameter grant_type" error

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,993 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,116 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 557 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans