NavBC: httpclient error when get data

golfdukdik
Member Posts: 4
Hi all,
I can't get data from api url.
anyone can help me ?
my code as below
procedure StartBOTT_API();
var
Client: HttpClient;
HttpRespone: HttpResponseMessage;
ResponseText: Text;
Url: Text;
begin
Url := 'https://api.exchangeratesapi.io/latest';
Client.Get(Url, HttpRespone);
end;
=========
when run this code

I'm using dynamics 365 business central 15.0.36560.0
I can't get data from api url.
anyone can help me ?
my code as below
procedure StartBOTT_API();
var
Client: HttpClient;
HttpRespone: HttpResponseMessage;
ResponseText: Text;
Url: Text;
begin
Url := 'https://api.exchangeratesapi.io/latest';
Client.Get(Url, HttpRespone);
end;
=========
when run this code

I'm using dynamics 365 business central 15.0.36560.0
0
Best Answer
-
Hello @golfdukdik ,
Your code works, I changed a little to get an ouptutprocedure StartBOTT_API(); var Client: HttpClient; HttpRespone: HttpResponseMessage; ResponseText: Text; Url: Text; ResTxt: Text; begin Url := 'https://api.exchangeratesapi.io/latest'; Client.Get(Url, HttpRespone); if HttpRespone.IsSuccessStatusCode() then begin HttpRespone.Content.ReadAs(ResTxt); Message(ResTxt); end else Message('Error: %1', HttpRespone.HttpStatusCode); end;
and is ok:
Maybe your extension is not allowed to use httpclient requests, check this in the extension:
Regards.
5
Answers
-
Hello @golfdukdik ,
Your code works, I changed a little to get an ouptutprocedure StartBOTT_API(); var Client: HttpClient; HttpRespone: HttpResponseMessage; ResponseText: Text; Url: Text; ResTxt: Text; begin Url := 'https://api.exchangeratesapi.io/latest'; Client.Get(Url, HttpRespone); if HttpRespone.IsSuccessStatusCode() then begin HttpRespone.Content.ReadAs(ResTxt); Message(ResTxt); end else Message('Error: %1', HttpRespone.HttpStatusCode); end;
and is ok:
Maybe your extension is not allowed to use httpclient requests, check this in the extension:
Regards.
5 -
Hi ftornero,
Thanks for your reply
I'm already to allow httpclient and use your code but get same error
I try to debug my code is break at this point
Do you have any recommendations?
0 -
Hello @golfdukdik ,
Have you tried to call the URL from a browser ?
What is your environment (docker, local installaction, etc.) ?
Regards
0 -
0
-
0
-
Hi @ftornero
I try to use environment on localhost is works.
I think my docker is broken
thank you very much for your help
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions