zendesk / zendesk_api_client_php Goto Github PK
View Code? Open in Web Editor NEWOfficial Zendesk API v2 client library for PHP
Official Zendesk API v2 client library for PHP
I'd like to be able to use this from behind a proxy server. Can we add something like
$curl->setopt(CURLOPT_PROXY, $proxy);
to the Http.php file along with a setProxy function in the Client?
-micah
Hey @maximeprades (and @zendesk/quokka),
I would like to chip into this project as well, but a lot of the unit tests are written in such a way it needs access to a specific (I'm guessing sandedboxy) zendesk instance.
For example this one: ForumsTest.php
It points to $forum = $this->client->forum(22480662)->find(); // don't delete forum #22480662
While you can instead of relying on an existing ticket, move this testFind() function to below the createTest() and use the outcome of that to test the testFind().
You guys have done this for some tests. For example: TargetsTest.php.
Is there a specific reason you guys have written the test like this or can I go ahead, rewrite some of the tests, so that all test will work with any zendesk instance and doesn't rely on certain tickets or forums to exists?
If you guys give me a heads up I will add that functionality and do a PR.
Using composer to include dev-master, when I updated to 52bdc2c, suddenly it causes a Zendesk\API\Client class not found. Changed composer.json to install dev-master#7177ef7 and it's working again.
Here's my code:
$attachment = $zendesk->attachments()->upload(
array(
'file' => $file[0],
'type' => $file[1]
)
);
$token = $attachment->upload->token;
$zendesk->tickets()->create(
array(
'subject' => "Test",
'description' => $description,
'priority' => 'normal'
"comment" => array(
"body" => "Contact Form Attachment",
"uploads" => array($token)
)
));
The file and the ticket is being created correctly in the ZenDesk panel, however, a CSV rendered on the ZenDesk side like this:
------------------------------d57d8e1f7f8d
Content-Disposition: form-data; name="filename"; filename="/path/to/my/website/diretiory/media/contactfiles/file.csv"
Content-Type: application/octet-stream
๏ฟฝ๏ฟฝ"CSV","Columns","1","2"
--------------------------d57d8e1f7f8d--
Where it should appear like this:
"CSV","Columns","1","2"
Images are then not rendered at all; but I think this is because the headers information is breaking the rendering code.
In some places the return annotations simply consist of the word "mixed". In my opinion, should it matter, this isn't enough.
I'm getting this error Fatal error: Call to a member function getReasonPhrase()
I'm working in local system.
Kindly provide me a solution.
Hi, is there any planning for a expantion with the helpcenter api (And maybe Zopim)?
First of all: Thank you for taking the time to make this API.
Being an avid PhpStorm-user, I miss my code-completions. Both for API-calls and the entities returned.
I realize this might make the API-client less maintainable, but ease and comfort of use is also important.
I will be using this client extensively for a web-project in the near-future. I might open a pull-request adding IDE-friendlyness, but I would be very happy if you could give some pointers how to go about it! :)
We have some code written against the v1 client to find users based on our external_id that no longer works (see below)
$result = $this->client->users()->search(array(
'external_id' => sprintf('user-%s', $externalId),
));
Comparing the v1 and v2 code, it appears now that you're whitelisting query params between Http:: prepareQueryParams
(
zendesk_api_client_php/src/Zendesk/API/Http.php
Lines 27 to 45 in 7001882
Users->search
(zendesk_api_client_php/src/Zendesk/API/Resources/Core/Users.php
Lines 221 to 222 in a1b69bc
external_id
from the query params.
For local dev env reasons I've had trouble getting things set up to verify, but I think that when there are no params sent to search it returns anything that matches (everything), or at least that's my hunch because all our tickets lodged by signed in users are getting attached to our oldest user.
Would appreciate if you could confirm/fix, or just close it off if I'm mistaken.
I can not use the composer in my application. Some way to load the api client?
When using the search function, it is not possible to use multiple parameters.
This...
$client->search(array('query'=>'requester:[email protected]+tags:mystuff'));
Sends this to the API...
https://subdomain.zendesk.com/api/v2/search.json?query=requester%3Atester%40me.com%2Btags%3Amystuff
It appears the API wants to see the '+' and not the encoded equivalent '%2B'
Please revamp whole exception handling of the API so that every status code for exception cases are reflected correctly. E.g. instead of having one ResponseException
let's have separate exceptions such as TooManyConnectionsException
, MissingParameterException
etc (and of course have unit-test-case for each exception handled). For every single status code at least. In it's current case, there is no way of managing the flow of code-logic, based upon the result's status code. E.g., it would be awesome to know before hand if one receives TooManyConnectionsException
and upon the exception wait for necessary Retry-time
seconds and try again.
With all due respect, this code needs very good peer-reviewing! It looks as if it was written for the sake of being written!
Hello, I am using the new ticket creation code as follows but it is showing error "Trying to get property of non-object"...Please help.
"Help, my device is off!", "z_description"=>"help I need some help", "z_recipient"=>"[email protected]", "z_name"=>"Jacks Ferro", "z_requester"=>"[email protected]" ); $create = json_encode(array('ticket' => array('subject' => $arr['z_subject'], 'description' => $arr['z_description'], 'requester' => array('name' => $arr['z_name'], 'email' => $arr['z_requester']))), JSON_FORCE_OBJECT); $data = $zendesk->call("/tickets", $create, "GET"); print "hello test".$data->ticket->id; $test = $zendesk->test(); print "\n"; ?>Thanks in advance.
Hello,
You could make some version as release?
This way when using with composer, you could use version instead of "dev-master" and that way prevent "unbound version constraints (dev-master) should be avoided" warning with composer.
Thanks!
when initiating ZendeskAPI object it gives an error
$client = new ZendeskAPI($subdomain, $username);
Here is the error:
Catchable fatal error: Argument 1 passed to Zendesk\API\Search::search() must be an array, object given, called in /Webserver/htdocs/project/vendor/zendesk/zendesk_api_client_php/src/Zendesk/API/Client.php on line 90 and defined in /Webserver/htdocs/project/vendor/zendesk/zendesk_api_client_php/src/Zendesk/API/Search.php on line 13
If I comment $this->search = new Search($this); on the line 90 of the file vendor/zendesk/zendesk_api_client_php/src/Zendesk/API/Client.php it starts to work.
I've installed via Composer and in my php page (in the same directory as the vendor directory) I have copied this and put in my settings:
use Zendesk\API\Client as ZendeskAPI;
$subdomain = "subdomain";
$username = "username";
$token = "6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv"; // replace this with your token
// $password = "123456";
$client = new ZendeskAPI($subdomain, $username);
$client->setAuth('token', $token); // set either token or password
My page is giving the error: Fatal error: Class 'Zendesk\API\Client' not found
For more context, I'm trying to use the library as a plugin to my CMS system, but that shouldn't matter...
I'm using PHP Version 5.5.24...
Are there any troubleshooting steps I could take to help solve this?
Thanks!
Sean
It's not clear how to use this api client to add multiple attachments to a ticket, or if its even possible. My attempts result in only the last file actually getting attached. Has anyone been able to do this and if so do you mind sharing how?
The example doesn't work, there is no vendor/autoload and i can't get access to methods
Finding users with the roles "admin" and "agent" was resulting in a not working link.
zendesk.com/users.json&role[]=agent&role[]=admin
As we can see the link should be :
zendesk.com/users.json?role[]=agent&role[]=admin
Solution:
File: src\Zendesk\API\Users.php
Online: 43
&role[]='.implode('&role[]=', $params['role'])
Should be
?role[]='.implode('&role[]=', $params['role'])
When can we expect the HC API to be added to the PHP API Client?
Many thanks!
In the current dev-master the debug info is automatically printed if the response was >= 400.
The debug info may contain the authorization header, among other things.
Since the LastRequestHeaders is reflected, it is also possible to inject JS code if for instance the id wasn't validated properly in a search request.
[...]
if ($responseCode >= 400) {
print($client->getDebug());
throw new ResponseException(__METHOD__);
}
[...]
https://github.com/zendesk/zendesk_api_client_php/blob/master/src/Zendesk/API/Http.php#L149
v1.2.0 appears to be okay.
I did not check other parts of the code or other versions, though. I currently don't have the time. I just wanted to pass this information quickly.
When trying to create tickets via API, I sometimes get following error:
Response to Zendesk\\API\\Tickets::create is not valid. Call $client->getDebug() for details
However, all I can get from getDebug() is HTTP code:
HTTP/1.1 422 Unprocessable Entity
Looking briefly at the source code, it is not possible to extract exact reason why entity is not valid. Or am I missing something?
Hi,
I'm trying to use the SDK, but I cannot comunicate with zendesk.
I tryed to launch this code:
$client = new ZendeskAPI( $this->zendesk_domain, $this->zendesk_usr );
$client ->setAuth('basic', ['username' => $this->zendesk_usr, 'token' => $this->zendesk_pss ]);
$tickets = $client->tickets()->findAll();
But I receive this error:
Zendesk\API\Exceptions\ApiResponseException : Error completing request [url] https://yithemes1432719252.zendesk.com/api/v2/tickets.json [http method] GET [body]
I'm using the sandbox of zendesk and the email and token are correct, I already checked it.
Why am I having this problem?
Thanks.
Including dev-master feels unstable.
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license. require.doctrine/dbal : unbound version constraints (*) should be avoided require.zendesk/zendesk_api_client_php : unbound version constraints (dev-master) should be avoided
Hi There,
How do I filter the request?
I want to filter tickets creating (greather than) date like:
Ticket create more than 2015-09-01 and less than 2015-10-01;
How can I do that?
$tickets = $zendesk->tickets()->findAll(["created_at" => "2015-09"]);
And the search API is not documented, how do I use it?
There's some documentation to guide me?
I appreciate that!
Filing an issue that changes introduced on May 5 have caused ticket creation to fail when using $client->tickets()->create($ticket);
Here are the error messages:
Warning: fopen({): failed to open stream: No such file or directory in Zendesk\API\Http::send() (line 49 of /vagrant/html/profiles/dosomething/libraries/zendesk/src/Zendesk/API/Http.php).
Warning: filesize(): stat failed for { in Zendesk\API\Http::send() (line 50 of /vagrant/html/profiles/dosomething/libraries/zendesk/src/Zendesk/API/Http.php).
Warning: fread() expects parameter 1 to be resource, boolean given in Zendesk\API\Http::send() (line 51 of /vagrant/html/profiles/dosomething/libraries/zendesk/src/Zendesk/API/Http.php).
Warning: curl_setopt(): supplied argument is not a valid File-Handle resource in Zendesk\API\Http::send() (line 53 of /vagrant/html/profiles/dosomething/libraries/zendesk/src/Zendesk/API/Http.php).
I've confirmed that if I checkout this commit 6aa9662 and run composer install
, tickets will be created without an errors.
Please update the README file to reflect the recent changes to the dev-master
version of the codebase.
In particular the code examples do not reflect the change of Zendesk\API\Client
to Zendesk\API\HttpClient
:
Class 'Zendesk\API\Client' not found
More importantly there is no mention to the fact token
in no longer considered a valid authentication method:
Invalid auth strategy set, please use `basic` or `oauth`
Thanks.
How to retrieve tickets requested by a specific user in Zendesk PHP API Client V2?
In previous version I used this way
$tickets = $client->users($requesterId)->tickets()->findAll()
But in V2 there is no method called tickets available in Zendesk\API\Resources\Core\Users.
There is no reference about it in upgrade guide.
Hello. I don't know if I'm missing it, but where can I get things like Articles? Is there a separate HC API somewhere?
Thanks
You can return the XML data with the REST API?
I am using this api client in a laravel 4.2 project I have the following code:
public function GetClient()
{
$client = new ZendeskAPI($this->zendesk['Subdomain'], $this->zendesk['Username']);
$client->setAuth('basic', ['username' => $this->zendesk['Username'], 'token' => $this->zendesk['Token']]);
return $client;
}
And I use it like this:
$client = $this->GetClient();
$query = 'type:organization name:"'.$zendesk_organisation_name.'"';
$params = array(
'query' => $query
);
$organisations = $client->search($params);
This gives me the following error: Undefined property: Zendesk\API\Resources\Core\Search::$results
I have not been able to track down exactly where or how this error is occurring. This code worked fine before until I recently did a composer update
. Has there been any major breaking changes?
Hi,
After i Load my library directly by downloading from git repositoy.
I get the error as:
Fatal error: Class 'Zendesk\API\Debug' not found in C:\xampp\htdocs\Former\zendesk_api_client\src\Zendesk\API\Client.php on line 240
Hi,
I was looking for using the application upload feature of the API but it seems that the Apps class is not implemented in the Client main class.
Regards,
Ryan.
I am trying the example in oauth.php. I am able to get the authorisation code, but when I get redirected back to exchange the code for the token, I get this error:
HTTP/1.1 400 Bad Request
Hey guys, I've cc'd everyone who's contributed to this repo recently.
@miogalang, @joseconsador and I are about to start a week-long intensive on this project in the Manila office. What do you think we should work on? I've identified a few things so far:
Anything else you'd like to mention? Now's a good time =)
@mtibben @jurajseffer @andreionut @bvarent @ha-quidco @miogalang @jwswj @mmolina
Using 04e31fb we're seeing the following error being thrown inside the Zendesk library:
vendor/zendesk/zendesk_api_client_php/src/Zendesk/API/Exceptions/ApiResponseException.php:22
Call to a member function getReasonPhrase() on a non-object
Given that it's a fatal error occurring inside the library we can't see the context in which this is occuring
Title says it all: is Incremental Ticket API supported by this library? I checked the code thoroughly and couldn't find any sign of it in there. Thanks!
@see https://developer.zendesk.com/rest_api/docs/core/ticket_export
Tried authenticating by username/password, but got the following response: "Couldn't authenticate you". I then tried the url used directly in the browser, and was easily authenticated.
The link to the documentation in the README throws a 404 error.
Hi,
Any specific reason that SSL peer verification is disabled for the API code? This would make it vulnerable to MITM attacks. It looks to me that we should make it always enabled instead.
I have discovered, that parameters set to function findAll were not passed to the API call
current function
/**
* List all users
*
* @param array $params
*
* @throws ResponseException
* @throws \Exception
* @return mixed
*/
public function findAll(array $params = [])
{
if (isset($params['organization_id'])) {
$this->endpoint = "organizations/{$params['organization_id']}/users.json";
} elseif (isset($params['group_id'])) {
$this->endpoint = 'groups/' . $params['group_id'] . '/users.json';
} else {
$this->endpoint = 'users.json';
}
return $this->traitFindAll();
}
should be fixed to:
/**
* List all users
*
* @param array $params
*
* @throws ResponseException
* @throws \Exception
* @return mixed
*/
public function findAll(array $params = [])
{
if (isset($params['organization_id'])) {
$this->endpoint = "organizations/{$params['organization_id']}/users.json";
} elseif (isset($params['group_id'])) {
$this->endpoint = 'groups/' . $params['group_id'] . '/users.json';
} else {
$this->endpoint = 'users.json';
}
return $this->traitFindAll($params);
}
The only change is missing parameter $params in the line:
return $this->traitFindAll();
Very simply not problem with autoload or authentication.
Just trying to get all tickets:
$tickets = $client->tickets()->findAll();
print_r($tickets);
Produces:
PHP Fatal error: Call to a member function getReasonPhrase() on a non-object in /var/www/html/ZD/vendor/zendesk/zendesk_api_client_php/src/Zendesk/API/Exceptions/ApiResponseException.php on line 22
I tried to follow some of the previous reports of similar challenges and I wan unable to find an answer.
Can you provide some insight into what I am doing incorrectly?
If open_basedir is set, PHP issues a warning,
PHP Warning: curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set in [...]/zendesk_api_client_php/src/Zendesk/API/Http.php on line 110
$client->tickets()->comments()->sideload(['users'])->findAll($params) is returning the comments but not the sideloaded users.
Hello,
Is it possible to have the requester name & email when submitting a new ticket?
I have a simple contact form email / message and I get the name in session.
The following code works perfectly (comes from your sample):
$newTicket = $client->tickets()->create(array(
'subject' => 'test subject',
'comment' => array (
'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
),
'priority' => 'normal'
));
How can I add the customer name as requester? Because currently, on Zendesk, the requester is me ($username)
I have a working version with curl method, but experiencing some "self signed certificate" problems on my local machine. So, this is just to know if I can do that with the API client ๐
Thanks!
Importing tickets fails when importing a ticket with multiple comments. Annoyingly the error message is so generic. The error in the end was the author ID was not valid.
I'm assuming that the first comment has a fall back in the code to use the requester_id whereas the subsequent comments do not have a fall back as the comment could be from anyone.
There seems to be no access to the Zendesk Voice API. I am looking for a way to create voice tickets. Can it be done with this client? If yes, how? And if not, what would be the best practice with PHP.
When I utilize the method "tickets()->findAll()" exactly like the example in readme, this exception returns:
Error completing request [url] https://betalabs.zendesk.com/api/v2/tickets.json [http method] GET
My code sample:
$zendesk = new ZendeskAPI($subdominio, $usuario);
$zendesk->setAuth('basic', ['username' => $usuario, 'token' => $senha]);
$tickets = $zendesk->tickets()->findAll();
When I try authenticate with HTTP configurations (with Scheme = "HTTP" AND Port = "80") (because I was making test in my local environment), this exception returns:
Client error response [url] http://betalabs.zendesk.com/api/v2/tickets/recent.json [http method] GET [status code] 400 [reason phrase] Bad Request [details] This is an HTTPS only API
How to proceed?
Waiting for answers,
Victor
Your recent v2.0.* releases are not available via Packagist. You may need to update your packagist github webhook
https://packagist.org/packages/zendesk/zendesk_api_client_php
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.