Menu

Token login to API

2024-03-08
2024-03-13
  • Niclas Eriksson

    Niclas Eriksson - 2024-03-08

    I've created a application token in iTop and given it the Rest services user profile. Then I added this config:

        'allow_rest_services_via_tokens' => true,
    

    adn added token in allowedlogintypes

    Is there something else I need to do? I get "Invalid login" when try connecting to the URL
    https://myitopurl/ webservices/rest.php

     
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2024-03-08

    Did you also add other permissions/profiles?
    Not sure if there's more extensive debugging you could enable.

     
    • Niclas Eriksson

      Niclas Eriksson - 2024-03-11

      I've added the admin role as well. No change I'm affraid. Is there any logs I can look into?

       
  • Lari

    Lari - 2024-03-13

    I've not used the authentication by token extension myself, but regarding using REST - I think you may have missed one important thing. That is:
    "As any User, it requires REST Services profile to access the REST API"

    So check that your user has "REST Service User" priviledge. Admin role is not enough, maybe not even needed. And also if you plan to modify tickets, you will probably need Support Agent + Service Desk Agent.

     
  • Niclas Eriksson

    Niclas Eriksson - 2024-03-13

    That role is already present, forgot to mention that. Still no luck I'm afraid. Is there a logfile I can look in to investigate? If so, where is that located?

     
  • Guillaume Lajarige

    Hello Niclas,

    Try to put "token" first in the "allowedlogintypes" parameter

     
  • Guillaume Lajarige

    If it doesn't work, paste a screenshot of the config please.

     
  • Niclas Eriksson

    Niclas Eriksson - 2024-03-13

    I now actually think I see my problem. It seems like the tests I've done using curl had some from formating.. I did:
    curl -X POST -F 'version=1.3' -F 'auth_token=xxxxxx' and that failed with Invalid login, but when I did with "-quotes instead it seems to go further giving me some other errorcode due to json formating.. and if I type the wrong token info it fails so I think it's good now. Just need to figure out whats wrong in my json formating. Thanks for all input!

     
  • Lari

    Lari - 2024-03-13

    Try this:
    curl -k -X POST -F 'version=1.3' -F 'auth_token=YOURTOKEN' -F 'json_data={"operation": "core/get","class": "Person","key": "SELECT Person WHERE email LIKE '\''SOME@EMAIL.COM'\''","output_fields":"friendlyname,email"}' "https://SOMESERVER/itop-xxx/webservices/rest.php"

     
  • Niclas Eriksson

    Niclas Eriksson - 2024-03-13

    I did get it to work using this:

     curl -X POST -F "version=1.3" -F "auth_token=xxxx" https://<url>/rest.php -F "json_data=@./my-json-operation.json"
    

    And the json file contains:

    {
      "operation":"core/get",
      "class":"Person",
      "output_fields":"friendlyname, email",
      "key":"SELECT Person WHERE email LIKE 'niclas@gingby.se'"
    }
    

    So I think I now got it going :)

     
  • Guillaume Lajarige

    Glad to see you fixed it!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.