AddQueueItem from a VBscript gives authentication error

Hi,

Im writing a vbscript that should create QueueItems. I got it working using Postman, but Im unable to make it work in my script.

I successfully retrieve the “access_token” using POST https://account.uipath.com/oauth/token and store the token in the variable access_token

I then make another call using POST https://platform.uipath.com/odata/Queues/UiPathODataSvc.AddQueueItem , which fails and this part looks like this:

jsonData2 = “{ ““itemData””: {”“Name”": ““Queue””, ““Priority””: ““Normal””, ““SpecificContent””: { ““Name””: ““Solan Gundersen””, ““Age””: 54 }}}"
Set HTTP2 = CreateObject(“MSXML2.ServerXMLHTTP”)
HTTP2.Open “POST”, url2, False
HTTP2.setRequestHeader “Content-Type”, “application/json”
HTTP2.setRequestHeader “Authorization”, “Bearer " & access_token
HTTP2.setRequestHeader “X-UIPATH-TenantName”, “”” & tenant_logical_name & “”"
HTTP2.setRequestHeader “X-UIPATH-OrganizationUnitId”, “12345”
HTTP2.send jsonData2
msgbox "Status code: " & HTTP2.status & " Response: " & HTTP2.responseText’

I just get a 401-error - “You are not authenticated!”

The Json-string might be wrong, but I should get a 400-error when the json-string is wrong, but the authentication is correct.

Are there anyone that can see what I`m doing wrong?

I got it working, changing the following lines:
HTTP2.setRequestHeader “X-UIPATH-OrganizationUnitId”, “” & OrganizationUnitId & “”
HTTP2.setRequestHeader “Authorization”, "Bearer " & access_token & “”

The reason for my error was probably something with the X-UIPATH-OrganizationUnitID (or both), which confused me because I was certain that it was the access_token that were wrong. Either way, by eliminating each line I was able to make it work.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.