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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

How to call external API from navision

(0) ShareShare
ReportReport
Posted on by 2,582

Hi all,

I want to call external api from navision

I have used below code

CallRESTWebServiceFinal(BaseUrl : Text;Method : Text;RestMethod : Text;HttpContent : DotNet "System.Net.Http.HttpContent";HttpResponseMessage : DotNet "System.Net.Http.HttpResponseMessage")

HttpClient := HttpClient.HttpClient();

HttpClient.DefaultRequestHeaders.Add('Username', 'username');
HttpClient.DefaultRequestHeaders.Add('Password', 'password');
HttpClient.DefaultRequestHeaders.Add('ContentType', 'application/json');
HttpClient.BaseAddress := Uri.Uri(BaseUrl);
CASE RestMethod OF
'GET':
HttpResponseMessage := HttpClient.GetAsync(Method).Result;
'POST':
HttpResponseMessage := HttpClient.PostAsync(Method,HttpContent).Result;
'PUT':
HttpResponseMessage := HttpClient.PutAsync(Method,HttpContent).Result;
'DELETE':
HttpResponseMessage := HttpClient.DeleteAsync(Method).Result;
END;

HttpResponseMessage.EnsureSuccessStatusCode(); // Throws an error when no success

CallAPIFunction()

SubUrl:='suburl';
ServicePointManager.SecurityProtocol:=SecurityProtocolType.Tls12;
CallRESTWebServiceFinal('MainURL',SubUrl,'GET',null,HttpResponseMessage);
result := HttpResponseMessage.Content.ReadAsStringAsync.Result;

But I'm getting below error

unsupported media type

please help

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

    I would suggest first the URL result with the Postman App or any other app, if you are getting the same result, the same you want to achieve with this code in NAV

    Also try to add below lines

    HttpClient.Accept := 'application/json';
    HttpClient.ContentType := 'application/json';

  • Tina Menezes Profile Picture
    2,582 on at

    Hello Sir,

    Yes, its working with postman.

    Even after putting the code which you suggested I'm getting same error.

    HttpClient.DefaultRequestHeaders.Add('Accept', 'application/json');

    HttpClient.DefaultRequestHeaders.Add('ContentType', 'application/json');

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,010

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,270 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,085 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans