davidtsadler / ebay-sdk-php

An eBay SDK for PHP. Use the eBay API in your PHP projects.
Apache License 2.0
350 stars 346 forks source link

Uncaught Guzzle Exception 500 on downloadFile of FileTrasfer API #240

Closed firstroad closed 5 years ago

firstroad commented 5 years ago

Hello, I have made ton of calls and now I am trying to do what is in 09-download-category-item-specifics.php but after I get the FileReferenceID and TaskReferenceID. I get an error when downloadFile is running. My code:

$sdk = new eBaySDK\Sdk([
    'authToken' => $client['authToken'],
    'authorization' => $client['oauthUserToken'],
    'credentials'   => $client['credentials'],
    'siteId'    => $client['siteId']
]);

$service = $sdk->createTrading();
$request = new eBaySDK\Trading\Types\GetCategorySpecificsRequestType();
$request->CategorySpecificsFileInfo = true;
$response = $service->getCategorySpecifics( $request );

if ($response->Ack !== 'Failure') {
    $service = $sdk->createFileTransfer();
    $request = new eBaySDK\FileTransfer\Types\DownloadFileRequest();
    $request->fileReferenceId = $response->FileReferenceID;
    $request->taskReferenceId = $response->TaskReferenceID;

    error_log( "Downloading file: FileReferenceID $request->fileReferenceId TaskReferenceID $request->taskReferenceId" );

    $response = $service->downloadFile( $request );

    if ($response->ack !== 'Failure') {
        if ($response->hasAttachment()) {
            $attachment = $response->attachment();
            $tempFilename = tempnam( sys_get_temp_dir(), 'categories_specifics_' ) . '.zip';
            $fp = fopen( $tempFilename, 'wb' );
            if (!$fp) {
                $r->error = 1;
                $r->errors[] = __( "Failed. Cannot open $tempFilename to write!", 'simple-inventory' );
            } else {
                fwrite( $fp, $attachment['data'] );
                fclose( $fp );
                error_log( __( "File downloaded to $tempFilename. Unzip this file to obtain the category item specifics.", 'simple-inventory' ) );
            }
        } else {
            $r->error = 1;
            $r->errors[] = __('Unable to locate attachment', 'simple-inventory');
        }
    }
}

The error:

Fatal error: Uncaught GuzzleHttp\Exception\ServerException: Server error: `POST https://storage.ebay.com/FileTransferService` resulted in a `500 Internal Server Error` response:
--MIMEBoundaryurn_uuid_33410B11DB624889FB1544452064173546262
Content-Type: application/xop+xml; charset=utf-8; type="te (truncated...)
 in /var/www/html/wp-content/plugins/simple-inventory/includes/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113

The call stack goes from my line $response = $service->downloadFile( $request ); to FileTransferService.php:53 and then you can see in the error message. I have the latest (18) version of sdk, psr7(1.4.2), promises(1.3.1), guzzle(6.3.3) I have checked my credentials and as I told you the first request returns correctly. Something goes wrong with the second request but I can't find what, even if I am struggling for the last 3 hours.

michabbb commented 5 years ago

you should debug the whole request the SDK is generating: header, body, url... and compare it with the ebay docu. use postman to build your own "download file request" (that works, based on the ebay docu). then compare your request with the one the SDK is generating. then you will find out if something is missing or if the SDK is doing something wrong.

firstroad commented 5 years ago

It appears to be that File Transfer API only works with AuthNAuth token and not with oAuth