Error occurred: Status code received was Unauthorized, i.e. Unauthorized

Topics: Bug / Problems
Dec 13, 2016 at 7:40 AM
Edited Dec 13, 2016 at 7:43 AM
Hello,

I am configuring the JSON Source Component, but when clicking test, i get the following error:
Error occurred: Status code received was Unauthorized, i.e. Unauthorized.

I suppose i has something to do with the use of required token, I don't know exactly how to configure it with Http headers or parameters.

The URL for calling the connector is (fake example company number):
https://12345.afasonlineconnector.nl/profitrestservices/metainfo/get/ARISYS_Personen

And the service provider has the following sample code on their website, but I don't know how to use this in the JSON Source component headers / parameters:

These examples are made with Windows Powershell by the service provider. When calling the token it has to be converted to a base64-string.

Calling the Get-rest service:

$token= '<token><version>1</version><data>0E6824699F40129E254DB96441233E32F13454355184E5A24F8E3C0DFA4F</data></token>'
$encodedToken = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($token))
$authValue = "AfasToken $encodedToken"
$Headers = @{
Authorization = $authValue
}
$url = 'https://nltqs1pas01.afasgroep.nl/Profitrestservices/connectors/Profit_Article'
$file = '\nltqfs01\Testteam\TestSet\2011.1\Algemeen\SCRIPT\Connectoren\CONNECTOREN_JSON\Output\Getconnector.json'
Invoke-WebRequest -Uri $url -OutFile $file -Headers $Headers



Load Meta-info:

$token= '<token><version>1</version><data>0E6824612043AA9E254DB961223DD33E32F14943D93184E5A234553C0DFA4F</data></token>'
$encodedToken = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($token))
$authValue = "AfasToken $encodedToken"
$Headers = @{
Authorization = $authValue
}
Invoke-WebRequest -Uri 'https://nltqs1pas01.afasgroep.nl/Profitrestservices//metainfo' -Headers $Headers

Thanks in advance,

Hennie
Jan 9 at 2:11 PM
Edited Jan 10 at 4:36 PM
Hi Hennie,

Been there. This is not all straight-forward/self-explaining.

1) base64-encode the token; then get the string-data from it (just as they do in the MS-PowerShell-script) . I've done this for your examplestring; this way you can also verify if this part is correct :-)

2) Enter the data behind the "Header"-button (mind the space between AfasToken and the token)
Name = Authorization
Binding = CustomValue
Value = AfasToken PHRva2VuPjx2ZXJzaW9uPjE8L3ZlcnNpb24+PGRhdGE+MEU2ODI0Njk5RjQwMTI5RTI1NERCOTY0NDEyMzNFMzJGMTM0NTQzNTUxODRFNUEyNEY4RTNDMERGQTRGPC9kYXRhPjwvdG9rZW4+
URLEncode = 0
This worked for me; next is processing the response.

The json-object is "enriched" with meta-data information.
I have no idea how to tackle this. If I understand correctly; the relevant JSON-object is contained within the square-brackets and could be picked up "automagically"....hopefully :-)
The returned data OK on json-syntax (as far as I get JSON)
I have no idea how to get around this using JSONsource; the afas website also had no information on a possible parameter which cuts down the response to a basic json-object. I can not imagine AFAS would think about supporting such an option as it is a sane thing to inform what is actually in the response. It could be about the day after tomorrows weather.
Downloaded: {
  "skip": 0,
  "take": 100000,
  "rows": [
   {
      "Werkgever": "01",
      ...
   }
 ]
 } 
Good luck & thanks for the nice tool
Coordinator
Feb 3 at 8:41 AM
Hi,

getting out the info from the square brackets takes no effort at all. You just have to specify the Root Array Path parameter, which will be "rows". Then, for each object's attribute, specify the relavite column, such as "Werkgever", etc. I tried using the webservice, but it seems to be down at the moment, so I cannot help.

A.