Giter Site home page Giter Site logo

Comments (4)

rygilles avatar rygilles commented on July 4, 2024

I've tried adding the implementation and when I do :

$params = array('file' => $my_zip_file_local_path);
try
{
   $my_client->apps()->upload($params);
}
else
{
   die('<pre>' . print_r($my_client()->getDebug(), true) . '</pre>');
}

I get this :

Zendesk\API\Debug Object
(
    [lastRequestHeaders] => POST /api/v2/apps/uploads.json HTTP/1.1
Authorization: Basic cnlhbkBlLW1vbnNpdGUuY29tL3Rva2VuOk9uRnlSd1YwM2tSYTdmWVljWmJoQ0Q0VWVUZk1UVTV1SVFsY1k5eGs=
Host: testemonsite.zendesk.com
Accept: application/json
Content-Length: 83319
Expect: 100-continue
Content-Type: application/binary; boundary=----------------------------b9438b9d3355


    [lastResponseCode] => 422
    [lastResponseHeaders] => HTTP/1.1 100 Continue

HTTP/1.1 422 Unprocessable Entity
Server: nginx/1.4.7
Date: Thu, 22 May 2014 14:01:25 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 422 Unprocessable Entity
X-FRAME-OPTIONS: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Set-Cookie: _zendesk_shared_session=eyJpZCI6IjQ1OGM2ZTY0M2EwODk3YWFlNDQ3Y2ZjODFhOWY2NTgyIiwiYWNjb3VudCI6NTI1MDI1fQ%3D%3D--7d74591285df788fb00663808acceeab8b958861; path=/; secure; HttpOnly
Set-Cookie: _carson_container_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFVEkiJTM1NTRkNGE3MmUwNWI5NmNlMzUwOTU2NmJhYzRhMTI4BjsAVEkiDGFjY291bnQGOwBGaQPhAgg%3D--102f4a3a163edd56ca3fd8f88fa579e86b9b557c; path=/; secure; HttpOnly
X-Zendesk-Origin-Server: carson3.pod3.dub1.zdsys.com
X-UA-Compatible: IE=Edge,chrome=1
Cache-Control: no-cache
X-Zendesk-Request-Id: 767875d6d4316645beaf8bd0ac814a48
X-Request-Id: 767875d6d4316645beaf8bd0ac814a48
X-Runtime: 1.063949
X-Rack-Cache: invalidate, pass


)

But maybe i'm using this part of the API not properly at all....

from zendesk_api_client_php.

rygilles avatar rygilles commented on July 4, 2024

After trying to execute the request directly with CURL, like this :

$ch = curl_init();

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_URL, 'https://mysubdomain.zendesk.com/api/v2/apps/uploads.json');
curl_setopt($ch, CURLOPT_USERPWD, $user . '/token:' . $token));
curl_setopt($ch, CURLOPT_VERBOSE, 1);       
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/binary'));
curl_setopt($ch, CURLOPT_POST, true);
$file = fopen($filepath, 'r');
$size = filesize($filepath);
$filedata = fread($file, $size);
curl_setopt($ch, CURLOPT_POSTFIELDS, $filedata);
curl_setopt($ch, CURLOPT_INFILE, $file);
curl_setopt($ch, CURLOPT_INFILESIZE, $size);
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);

$output = curl_exec($ch);

curl_close($ch);

$decoded = json_decode($output);

die('<pre>' . print_r($decoded, true) . '</pre>');

I get this :

stdClass Object
(
    [error] => RecordInvalid
    [description] => Attachment cannot be empty
Attachment file name cannot be empty
)

Also, after analyzing the Http.php code, i think there's a problem with the param

array('uploaded_data' => '@'.$params['file'])

in Apps.php passed as $json in Http.code wich there's nothing converting the 'uploaded_data' param in "file post". This variable should be nammed $json['filename'] think.

In Http.php :

 if($method == 'POST') {
            $curl = curl_init($url);
            curl_setopt($curl, CURLOPT_POST, true);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
            if(isset($json['filename'])) {
                            $file = fopen($json['filename'], 'r');
                            $size = filesize($json['filename']);
                            $filedata = fread($file, $size);
                            curl_setopt($curl, CURLOPT_POSTFIELDS, $filedata);
                            curl_setopt($curl, CURLOPT_INFILE, $file);
                            curl_setopt($curl, CURLOPT_INFILESIZE, $size);
                            curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/binary'));
                        }
        }

from zendesk_api_client_php.

dpawluk avatar dpawluk commented on July 4, 2024

Looks like PR #26 fixed this issue. Closing.

from zendesk_api_client_php.

mikealmond avatar mikealmond commented on July 4, 2024

I don't believe #26 fixed this issue. See https://github.com/zendesk/zendesk_api_client_php/blob/master/src/Zendesk/API/Apps.php#L40 as @RyanGilles mentioned.

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.