janhenkes / teamleader-php-sdk

Teamleader API v2 PHP SDK
MIT License
16 stars 25 forks source link

Fatal Error on access token #29

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hi,

I'm trying to make a script to send datas from a website form to teamleader. But when i test your sdk, it return me an error :

Fatal error: Uncaught Teamleader\Exceptions\InvalidAccessTokenException: Invalid access token, please acquire a new one. in C:\laragon\www\APITL\vendor\janhenkes\teamleader-php-sdk\src\Teamleader\Connection.php:322 Stack trace: #0 C:\laragon\www\APITL\vendor\janhenkes\teamleader-php-sdk\src\Teamleader\Connection.php(398): Teamleader\Connection->createRequest('POST', 'https://api.tea...', '{"first_name":"...') #1 C:\laragon\www\APITL\vendor\janhenkes\teamleader-php-sdk\src\Teamleader\Actions\Storable.php(34): Teamleader\Connection->post('contacts.add', '{"first_name":"...') #2 C:\laragon\www\APITL\vendor\janhenkes\teamleader-php-sdk\src\Teamleader\Actions\Storable.php(20): Teamleader\Entities\CRM\Contact->insert() #3 C:\laragon\www\APITL\SDK.php(19): Teamleader\Entities\CRM\Contact->save() #4 {main} thrown in C:\laragon\www\APITL\vendor\janhenkes\teamleader-php-sdk\src\Teamleader\Connection.php on line 322

This error come with your "addClient" example

janhenkes commented 4 years ago

Hi Jeremy,

You have to register your integration first at the Teamleader Marketplace as described in the Readme: Teamleader API v2 works with OAuth2. This means your application needs to be registered on the Teamleader Marketplace (you can keep them private though).

Please also read this: https://developer.teamleader.eu/#/introduction/authentication

You can register your integration here: https://marketplace.teamleader.eu/nl/en/build/integrations

ghost commented 4 years ago

Hi,

The thing is, i've already registered the application before sending the new client information that's why i'm asking you where i make an error :D

janhenkes commented 4 years ago

I am guessing you are using this example? Can you please confirm you did the following:

  1. You created a file "credentials.php" and stored the client Id and client secret in there, like so:
    <?php
    $clientId     = 'your-client-id';
    $clientSecret = 'your-client-secret';
  2. You did set up a local dev environment with the URL "teamleader-php-sdk.test" and an SSL certificate (with XAMPP or so)
  3. Go to https://teamleader-php-sdk.test/examples/acquire-access-token.php in your browser, you should be redirected to the Teamleader login page
  4. Log in in Teamleader, you should now redirect back to https://teamleader-php-sdk.test/examples/acquire-access-token.php
  5. Now try to run your first script again

Please let me know if this helps. Of course, this is the example code. In your real application you should integrate the acquiring access token flow in your application.

ghost commented 4 years ago

Hi !

I'm using this example : https://github.com/janhenkes/teamleader-php-sdk/blob/master/examples/add-contact.php

I will answer in the same order as you did for your questions :

  1. Yes i have a credentials.php file with my client id and my client secret

  2. I'm working on a local environment, i'm using "teamleader-php-sdk.me" as url name. SSL is activated.

I don't know where i made a mistake but it's working now so, THANK YOU really a big THANK YOU for your help !

janhenkes commented 4 years ago

NP :-)