PHP API Library

Comments

125 comments

  • Avatar
    Jason Knudsen

    This is really awesome. Thanks for your hard work Brian! It's very appreciated.

  • Avatar
    Morten Primdahl

    Absolutely! Thanks Brian, stunning.

  • Avatar
    Jossi Fresco

    Fantastic! Thank you/

  • Avatar
    Tom Deryckere

    Great library. Works perfect

  • Avatar
    rich breton

    what if you dont know the users password, is there a way to use the zendesk X-On-Behalf-Of: joe.enduser@theendusers.com header?

  • Avatar
    Tanya

    This is awesome - thank you so much for putting this together and sharing it with us!

  • Avatar
    Brian Hartvigsen

    Use $arg['on-behalf-of'] = 'joe.enduser@theendusers.com'; . So for example:

    $result = $zd->create(ZENDESK_TICKETS, array(
        'details' => array(
            'description' => 'My printer is not working',
            'requester-id' => 3,
            'priority' => 4,
            'set-tags' => 'pr facility'
        ),
        'on-behalf-of' => 'joe.enduser@theendusers.com'
    ));

  • Avatar
    Tanya

    Hello Brian,

    I am trying to use this library for forum search. How would you recommend adding tag specific search into the URL?

    Also, there's a bug in how the GET parameters get assembled in this code ('&') (that character is missing between the parameters in the final URL):

    if (is_array($opts['query'])) { $query = '?'; foreach ($opts['query'] as $key=>$value) $query .= urlencode($key).'='.urlencode($value); $url .= $query; }

  • Avatar
    Adam

    Does this work for users, getting list of tickets, etc?

  • Avatar
    Brian Hartvigsen

    Tanya: It doesn't appear to be possible to search forums using the API (unless it's implemented in the standard search rest api, but that appears to relate specifically to tickets.)  If entries support searching the same way users do, then you would do something like $array('query' => 'query=tags:blah keyword keyword2') with the options array.  I've never tested that. The GET parameters building is definitely a bug, only applies if you pass in the options as an array.  I've fixed it locally, need to upload.  Just want to confirm so other tweaks I've made.

    Adam: Sure, use the 'on-behalf-of' argument mentioned a couple posts previously, than something like:

    $result = $zd->get(ZENDESK_REQUESTS, array(
        'on-behalf-of' =>  'joe.enduser@theendusers.com'
    ));

    That will get a list of all tickets 'joe.enduser@theendusers.com' opened which can then be displayed to the end user.  For most things, just follow the API documentation and it _should _work.

  • Avatar
    Adam

    Thanks Brian all working well so far.

  • Avatar
    Adam

    Brian I'm struggling with updating a ticket with an end user comment. Currently got this:

     

     

    $result = $zd->update(ZENDESK_TICKETS, array(

       'id' => '6',

       'details' => array(

           'comment' => 'My printer is not working',

          ),

       'on-behalf-of' => 'joe.enduser@theendusers.com'

    ));

    $result = $zd->update(ZENDESK_TICKETS, array(   

     'id' => '6',

     'details' => array(        'comment' => 'My printer is not working',

      ),

     'on-behalf-of' => 'joe.enduser@theendusers.com'

    ));

     

    Obviously I'm using the right email address. I think I'm doing the ticket id wrong?

  • Avatar
    Brian Hartvigsen

    Hey Adam, you aren't doing anything wrong.  That's one of those "tweaks" I was mentioning in my reply to Tanya.  Adding a comment doesn't work correctly in that build since it wraps the XML data in a <ticket> object instead of a <comment> object.  Copy the following code and replace the existing $args['data' ] = ... in function update($page, $args):

     

            if ($page != ZENDESK_REQUESTS && !($page == ZENDESK_TICKETS && isset($args['details']['value'])))       

                $args['data'] = $this->_build_xml($args['details'], $this->_singular($page));

            else

            if ($page != ZENDESK_REQUESTS && !($page == ZENDESK_TICKETS && isset($args['details']['value'])))
                      $args['data'] = $this->_build_xml($args['details'], substr($page, 0, -1));
            else
                      $args['data'] = $this->_build_xml($args['details'], 'comment'); 

     see if that resolves the issue for you.  I'm surprised that never came up sooner.

  • Avatar
    Brian Hartvigsen

    Not sure what happened w/ my copy paste there.  But that code should simply be:

            if ($page != ZENDESK_REQUESTS && !($page == ZENDESK_TICKETS && isset($args['details']['value'])))
                      $args['data'] = $this->_build_xml($args['details'], substr($page, 0, -1));
            else
                      $args['data'] = $this->_build_xml($args['details'], 'comment');

  • Avatar
    Adam

    Thanks Brian !

    Still not working for me though. Not getting any errors logged and nothing back from $result. Will have a think!

  • Avatar
    mantra1

    Hi, I'm using PHP API Library Is there a way to get all the tickets of a particular end-user ?

  • Avatar
    Chris Houseknecht

    Brian-

    Nice job!  We're using your library to connect external, hosted apps to Zendesk. 

    I found something that might be of interest to you or others. The _singular function only returns the first character of the input parameter, if the input parameter does not contain 'ies'. When trying to create a ticket, the string 'tickets' is passed in, and the result is 't'.

    To correct this, I changed the last line of the _singular function to the following:

    else return substr($noun, 0, strlen($noun) - 1); 

    This causes it to return the full string minus the last character.  In other words, pass in 'tickets', and the result is now 'ticket'. 

    Hope this helps!

     

  • Avatar
    Chris Houseknecht

    It just occurred to me, there is a simpler way to write that...

    else return substr($noun, 0, -1);

    No need for a call to strlen().  All that was missing was a '-'. 

  • Avatar
    Brian Hartvigsen

    @mantra1 - ZenDesk pages things so no

    @Chris Houseknecht - Good catch, I've updated the download on Google Code.

  • Avatar
    Samuel Nilsson

    Hi, thanks for spending time on the library. I´ve been trying to get it working but it fails somewhere.. I can get users and tags but not any entries nor posts and requests. I also tried to do a search with no success. What am  I doing wrong:

    $result = $zd->get(search, array('query' => 'type:ticket', 'on-behalf-of' => 'test@domain.com'));

  • Avatar
    Sahil Parikh

    Hello!

    Thanks for the library. Before we start to use it I just wanted to know if it does the following. Please let me know:

    1. Adding a new ticket

    2. Adding a new ticket with attached files

    3. Adding a comment to an existing ticket

    4. Closing a ticket

    5. Adding time to a ticket

  • Avatar
    Dennis Monsewicz

    I am trying to utilize the api library that you have created but when I try to retrieve all of the tickets in our system... I get a blank page... not that there are any errors but that the script isn't pulling all of the tickets.

    require_once "Zendesk.lib.php";
            
            $zd = new Zendesk("account", "username", "password", true);
            $result = $zd->get(ZENDESK_TICKETS);
            
            echo $result;

  • Avatar
    EricDahl

    I am trying to figure out how to make a simple form that I can manually enter my user's external ID and have it populate.

    can anyone point me in the right direction?

  • Avatar
    Tikhon Tasenko

    Hi Brian!

    Useful lib, thanks for that.

    Have a small question - Is it possible to sync users' passwords as well?

  • Avatar
    Tikhon Tasenko

    Me again :-)

    Answering to my question - yes, it's possible.

     

    'id' => $zendesk_id,

            'details' => array(

                  'email' => $account->mail,

                  'name' => $account->name,

                  'external-id' => $account->uid,

     'password' => $edit["pass"], //password synchronize

                ),

              )

    'id' => $zendesk_id,

    'details' => array(

    'email' => $account->mail,

    'name' => $account->name,

    'external-id' => $account->uid,

    'password' => $edit["pass"], //password synchronize

    ),

    )

    Maybe it will be useful to anyone

     

  • Avatar
    Tikhon Tasenko

    ops, sorry

    don't know how to manage that parser

  • Avatar
    Nicholas Van Dusen

    I'm not seeing any downloads on Google Code, am I missing something? I'd really like to use this library!

  • Avatar
    Tikhon Tasenko

    Hey Nicholas, try look here http://zendesk-php-lib.googlecode.com/svn/trunk/

     

    Cheers, Tikhon

  • Avatar
    Nicholas Van Dusen

    Thanks, Tikhon!

  • Avatar
    Brian Hartvigsen

    Yeah.  I got rid of the download since I was doing a lot of changes in a very short period of time and realized it wasn't actually very helpful in this case to have a separate download.  As the main page says:

    "Grab the latest download from  repository."

Please sign in to leave a comment.

Powered by Zendesk