Giter Site home page Giter Site logo

Comments (2)

joeelizondo avatar joeelizondo commented on July 24, 2024 2

Just incase anyone else was having trouble with this, it can be done by setting the 'optional_token' parameter when looping through the files you want to upload.

use Zendesk\API\Client as ZendeskAPI;

$client = new ZendeskAPI($this->keys['subdomain'], $this->keys['username']);
$client->setAuth('token', $this->keys['token']); // set either token or password
$ticket = $client->tickets($ticket_id)->find();
$upload_token = '';
foreach($datas as $data) {
    $params = array('file' => self::PATH . $data['output_file'],
                  'type' => 'text/plain',
                  'name' => $data['output_file']);
    if(isset($upload_token)) {
        $params['optional_token'] = $upload_token;
    }
    $attachment = $client->attachments()->upload($params);
    $upload_token = $attachment->upload->token;
}

from zendesk_api_client_php.

hiaik avatar hiaik commented on July 24, 2024

Hi @joeelizondo

Although in code sample provided we have this doc:

 * Optional:
 *    'optional_token' - an existing token
 *        'name' - preferred filename

In the real code we have this:

if (isset($params['token'])) {
            $queryParams['token'] = $params['token'];
        }

In conclusion,

RE: adding multiple attachments to one comment of ZD ticket

<?php

use Zendesk\API\HttpClient as ZendeskAPI;

class ZDTEST
{

    public function execute()
    {
        // https://github.com/zendesk/zendesk_api_client_php
        // run "php composer.phar require zendesk/zendesk_api_client_php" from LSS dir

        $subdomain = "";
        $username = "";
        $token = ""; // replace this with your token

        $ticket_id = 2600;

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

        $sqlFiles = glob($this->directory . '/*.png');
        $upload_token = '';

        foreach ($sqlFiles as $sqlFile) {
            $params = array(
                'file' => $this->directory . basename($sqlFile),
                'type' => 'image/png',
                'name' => basename($sqlFile) // Optional parameter, will default to filename.ext
            );


            // multiple attachments
            // persist token https://github.com/zendesk/zendesk_api_client_php/issues/25
            if (isset($upload_token)) {
                $params['token'] = $upload_token;
            }

            $attachment = $client->attachments()->upload($params);
            $upload_token = $attachment->upload->token;
        }

        $client->tickets()->update($ticket_id, [
            'priority' => 'high',
            'comment' => [
                'body' => 'TEST',
                'uploads' => [$upload_token],
                'public' => false
            ]
        ]);
    }
}

from zendesk_api_client_php.

Related Issues (20)

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.