Announcement

Collapse
No announcement yet.

How get authentication token using API

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How get authentication token using API

    Hi,

    I'm using the client API for PHP suggested at https://docs.espocrm.com/development/api-client-php/

    I'm already using basic authentication (username and password), and I'm able to validate data and I can see the authentication token as a cookie.

    Now my question is: Is this autentication token that I need to use with the authentication method described into the documentation?

    "Espo-Authorization: " + base64Encode(username + ':' + passwordOrToken)
    Thanks
    Last edited by eduardofendrich; 10-27-2021, 04:03 PM.

  • #2
    Hi,

    I think you need to create an API user and use the API key instead to connect to espocrm.

    $client = new EspoApiClient('https://your-espocrm-site');

    $client->setApiKey('API_KEY');

    The API key will be generated once you create the API user then you can use the API key to connect. Also make sure to give the API user the role to access scopes which you want to manipulate.

    See the video from one of the developer in the community https://www.youtube.com/watch?v=j6NZ41Uj7R8

    Hope this help

    Cheers,

    Comment


    • eduardofendrich
      eduardofendrich commented
      Editing a comment
      I can't use an API key. I need to connect by username+password and make calls to Espo...

  • #3

    Comment


    • eduardofendrich
      eduardofendrich commented
      Editing a comment
      I've tried... When I run

      $client = new EspoApiClient('http://mysite/espocrm');
      $client->setUserName($user);
      $client->setPassword($password);

      $response = $client->request('GET', 'App/user', []);
      $myToken = $response["token"];

      $myToken has a blank value. I get other values (name, surname, email, telephone, acl data, preferences, etc)

      (I'm connecting with an admin account, so I have all the permissions)
      Last edited by eduardofendrich; 10-27-2021, 05:27 PM.

  • #4
    Any idea why $response["token"] is returning null?

    Comment

    Working...
    X