-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest.php
More file actions
27 lines (22 loc) · 765 Bytes
/
Copy pathtest.php
File metadata and controls
27 lines (22 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
/**
* A basic example of creating a 1CRM client script using .env
*/
use OneCRM\APIClient\Authentication\Basic;
use OneCRM\APIClient\Client;
use OneCRM\APIClient\Error as OneCRMError;
require 'vendor/autoload.php';
//Load environment vars, checks in current dir for a .env file
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
//Set up a client
$auth = new Basic($_ENV['ONECRM_USERNAME'], $_ENV['ONECRM_PASSWORD']);
$client = new Client($_ENV['ONECRM_ENDPOINT'], $auth);
//Call an API endpoint
try {
echo json_encode($client->me(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);
} catch (JsonException $e) {
echo 'Invalid JSON response: ', $e->getMessage();
} catch (OneCRMError $e) {
echo '1CRM error: ', $e->getMessage();
}