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...
Answered

Sending a POST Request in AL code for Stripe Checkout API

(0) ShareShare
ReportReport
Posted on by 2,304 Moderator

I'm trying to create a Stripe checkout session in Business Central. but I'm facing an issue with passing the content type as "application/x-www-form-urlencoded". I've tried setting the header  header.Add('Content-Type', 'application/x-www-form-urlencoded') but I'm facing this error.
pastedimage1676309836993v1.png

This is my Code..

procedure StripeAPI()
    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
        CancelURL1 := 'https://example.com';
        success_url1 := 'https://example.com';
        line_items_currency1 := 'usd';
        line_items_Nam := 'Shirt';
        line_items_unitAmoun := '2000';
        LineAmountQuantit := '1';
        Mode1 := 'payment';
        PaymentMethodType1 := 'card';

        tmpString := 'mode='   TypeHelper.UrlEncode(Mode1)   '&line_items[0][price_data][unit_amount]='   TypeHelper.UrlEncode(line_items_unitAmoun)   '&cancel_url='   TypeHelper.UrlEncode(CancelURL1)   '&success_url='   TypeHelper.UrlEncode(success_url1)   '&line_items[0][price_data][currency]='   TypeHelper.UrlEncode(line_items_currency1)   '&line_items[0][price_data][product_data][name]='   TypeHelper.UrlEncode(line_items_Nam)   '&line_items[0][quantity]='   TypeHelper.UrlEncode(LineAmountQuantit)   '&payment_method_types[0]='   TypeHelper.UrlEncode(PaymentMethodType1);

        Message(tmpString);
        cont.WriteFrom(tmpString);
        cont.ReadAs(tmpString);

        cont.GetHeaders(header);
        header := client.DefaultRequestHeaders;
        header.Add('charset', 'UTF-8');
        header.Remove('Content-Type');
        header.Add('Content-Type', 'application/x-www-form-urlencoded');
        header.Add('Authorization', 'Bearer *********************************************');

        client.Post('**********************', cont, response);
        response.Content.ReadAs(responseText);
    end;


I have also checked that the tmpString a variable that contains the data in the text format url embedded and it is working fine in Postman when selecting "application/x-www-form-urlencoded".

can you guys help me..
Regards

I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Hi,

    Try to use as per below

    cont.WriteFrom(tmpString);

    cont.getheaders(Header);

    header.clear();

    header.DefaultRequestHeaders.Add('Authorization', 'Bearer ' + APIKey + '');

    header.Add('Content-Type', 'application/x-www-form-urlencoded');

    client.Post('**********************', cont, response);
    response.Content.ReadAs(responseText);

  • Govinda Kumar Profile Picture
    2,304 Moderator on at

    Hi Nitin Verma,

    Thank you for replying..

    I tried using your way, but getting the error..
    pastedimage1676355084135v1.png

    I also tried that one
    pastedimage1676355135684v2.png

    Can you help kindly tell me what should I do..
    regards

  • Govinda Kumar Profile Picture
    2,304 Moderator on at

    Hi, Nitin Verma thank you very much for helping...

    I just replaced HttpHeaders with HttpClient, It was my mistake in the previous reply.. sorry for that..

    pastedimage1676355648629v1.png
    Thank you
    regards

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

    So its working now?

  • Govinda Kumar Profile Picture
    2,304 Moderator on at

    Hi, Nitin Verma

    Yes, it is working.

    Regards

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

    Good to know.

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 April 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,086 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,290 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,218

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans