Post

2 followers Follow
0
Avatar

REST API Error

Hello,

I am following the guide for accessing the clarizen API. https://success.clarizen.com/hc/en-us/articles/205711828-16-13-REST-API-Guide-Version-2#authentication

Unfortunately I am receiving the following error while trying to authenticate: 
{"errorCode":"FileNotFound","message":"File not found: V2.0/services.","referenceId":"2iPRWfmd4Z7kJ9I64GCwJD"}

The API URL I received for the getServerDefintion request is this: 
serverLocation : https://apie1.clarizen.com/v2.0/services 
appLocation : https://eu1.clarizen.com/Clarizen 
organizationId : 0

If I try to access the url https://apie1.clarizen.com/v2.0/services from the browser I also get the "File not found" Error message.

This seems like a general error in your system or am I doing something wrong? I have attached the code I use to access the API.

# general parameters
$Authentication = @{
userName = "thomas.eitler@learnchamp.com"
Password = "********"
}
# get correct api server url
$baseURL = "https://api.clarizen.com"
$getServerDefinitionURI = ($baseURL+"/V2.0/services/authentication/getServerDefinition")

$getServerDefinitionPayload = $Authentication


Try{
$Response = Invoke-WebRequest -Method Post -Uri $getServerDefinitionURI -Body (ConvertTo-Json $getServerDefinitionPayload) -ContentType "application/json" -ErrorAction Stop
}
Catch {
Write-Warning (convertfrom-json $_).errorCode
Write-Warning (convertfrom-json $_).message
}
Finally{
If($Response.statuscode){
Write-Host $Response.statuscode
}
}

$LCAPI_BASEURL = (convertfrom-json $Response.Content).serverlocation

# Authenticate against our api server
$loginURI = $LCAPI_BASEURL+"/V2.0/services/authentication/login"
$loginPayload = $Authentication

Try{
$Response = Invoke-WebRequest -Method Post -Uri $loginURI -Body (ConvertTo-Json $loginPayload) -ContentType "application/json" -ErrorAction Stop
}
Catch {
Write-Warning (convertfrom-json $_).errorCode
Write-Warning (convertfrom-json $_).message
}
Finally{
If($Response.statuscode){
Write-Host $Response.statuscode
}
}

echo (convertfrom-json $Response.Content) | fl *

 

 

Thank you for any advice!

Regards,
Thomas

Thomas Eitler Answered

Please sign in to leave a comment.

2 comments

0
Avatar

Hi Elad,

thank you for pointing me in the right direction.

My error was that the serverlocation returned by getServerDefinition already includes v2.0/services. So the following had to be changed:

$loginURI = ($LCAPI_BASEURL+"/V2.0/services/authentication/login")

should be

$loginURI = ($LCAPI_BASEURL+"/authentication/login")

 

Authentication now works!

Thank you!

 

Thomas Eitler 0 votes
Comment actions Permalink