Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

Json API Get and POST methods in X++ with API Key Authorization

Posted on by 505

Dear All,

I have Json API with Key and Value as Authorisation and Ineed to  get the data from API using the key and value by X++ code and send them response. I also need to send data to API web services using Json using secret key and value.

Environemnt : AX 2012 R3

Code:

static void MYAPITest(Args _args)
{
RetailWebRequest request;
RetailWebResponse response;
str rawResponse, value;
str _startDate, _endDate;
Map data;

#define.ServiceURL(API URL Link)
#define.APIkey("MYKEY")

RetailCommonWebAPI webApi = RetailCommonWebAPI::construct();
request = RetailWebRequest::newUrl(#ServiceURL);
request.parmHeader(@"'x-apiKey','MYKEY', 'x-secret', 'MYVALUE'");


request.parmContentType(@"application/json; encoding='utf-8");
request.parmMethod("GET");

response = webApi.getResponse(request);
rawResponse = response.parmData();
data = RetailCommonWebAPI::getMapFromJsonString(rawResponse);
value = data.lookup("employeeId");
info(strFmt("Employee Id: %1",value));
}

Cause of Error ( Assumption) : I do not  know how to pass key and value that make valid key for API.

  • Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: Json API Get and POST methods in X++ with API Key Authorization

    You too will need to give us more details about your problem before we can help you with it. First of all, look into documentation of the service you're going to call - it should tell you how it should be used. It can be implemented in million ways and we can't know which one it is if you don't tell us anything about it.

  • Gourav Goyal Profile Picture
    Gourav Goyal 30 on at
    RE: Json API Get and POST methods in X++ with API Key Authorization

    Heyy, 

    Did u got the solution ?

    I also want to use key and value to send sms , but i also dont know to do it in x++ , please share ur solution / code ..

  • Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: Json API Get and POST methods in X++ with API Key Authorization

    I'm sorry, but we can't solve your problem if you don't tell us what you're doing and what kind of problem you have with it. You'll have to explain that first.

  • D365Techies Profile Picture
    D365Techies 10 on at
    RE: Json API Get and POST methods in X++ with API Key Authorization

    Hi Martin,

    I need to call a third party service(external service) with API authentication method through x++. Kindly send me any sample code for this method

    Thanks.

  • Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: Json API Get and POST methods in X++ with API Key Authorization

    Can you please give us a more details description of your problem? As above, either find out how the service expects to receive the key (it's usually in documentation), or tell us which service it is, so we could help you to find it.

    We can't write code unless we know what it should do.

  • D365Techies Profile Picture
    D365Techies 10 on at
    RE: Json API Get and POST methods in X++ with API Key Authorization

    I also have same issue. Have you got any solution to send the API key

  • Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: Json API Get and POST methods in X++ with API Key Authorization

    We can't write any code for this logic before we clarify what "this logic" is.

    Yes, I know that the owner will provide the key, but you didn't tell us where it should be used when calling the service. Somewhere in a header? If so, which one? Or somewhere in the actual payload?

    I see you tried to set some headers, but I can't say whether it's correct or not. Maybe you have information about the service that you didn't share, or maybe you just copied a piece of code unrelated to the web service in question.

  • Safeer PS Profile Picture
    Safeer PS 505 on at
    RE: Json API Get and POST methods in X++ with API Key Authorization

    The vendor will proviide key and value. we need to acces their API webservice use key and value. Do you know any link/posts that can help me to write this logic in X++.

  • Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: Json API Get and POST methods in X++ with API Key Authorization

    Then you must ask the owner of the web service how they expect that you'll provide the key.

    By the way, you say "API Key Authorisation" but the link explains that "an API key is not a method of authorization, it’s a method of authentication". :-)

  • Safeer PS Profile Picture
    Safeer PS 505 on at
    RE: Json API Get and POST methods in X++ with API Key Authorization

    Its API Key Authorisation present in json api Authorisation

    The vendor gave us secret key and value and we nee to use that for our data in their DB using API provide dby them.

    nordicapis.com/.../

    I need the code to use the key

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans