Download the PHP package shayand/api-library without Composer
On this page you can find all versions of the php package shayand/api-library. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package api-library
Using the NextLead API Library
Requirements
- PHP 5.3.7 or newer
- cURL support
Shayand Setup
The API must be enabled in NextLead. Within NextLead, go to the Configuration page (located in the Settings menu) and under API Settings enable NextLead's API. If you intend on using Basic Authentication, ensure you enable it. You can also choose which OAuth protocol to use here. After saving the configuration, go to the API Credentials page (located in the Settings menu) and create a new client. Enter the callback/redirect URI that the request will be sent from. Click Apply then copy the Client ID and Client Secret to the application that will be using the API.
Authorization
Obtaining an access token
The first step is to obtain authorization. NextLead supports OAuth 1.0a and OAuth 2 however it is up to the administrator to decide which is enabled. Thus it is best to have a configuration option within your project for the administrator to choose what method should be used by your code.
Using Basic Authentication Instead
Instead of messing around with OAuth, you may simply elect to use BasicAuth instead.
Here is the BasicAuth version of the code above.
Note: If the credentials are incorrect an error response will be returned.
API Requests
Now that you have an access token and the auth object, you can make API requests. The API is broken down into contexts.
Get a context object
Supported contexts are currently:
See the developer documentation.
Retrieving items
All of the above contexts support the following functions for retrieving items:
Creating an item
Editing an item
Deleting an item
Error handling
Unit tests
Configure the unit tests config before running the unit tests. The tests fire real API requests to a NextLead instance.
- Copy
/tests/local.config.php.dist
to/tests/local.config.php
. - Open the API tester in the browser like http://localhost/api-library/apitester/index.php
- Fill in the URL of your NextLead instance.
- Click Submit to store the URL to the session.
- Fill in one of the OAuth credentials and authorize.
- Open the $_SESSION array and copy the 'access_token' to the local.config.php file.
- Then run
vendor/bin/phpunit
to run the tests.
Modify this command to run a specific test: vendor/bin/phpunit --filter testCreateGetAndDelete tests/Api/NotesTest.php
Modify this command to run all tests in one class: vendor/bin/phpunit --filter test tests/Api/NotesTest.php