NAV 2009 SP1 - GET data from an API using 'Microsoft XML, v6.0'.XMLHTTP60

Please would someone be able to help point me in the right direction with this?
I am using NAV 2009 SP1 but need to GET data from an API using 'Microsoft XML, v6.0'.XMLHTTP60
The API also needs an API Key to be used and this key has been made available to me.
So far I have a codeunit which has the following global variables.

Name DataType Subtype Length
xmlHttpReq Automation 'Microsoft XML, v6.0'.XMLHTTP60
locautXmlDoc Automation 'Microsoft XML, v6.0'.DOMDocument60
XMLNode Automation 'Microsoft XML, v6.0'.IXMLDOMNode

In the codeunit I have the following code which is supposed to get the data from the API and collect the data as an XML file to be saved in a folder. It is difficult to tell whether or not any of it is working. I have used the Postman application to check the URL and it does reach the customer's API, but it cannot get through security. The codeunit runs but there is no data in the file which gets created. Also it is not clear to me whether or not the username and password parameters of the GET Action can be the inserted as I have done it, using the shop ID and the API Key. I suspect that these have to be passed through in another way?


CREATE(xmlHttpReq);'GET', '', FALSE, [Shop-ID], [APIKey]);


Any feedback on this would be very welcome indeed.
Many thanks.


  • ftorneroftornero Posts: 274Member
    Hello @robwalker425 ,

    You could test the conection with an external tool like Postman ( to see if it works, and in the other hand you should call xmlHttpReq.send after, even with a empty string like this
  • robwalker425robwalker425 Posts: 2Member
    Hi ftornero
    Really appreciate your response!
    Yes, I have tried to connect with Postman and it does work. Originally there was an issue with the API Key and other parameters which had to be set but this has been resolved and a file can be got. The Header data that had to be added are these:
    'Authorization','[our API KEY]'
    From NAV, you are right about the SEND call too and that has been added. Thanks.
    So now I can send the GET request and I get a response with a file but I still get an 'Not Authrorized' reply back. I also get an XML file which includes the error message and that is saved as requested as 'C:\temp\Output.xml'.
    So the new code is as follows:
    IF ISCLEAR(locautXmlDoc) THEN
    IF ISCLEAR(xmlHttpReq) THEN
    //'GET', '', //FALSE, [Shop-ID], [APIKey]);'GET', '');
    xmlHttpReq.setRequestHeader('Authorization','[API Key]');
    Do you think the setRequestHeader in NAV should work like this to pass through the header information which was needed in Postman or should it be included somewhere in the original input.xml file which is sent? I have tried so many different possibilities that I do not know what else to try.....
    Your feedback would be truly appreciated.
  • ftorneroftornero Posts: 274Member
    Hello @robwalker425 .

    Yes, the setRequestHeader works in NAV like this.

    Could you try to do a new test after comment the second Authorization line, looks like is redundant.

Sign In or Register to comment.