sendgrid / sendgrid-php

The Official Twilio SendGrid PHP API Library
https://sendgrid.com
MIT License
1.49k stars 624 forks source link

AWS error when try import contacts csv #1084

Closed Kleinast closed 2 years ago

Kleinast commented 2 years ago

Issue Summary

I have "Requests specifying Server Side Encryption with AWS KMS managed keys require AWS Signature Version 4" when try to import csv contact

Steps to Reproduce

  1. Ask for upload url
  2. curl to send contacts csv to given aws url

Code Snippet

try {
$request_body = [
            "file_type" => "csv",
            "field_mappings" => [
                '_rf2_T',
                '_rf0_T',
                '_rf1_T',
                null,
                null,
                '_rf6_T',
                null,
                '_rf8_T',
                '_rf9_T',
                'e1_T',
            ]
        ];

            $response = $this->sendGrid->client->marketing()->contacts()->imports()->put($request_body);
            dump(
                $response->statusCode(),
                $response->headers(),
                json_decode($response->body())
            );
        } catch (Exception $ex) {
            echo 'Caught exception: '.  $ex->getMessage();
        }

and after

curl --upload-file "contacts-upload-test.csv" "https://mc-contacts-import-upload-production.s3.us-west-2.amazonaws.com/***.csv\?*********" -H '{"header":"x-amz-server-side-encryption","value":"aws:kms"}'

Exception/Log

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>InvalidArgument</Code><Message>Requests specifying Server Side Encryption with AWS KMS managed keys require AWS Signature Version 4.</Message><ArgumentName>Authorization</ArgumentName><ArgumentValue>null</ArgumentValue><RequestId>FMGG7740DC75MP5E</RequestId><HostId>ulXwz+ikcuVLWndOfuRqKmXzSd2b56U5nfwqLmytF4ViURwHcPjWC4ipQ31RuIyStf2KB/CgwYY=</HostId></Error>%

Technical details:

Kleinast commented 2 years ago

I think I find the problem, just in https://docs.sendgrid.com/api-reference/contacts/import-contacts it say to call: curl --upload-file "file/path.csv" "URL_GIVEN" -H 'HEADER_GIVEN' But the given url given into double quote seem escape so it show me that error. Also it's not really mention that the upload_uri response param give a json object that have to be transform from {"header":"x-amz-server-side-encryption","value":"aws:kms"} to -H 'x-amz-server-side-encryption: aws:kms'