X++ code to call REST API and get response
This code will help you to make get request to an API and gets response.
class BASRetailCommonWebAPIJob
{
public static void main(Args _args)
{
System.Exception ex;
try
{
RetailWebRequest webRequest;
RetailWebResponse response;
RetailCommonWebAPI webApi;
str rawResponse, ref;
Map responseData;
webApi = RetailCommonWebAPI::construct();
//URL to get data
str tenantId = xInfo::serialNo();
webRequest = RetailWebRequest::newUrl(@"URL="+tenantId);
webRequest.parmMethod("GET");
response = webApi.getResponse(webRequest);
if(response.parmHttpStatus() != 200)
{
throw error("No data is returned");
}
rawResponse = substr(response.parmData(),2,(strlen(response.parmData())-2));
Info(rawResponse);
}
catch
{
ex = CLRInterop::getLastException().GetBaseException();
error(ex.get_Message());
}
}
}