ShipStream / fedex-rest-php-sdk

PHP SDK for FedEx REST APIs
Apache License 2.0
7 stars 0 forks source link

Trying to upload a letterhead image #1

Open Menno-Logitrade opened 2 months ago

Menno-Logitrade commented 2 months ago

The Image upload seems te be broken or I am doing something wrong.

I want to upload an image to FedEx to later use that in my letterhead and signature. I want to reference that image later on as 'IMAGE_1'

I'm trying to use it like this:

I have a working $connector

        $image1 = base64_encode(file_get_contents(__DIR__.'/files/image.png'));

        $apiDocuments = $connector->tradeDocumentsUploadV1();

        $documentRules = new DocumentRules("LetterheadSignature");
        $documentMeta = new DocumentMeta('LETTERHEAD','IMAGE_1');
        $document = new Document(
            'IMAGE_1',
            'letterhead.png',
            'image/png',
            $documentRules,
            $documentMeta
        );
        $imageUploadService = new FullSchemaImageUploadServiceInputVo($image1,$document);
        $uploadResponse = $apiDocuments->imageUploadServiceInfo($imageUploadService);

I get this error:

[InvalidArgumentException] The value array must only contain Saloon\Data\MultipartValue objects.

#1  /app/vendor/saloonphp/saloon/src/Repositories/Body/MultipartBodyRepository.php:190
#2  /app/vendor/saloonphp/saloon/src/Repositories/Body/MultipartBodyRepository.php:64
#3  /app/vendor/saloonphp/saloon/src/Repositories/Body/MultipartBodyRepository.php:48
#4  /app/vendor/saloonphp/saloon/src/Traits/Body/HasMultipartBody.php:32
#5  /app/vendor/saloonphp/saloon/src/Traits/Body/HasMultipartBody.php:24
#6  /app/vendor/saloonphp/saloon/src/Helpers/Helpers.php:95
#7  /app/vendor/saloonphp/saloon/src/Http/PendingRequest/BootPlugins.php:28
#8  /app/vendor/saloonphp/saloon/src/Http/PendingRequest.php:315

For some reason it does not want to accept a string as the "attachment" input. But the specifiactions does say I should input a string here:

final class FullSchemaImageUploadServiceInputVo extends Dto
{
    /**
     * @param  
final class FullSchemaImageUploadServiceInputVo extends Dto
{
    /**
     * @param  string  $attachment  Input the actual image file to be uploaded.
     * @param  Document  $document  Indicate the image reference metadata details.
     */
    public function __construct(
        public readonly string $attachment,
        public readonly Document $document,
    ) {
    }
}
Menno-Logitrade commented 2 months ago

https://stackoverflow.com/questions/78593938/restful-fedex-trade-document-upload-api-cant-upload-signature-or-letterhead-i/78697033#78697033

The fedex documentation is wrong according to this post. So this autogenerated API would also be wrong then...

colinmollenhour commented 2 months ago

Thanks for the report, we will test this as well. Note, the FedEx REST API is according to FedEx still in a "pilot phase" so we expect there to be changes in the coming months. I recommend you request an exemption from the August 31 deadline if you are having any troubles with the current API.