/** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. */ protected function setUp() { $this->client = new HttpClient($this->subdomain, $this->username, $this->scheme, $this->hostname, $this->port); $authOptions['username'] = $this->username; if ($this->authStrategy === 'basic') { $authOptions['token'] = $this->token; } else { $authOptions['token'] = $this->oAuthToken; } $this->client->setAuth($this->authStrategy, $authOptions); }
/** * Create service * * @param ServiceLocatorInterface $serviceLocator * @return Client */ public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Configuration'); $client = new Client($config['zendesk']['subdomain'], $config['zendesk']['username']); $client->setAuth('basic', ['username' => $config['zendesk']['username'], 'token' => $config['zendesk']['token']]); return $client; }
/** * Register the service provider. */ public function register() { $this->app->bind('zendesk', function () { $client = new ZendeskAPI($this->app['config']->get('services.zendesk.subdomain'), $this->app['config']->get('services.zendesk.username')); $client->setAuth('basic', array('username' => $this->app['config']->get('services.zendesk.username'), 'token' => $this->app['config']->get('services.zendesk.token'))); return $client; }); }
<?php include "../../vendor/autoload.php"; use Zendesk\API\HttpClient as ZendeskAPI; /** * Replace the following with your own. */ $subdomain = "subdomain"; $username = "******"; $token = "6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv"; $client = new ZendeskAPI($subdomain); $client->setAuth('basic', ['username' => $username, 'token' => $token]); try { $query = $client->groups()->findAll(); foreach ($query as $UserData) { echo "<pre>"; print_r($UserData); echo "</pre>"; } } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { echo 'Please check your credentials. Make sure to change the $subdomain, $username, and $token variables in this file.'; }
/** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. */ protected function setUp() { $this->client = new HttpClient($this->subdomain, $this->username, $this->scheme, $this->hostname, $this->port); $this->client->setAuth('oauth', ['token' => $this->oAuthToken]); }
<?php include "vendor/autoload.php"; use Zendesk\API\HttpClient as ZendeskAPI; $subdomain = "subdomain"; $username = "******"; $token = "6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv"; // replace this with your token //$password = "******"; $client = new ZendeskAPI($subdomain, $username); $client->setAuth('token', $token); // set either token or password // Get all tickets $tickets = $client->tickets()->findAll(); print_r($tickets); // Create a new ticket $newTicket = $client->tickets()->create(array('subject' => 'The quick brown fox jumps over the lazy dog', 'comment' => array('body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'), 'priority' => 'normal')); print_r($newTicket); // Update multiple tickets $client->ticket(array(123, 456))->update(array('status' => 'urgent')); // Delete a ticket $client->ticket(123)->delete();