Giter Site home page Giter Site logo

zendesk_api_client_php's Introduction

Zendesk PHP API Client Library

CI Latest Stable Version Total Downloads Code Climate License

API Client Version

This is the second version of our PHP API client. The previous version of the API client can be found on the v1 branch.

API version support

This client only supports Zendesk's API v2. Please see our API documentation for more information.

Requirements

  • PHP 7.4+

Installation

The Zendesk PHP API client can be installed using Composer.

Composer

To install run composer require zendesk/zendesk_api_client_php

Upgrading from V1 to V2

If you are upgrading from v1 of the client, we've written an upgrade guide to highlight some of the key differences.

Configuration

Configuration is done through an instance of Zendesk\API\HttpClient. The block is mandatory and if not passed, an error will be thrown.

// load Composer
require 'vendor/autoload.php';

use Zendesk\API\HttpClient as ZendeskAPI;

$subdomain = "subdomain";
$username  = "[email protected]"; // replace this with your registered email
$token     = "6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv"; // replace this with your token

$client = new ZendeskAPI($subdomain);
$client->setAuth('basic', ['username' => $username, 'token' => $token]);

Usage

Basic Operations

// Get all tickets
$tickets = $client->tickets()->findAll();
print_r($tickets);

// Get all tickets regarding a specific user.
$tickets = $client->users($requesterId)->tickets()->requested();
print_r($tickets);

// Create a new ticket
$newTicket = $client->tickets()->create([
    'subject'  => 'The quick brown fox jumps over the lazy dog',
    'comment'  => [
        '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 a ticket
$client->tickets()->update(123,[
    'priority' => 'high'
]);

// Delete a ticket
$client->tickets()->delete(123);

// Get all users
$users = $client->users()->findAll();
print_r($users);

Attachments

$attachment = $client->attachments()->upload([
    'file' => getcwd().'/tests/assets/UK.png',
    'type' => 'image/png',
    'name' => 'UK.png' // Optional parameter, will default to filename.ext
]);

Attaching files to comments

$ticket = $client->tickets()->create([
    'subject' => 'The quick brown fox jumps over the lazy dog',
    'comment' => [
        'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' .
                  'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
        'uploads'   => [$attachment->upload->token]
    ]
]);

Side-loading

Side-loading allows you to retrieve related records as part of a single request. See [the documentation] for more information. (https://developer.zendesk.com/rest_api/docs/core/side_loading).

An example of sideloading with the client is shown below.

$tickets = $client->tickets()->sideload(['users', 'groups'])->findAll();

Pagination

Methods like findAll() call the API without any pagination parameter. If an endpoint supports pagination, only the first page will be returned. To fetch all resources, you need to make multiple API calls.

Iterator (recommended)

The use of the correct type of pagination is encapsulated using an iterator, which allows you to retrieve all resources in all pages, making multiple API calls, without having to worry about pagination at all:

$iterator = $client->tickets()->iterator();

foreach ($iterator as $ticket) {
    echo($ticket->id . " ");
}

If you want a specific sort order, please refer to the sorting section in the documentation (Tickets, for example).

Iterator with params example
$params = ['my' => 'param1', 'extra' => 'param2'];
$iterator = $client->tickets()->iterator($params);

foreach ($iterator as $ticket) {
    echo($ticket->id . " ");
}
  • Change page size with: $params = ['page[size]' => 5];
  • Change sorting with: $params = ['sort' => '-updated_at'];
    • Refer to the docs for details, including allowed sort fields
  • Combine everything: $params = ['page[size]' => 2, 'sort' => 'updated_at', 'extra' => 'param'];

Note:

  • Refer to the documentation for the correct params for sorting with the pagination type you're using
  • The helper method iterator_to_array doesn't work with this implementation
Iterator API call response

The latest response is exposed in the iterator at $iterator->latestResponse(). This could come handy for debugging.

Custom iterators

If you want to use the iterator for custom methods, as opposed to the default findAll(), you can create an iterator for your collection:

$strategy = new CbpStrategy( // Or ObpStrategy or SinglePageStrategy
    "resources_key", // The root key with resources in the response, usually plural and in underscore
    [], // Extra params for your call
);
$iterator = PaginationIterator($client->tickets(), $strategy);
foreach ($ticketsIterator as $ticket) {
    // Use as normal
}

This can be useful for filter endpoints like active automations. However, in this common case where you only need to change the method from findAll() to findActive() there's a better shortcut:

$iterator = $client->automations()->iterator($params, 'findActive');

Which is analogous to:

use Zendesk\API\Traits\Utility\Pagination\PaginationIterator;
use Zendesk\API\Traits\Utility\Pagination\CbpStrategy;
$strategy = new CbpStrategy('automations', $params);
$iterator = new PaginationIterator(
    $client->automations(),
    $strategy,
    'findActive'
);

See how the Pagination Trait is used if you need more custom implementations.

Catching API errors

This doesn't change too much:

try {
    foreach ($iterator as $ticket) {
        // your code
    }
} catch (ApiResponseException $e) {
    $errorMessage = $e->getMessage();
    $errorDetails = $e=>getErrorDetails();
}

If you need to know at what point you got the error, you can store the required information inside the loop in your code.

FindAll using CBP (fine)

If you still want use findAll(), until CBP becomes the default API response, you must explicitly request CBP responses by using the param page[size].

// CBP: /path?page[size]=100
$response = $client->tickets()->findAll(['page[size]' => 100]);
process($response->tickets); // Your implementation
do {
    if ($response->meta->has_more) {
        // CBP: /path?page[after]=cursor
        $response = $client->tickets()->findAll(['page[after]' => $response->meta->after_cursor]);
        process($response->tickets);
    }
} while ($response->meta->has_more);

Process data immediately upon fetching. This optimizes memory usage, enables real-time processing, and helps adhere to API rate limits, enhancing efficiency and user experience.

Find All using OBP (only recommended if the endpoint doesn't support CBP)

If CBP is not available, this is how you can fetch one page at a time:

$pageSize = 100;
$pageNumber = 1;
do {
    // OBP: /path?per_page=100&page=2
    $response = $client->tickets()->findAll(['per_page' => $pageSize, 'page' => $pageNumber]);
    process($response->tickets); // Your implementation
    $pageNumber++;
} while (count($response->tickets) == $pageSize);

Process data immediately upon fetching. This optimizes memory usage, enables real-time processing, and helps adhere to API rate limits, enhancing efficiency and user experience.

Retrying Requests

Add the RetryHandler middleware on the HandlerStack of your GuzzleHttp\Client instance. By default Zendesk\Api\HttpClient retries:

  • timeout requests
  • those that throw Psr\Http\Message\RequestInterface\ConnectException:class
  • and those that throw Psr\Http\Message\RequestInterface\RequestException:class that are identified as ssl issue.

Available options

Options are passed on RetryHandler as an array of values.

  • max = 2 limit of retries
  • interval = 300 base delay between retries in milliseconds
  • max_interval = 20000 maximum delay value
  • backoff_factor = 1 backoff factor
  • exceptions = [ConnectException::class] Exceptions to retry without checking retry_if
  • retry_if = null callable function that can decide whether to retry the request or not

Contributing

Pull Requests are always welcome but before you send one please read our contribution guidelines. It would speed up the process and would make sure that everybody follows the community's standard.

Debugging

REPL

To help would be contributors, we've added a REPL tool. It is a simple wrapper for psysh and symfony's console. On your terminal, run bin/console <subdomain> <email> <api token>. This would automatically create an instance of Zendesk\API\HttpClient on $client variable. After that you would be able to enter any valid php statement. The goal of the tool is to speed up the process in which developers can experiment on the code base.

HTTP client print API calls

You can print a line with details about every API call with:

$client = new ZendeskAPI($subdomain);
$client->log_api_calls = true;

HTTP client debug

You can inspect this object for info about requests and responses:

$client->getDebug();

Copyright and license

Copyright 2013-present Zendesk

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

zendesk_api_client_php's People

Contributors

7ail avatar andreionut avatar armen avatar atroche avatar bdav24 avatar buheryfi avatar chrisminett avatar cmourizard avatar devarispbrown avatar dpawluk avatar dqneo avatar ecoologic avatar ggrossman avatar ghermans avatar jaydiablo avatar jmramos02 avatar joseconsador avatar kcasas avatar lobaster avatar manted avatar maximeprades avatar mikealmond avatar miogalang avatar nogates avatar samgavinio avatar shanitang avatar shershennm avatar thekindofme avatar themelter avatar yoshdog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zendesk_api_client_php's Issues

It doesn't work

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.

How to get reason why ticket creation fails?

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?

Recommend an other verison than dev-master

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

Open call for feedback

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:

  • Better exception handling (thanks @shehi and @ocke)
  • Better unit test coverage (thanks @ggrossman)
  • Full support for all endpoints in the core API
  • Higher code quality in general (using static analysis, if possible)
  • A consistent interface for resources (i.e. the constructors, getters, setters, etc. should all work the same whether you're working with apps, tickets or anything else)
  • More information in the README about what the library can do, and how to use it

Anything else you'd like to mention? Now's a good time =)

@mtibben @jurajseffer @andreionut @bvarent @ha-quidco @miogalang @jwswj @mmolina

oAuth Bad Request

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

PHP Fatal Error: Call to a member function getReasonPhrase() on a non-object

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

Error completing request [url]

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.

Regarding new ticket creation

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.

Users->findAll() bug found

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'])

Fatal error: Class 'Zendesk\API\Client' not found

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

SSL peer verification disabled in Http.php

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.

Make release tag

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!

Filter and search request

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!

Errors with $client->tickets()->create($ticket);

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.

Http-basic authentication does not work.

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.

XML Return

You can return the XML data with the REST API?

Unit tests written for specific zendesk instance.

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.

Update README to latest Zendesk client API

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.

Add requester name & email to tickets()->create

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 tried to add 'name', 'email', 'requester' to the array but same result

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!

findAll itertation is not working in PHP API

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();

Make the API for IDE friendly.

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! :)

zendesk_api_client_php

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

$tickets = $client->tickets()->findAll();

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?

HC API missing

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

Zendesk Voice API support

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.

API's grandiose exception handling problem!

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!

Multiple Attachments?

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?

Possible XSS and Information disclosure in Http::send

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.

Undefined property: Zendesk\API\Resources\Core\Search::$results

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?

Add support to make calls via a proxy server

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

Class not found error

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.

Am I missing something

The example doesn't work, there is no vendor/autoload and i can't get access to methods

Attachments are skewed when they arrive in ZenDesk

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.

Retrieve tickets requested by a user

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.

User Search via external_id no longer working

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 (

public static function prepareQueryParams(array $sideload = null, array $iterators = null)
{
$addParams = [];
// First look for side-loaded variables
if (is_array($sideload)) {
$addParams['include'] = implode(',', $sideload);
}
// Next look for special collection iterators
if (is_array($iterators)) {
foreach ($iterators as $k => $v) {
if (in_array($k, ['per_page', 'page', 'sort_order', 'sort_by'])) {
$addParams[$k] = $v;
}
}
}
return $addParams;
}
) and the code in Users->search (
$queryParams = isset($params['query']) ? ['query' => $params['query']] : [];
$extraParams = Http::prepareQueryParams($this->client->getSideload($params), $params);
) and as such are stripping out the 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.

open_basedir & CURLOPT_FOLLOWLOCATION

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

Help Center API?

When can we expect the HC API to be added to the PHP API Client?
Many thanks!

Importing tickets fails when importing a ticket with multiple comments

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.

Error completing request [url] https://betalabs.zendesk.com/api/v2/tickets.json [http method] GET

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.