web
You’re offline. This is a read only version of the page.
close
Skip to main content
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,211 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,607 Moderator on at
    RE: Sending a POST Request in AL code for Stripe Checkout API

    Good to know.

  • Govinda Kumar Profile Picture
    2,211 Moderator on at
    RE: Sending a POST Request in AL code for Stripe Checkout API

    Hi, Nitin Verma

    Yes, it is working.

    Regards

  • Suggested answer
    Nitin Verma Profile Picture
    21,607 Moderator on at
    RE: Sending a POST Request in AL code for Stripe Checkout API

    So its working now?

  • Govinda Kumar Profile Picture
    2,211 Moderator on at
    RE: Sending a POST Request in AL code for Stripe Checkout API

    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

  • Govinda Kumar Profile Picture
    2,211 Moderator on at
    RE: Sending a POST Request in AL code for Stripe Checkout API

    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

  • Suggested answer
    Nitin Verma Profile Picture
    21,607 Moderator on at
    RE: Sending a POST Request in AL code for Stripe Checkout API

    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);

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,725 Super User 2025 Season 2

#2
Sumit Singh Profile Picture

Sumit Singh 2,610

#3
Jeffrey Bulanadi Profile Picture

Jeffrey Bulanadi 2,221

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans