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.
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
Good to know.
Hi, Nitin Verma
Yes, it is working.
Regards
So its working now?
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..
Thank you
regards
Hi Nitin Verma,
Thank you for replying..
I tried using your way, but getting the error..
I also tried that one
Can you help kindly tell me what should I do..
regards
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); |
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,228 Super User 2024 Season 2
Martin Dráb 230,056 Most Valuable Professional
nmaenpaa 101,156