This project has moved and is read-only. For the latest updates, please go here.

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

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

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):

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 = ''
$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 '' -Headers $Headers

Thanks in advance,

Jan 9 at 3:11 PM
Edited Jan 10 at 5: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
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
Feb 3 at 9:41 AM

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.