Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter and search request #217

Closed
rafaelfoster opened this issue Oct 26, 2015 · 9 comments
Closed

Filter and search request #217

rafaelfoster opened this issue Oct 26, 2015 · 9 comments

Comments

@rafaelfoster
Copy link

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!

@RaFeNiX
Copy link

RaFeNiX commented Oct 26, 2015

Hi Rafael, try created_at>2015-01-01

Em 26/10/2015 10:50, Rafael Foster notifications@github.com escreveu:
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-06"]);

And the search API is not documented, how do I use it?
There's some documentation to guide me?

I appreciate that!


Reply to this email directly or view it on GitHub:
#217

@rafaelfoster
Copy link
Author

I've done this befere without success.
The organization field is being filtered perfectly, but creation date doesn't.

If try this codes bellow:

$tickets = $zendesk->tickets()->findAll(["created_at" => "2015-01-07", "organization_id" => $orgID]);

and

$tickets = $zendesk->tickets()->findAll(["created_at>2015-01-07", "organization_id" => $orgID]);

also

$tickets = $zendesk->tickets()->findAll(["created_at>2015-01-07"]);

print_r($tickets);
....

It returns me all tickets, like:
[created_at] => 2015-06-03T13:52:39Z
[updated_at] => 2015-07-17T20:05:29Z
[type] => problem
[subject] => "loren ipson"
etc....

Any idea?

@RaFeNiX
Copy link

RaFeNiX commented Oct 26, 2015

Hi rafael,
i just figured out you're using the findAll() from tickets().In this case i would use ## $teste = $client->search(['query'=>"type:ticket created_at>2015-01-07"]); ##
try it, working here

Date: Mon, 26 Oct 2015 08:23:05 -0700
From: notifications@github.com
To: zendesk_api_client_php@noreply.github.com
CC: rafa.jacomini@hotmail.com
Subject: Re: [zendesk_api_client_php] Filter and search request (#217)

I've done this befere without success.

The organization field is being filtered perfectly, but creation date doesn't.

If try this codes bellow:

$tickets = $zendesk->tickets()->findAll(["created_at" => "2015-01-07", "organization_id" => $orgID]);

and

$tickets = $zendesk->tickets()->findAll(["created_at>2015-01-07", "organization_id" => $orgID]);

also

$tickets = $zendesk->tickets()->findAll(["created_at>2015-01-07"]);

print_r($tickets);

....

It returns me all tickets, like:

[created_at] => 2015-06-03T13:52:39Z

[updated_at] => 2015-07-17T20:05:29Z

[type] => problem

[subject] => "loren ipson"

etc....

Any idea?


Reply to this email directly or view it on GitHub.

@rafaelfoster
Copy link
Author

Thanks for your response @RaFeNiX

Unfortunally, it still not working.

I've copied your entire line and add it to my code.
The API doesn't returns me any erros.

But it return this:

Zendesk\API\Resources\Core\Search Object
(
[resourceName:protected] => search
[objectName:protected] => search
[objectNamePlural:protected] => searches
[client:protected] => Zendesk\API\HttpClient Object
(
[auth:protected] => Zendesk\API\Utilities\Auth Object
(
[authStrategy:protected] => basic
[authOptions:protected] => Array
(
[username] => helpdesk@EXAMPLE.com.br
[token] => 8Gasdsadsada4GCBAuRiRLitJCcj6wbHNLWPQEhhTcl3epIfWK
)

            )

        [subdomain:protected] => EXAMPLE
        [username:protected] => helpdesk@EXAMPLE.com.br
        [scheme:protected] => https
        [hostname:protected] => zendesk.com
        [port:protected] => 443
        [apiUrl:protected] => https://EXAMPLE.zendesk.com:443/api/v2/
        [apiVer:protected] => v2
        [sideload:protected] => 
        [debug:protected] => Zendesk\API\Debug Object
            (
                [lastRequestBody] => 
                [lastRequestHeaders] => Array
                    (
                        [Host] => Array
                            (
                                [0] => EXAMPLE.zendesk.com
                            )

                        [Accept] => Array
                            (
                                [0] => application/json
                            )

                        [Content-Type] => Array
                            (
                                [0] => application/json
                            )

                        [User-Agent] => Array
                            (
                                [0] => ZendeskAPI PHP 2.0.0
                            )

                    )

                [lastResponseCode] => 200
                [lastResponseHeaders] => Array
                    (
                        [Server] => Array
                            (
                                [0] => nginx
                            )

                        [Date] => Array
                            (
                                [0] => Mon, 26 Oct 2015 16:28:05 GMT
                            )

                        [Content-Type] => Array
                            (
                                [0] => application/json; charset=UTF-8
                            )

                        [Content-Length] => Array
                            (
                                [0] => 5349
                            )

                        [Connection] => Array
                            (
                                [0] => keep-alive
                            )

                        [Status] => Array
                            (
                                [0] => 200 OK
                            )

                        [X-Zendesk-API-Version] => Array
                            (
                                [0] => v2
                            )

                        [X-Frame-Options] => Array
                            (
                                [0] => SAMEORIGIN
                            )

                        [Strict-Transport-Security] => Array
                            (
                                [0] => max-age=31536000;
                            )

                        [X-UA-Compatible] => Array
                            (
                                [0] => IE=Edge,chrome=1
                            )

                        [ETag] => Array
                            (
                                [0] => W/"46af5d3faec10f397298da25788aa75f"
                            )

                        [Cache-Control] => Array
                            (
                                [0] => must-revalidate, private, max-age=0
                            )

                        [X-Zendesk-Origin-Server] => Array
                            (
                                [0] => app13.pod4.sac1.zdsys.com
                            )

                        [X-Request-Id] => Array
                            (
                                [0] => 099b76e0-c9d2-4b66-cb0a-b8ca3a61dd58
                            )

                        [X-Runtime] => Array
                            (
                                [0] => 0.699089
                            )

                        [X-Rack-Cache] => Array
                            (
                                [0] => miss
                            )

                        [X-Zendesk-Request-Id] => Array
                            (
                                [0] => b23edeab94d1ca72b9c912adas
                            )

                        [X-Content-Type-Options] => Array
                            (
                                [0] => nosniff
                            )

                    )

                [lastResponseError] => 
            )

        [guzzle] => GuzzleHttp\Client Object
            (
                [config:GuzzleHttp\Client:private] => Array
                    (
                        [handler] => GuzzleHttp\HandlerStack Object
                            (
                                [handler:GuzzleHttp\HandlerStack:private] => Closure Object
                                    (
                                        [static] => Array
                                            (
                                                [default] => Closure Object
                                                    (
                                                        [static] => Array
                                                            (
                                                                [default] => GuzzleHttp\Handler\CurlMultiHandler Object
                                                                    (
                                                                        [factory:GuzzleHttp\Handler\CurlMultiHandler:private] => GuzzleHttp\Handler\CurlFactory Object
                                                                            (
                                                                                [handles:GuzzleHttp\Handler\CurlFactory:private] => Array
                                                                                    (
                                                                                        [0] => Resource id #90
                                                                                    )

                                                                                [maxHandles:GuzzleHttp\Handler\CurlFactory:private] => 50
                                                                            )

                                                                        [selectTimeout:GuzzleHttp\Handler\CurlMultiHandler:private] => 1
                                                                        [active:GuzzleHttp\Handler\CurlMultiHandler:private] => 0
                                                                        [handles:GuzzleHttp\Handler\CurlMultiHandler:private] => Array
                                                                            (
                                                                            )

                                                                        [delays:GuzzleHttp\Handler\CurlMultiHandler:private] => Array
                                                                            (
                                                                            )

                                                                        [_mh] => Resource id #93
                                                                    )

                                                                [sync] => GuzzleHttp\Handler\CurlHandler Object
                                                                    (
                                                                        [factory:GuzzleHttp\Handler\CurlHandler:private] => GuzzleHttp\Handler\CurlFactory Object
                                                                            (
                                                                                [handles:GuzzleHttp\Handler\CurlFactory:private] => 
                                                                                [maxHandles:GuzzleHttp\Handler\CurlFactory:private] => 3
                                                                            )

                                                                    )

                                                            )

                                                        [parameter] => Array
                                                            (
                                                                [$request] => 
                                                                [$options] => 
                                                            )

                                                    )

                                                [streaming] => GuzzleHttp\Handler\StreamHandler Object
                                                    (
                                                        [lastHeaders:GuzzleHttp\Handler\StreamHandler:private] => Array
                                                            (
                                                            )

                                                    )

                                            )

                                        [parameter] => Array
                                            (
                                                [$request] => 
                                                [$options] => 
                                            )

                                    )

                                [stack:GuzzleHttp\HandlerStack:private] => Array
                                    (
                                        [0] => Array
                                            (
                                                [0] => Closure Object
                                                    (
                                                        [parameter] => Array
                                                            (
                                                                [$handler] => 
                                                            )

                                                    )

                                                [1] => http_errors
                                            )

                                        [1] => Array
                                            (
                                                [0] => Closure Object
                                                    (
                                                        [parameter] => Array
                                                            (
                                                                [$handler] => 
                                                            )

                                                    )

                                                [1] => allow_redirects
                                            )

                                        [2] => Array
                                            (
                                                [0] => Closure Object
                                                    (
                                                        [parameter] => Array
                                                            (
                                                                [$handler] => 
                                                            )

                                                    )

                                                [1] => cookies
                                            )

                                        [3] => Array
                                            (
                                                [0] => Closure Object
                                                    (
                                                        [parameter] => Array
                                                            (
                                                                [$handler] => 
                                                            )

                                                    )

                                                [1] => prepare_body
                                            )

                                    )

@RaFeNiX
Copy link

RaFeNiX commented Oct 26, 2015

try this simple code.

include("./vendor/autoload.php");
use Zendesk\API\Client as ZendeskAPI;
$subdomain = "";
$username = "";
$token = "";
$client = new ZendeskAPI($subdomain, $username);
$client->setAuth('token', $token);

$tesrte = $client->search(['query'=>"type:ticket created_at>2015-10-20"]);

echo json_encode($tesrte);

@rafaelfoster
Copy link
Author

The json returns me empty.

Hey, maybe it could be the last version of API?
I've cloned this repo.
Which version are you using?

error_zenapi

error_zenapi2

@miogalang
Copy link
Contributor

Hi @rafaelfoster

On version 2 of the client things have changed quite a bit.

To achieve what you want, you would want a snippet like

$response = $client->search()->find('type:ticket created>=2015-09-01 created<2015-10-01');

Search is now a resource you can make calls on, similar to a ticket or a user. We wanted to keep this pattern consistent.

There definitely should be an example on search, will put that in the list of things to do.

For more documentation on using search there is https://developer.zendesk.com/rest_api/docs/core/search and https://support.zendesk.com/hc/en-us/articles/203663226

And a pro tip to test your query string easily is to try it out in the zendesk ui.
screen shot 2015-10-28 at 10 20 54 am

It also seems like you are using the version 1 way of making a search, if you are upgrading, there is a handy upgrade guide that can help you upgrade.

Please let me know if this works.

@rafaelfoster
Copy link
Author

Yeah! That's working now @miogalang

I really appreciate that!

Thanks for your help too @RaFeNiX

@JohnieMutio
Copy link

Hey, am using php curl to execute my search query but It returns null everytime. Below is a snippet of my code:

$date="2018-09-01";
//$link = isset($link) ? $link : "https://$subdomain.zendesk.com/api/v2/$resource.json?created_at>=".$date;
$link = isset($link) ? $link : "https://$subdomain.zendesk.com/api/v2/search?query=type:user created_at=".$date;
while($link){
$ch = curl_init($link);

			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

			curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); 
										
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

			curl_setopt($ch, CURLOPT_USERPWD, $email . ":" .$password);

			$response = curl_exec($ch);

			$output = json_decode($response);
				
			var_dump($output);

$link = $output->next_page;
}

What am I doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants