Home General Discussion

Problem With Using The API's on one of our systems

Stuart_EddyStuart_Eddy Customer IT Monkey ✭
I am having an issue when running the API's on one of our system when running I am getting a 401 error, I have set the calling user as an administrator in service manager is there any other permissions which need to be set?


  • Options
    Geoff_RossGeoff_Ross Cireson Consultant O.G.
    Hey Stuart,

    Hope you are well, long time no speak. You need to call the authorisation API first to get a token, then use the token in subsequent calls. Here's an example in PowerShell.

    # Get token for SMP calls
    $mycreds = @{ UserName = $UserName; Password = $Password; LanguageCode = "ENU"; }
    $jsonCreds = ConvertTo-Json $mycreds
    try { $result = Invoke-WebRequest 'http://localhost/api/V3/Authorization/GetToken' -Method POST -Body $jsonCreds -ContentType 'application/json' } catch { $_.Exception.Response.GetResponseStream() ; exit }
    $apiToken = $result.Content -replace '"(.*)"','$1'
    Invoke-WebRequest 'http://localhost/api/V3/Article/Get' -Headers @{ "Authorization" = 'Token ' + $apiToken }

    See if that helps

  • Options
    Stefan_AllanssonStefan_Allansson Customer IT Monkey ✭


    For how long can you use the Authorization Token when you got it?

    Does it have a limited lifetime?


Sign In or Register to comment.