0

After executing a MailChimp API v3 batch request, it returns a URL to a .tar.gz file with the response.

When copy/paste the URL into the browser's address field, the file get's downloaded instantly.

But, when trying to download this file via PHP cURL, the response is "Access Denied".

This is my PHP cURL script:

$_curl = curl_init();
curl_setopt_array($_curl, array(
    CURLOPT_URL => $_GET['responseUrl'],
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => ''
));
$_response = curl_exec($_curl);
curl_close($_curl);
echo $_response;

This is the response (as string):

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>AccessDenied</Code>
    <Message>Access Denied</Message>
    <RequestId>___someRequestId___</RequestId>
    <HostId>___someHostId___</HostId>
</Error>

Trying a cURL request from the command line curl -v https://... this is returned:

[1] 54284
[2] 54285
[2]+  Done                    Expires=1475609534
*   Trying 54.231.40.155...
* Connected to mailchimp-api-batch.s3.amazonaws.com (54.231.40.155) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.s3.amazonaws.com
* Server certificate: DigiCert Baltimore CA-2 G2
* Server certificate: Baltimore CyberTrust Root
> GET /c1b0e9e42e-response.tar.gz?AWSAccessKeyId=AKIAJWOH5BECJQZIEWNQ HTTP/1.1
> Host: mailchimp-api-batch.s3.amazonaws.com
> User-Agent: curl/7.49.1
> Accept: */*
> 
< HTTP/1.1 403 Forbidden
< x-amz-request-id: E15A53E1C3223996
< x-amz-id-2: UlcIl/cpOwDL9glkG7aho7HEpbskm8f/V56U71yfZWyefyALUHW0bvLFU5iRGiAFb+t2fx/77Fo=
< Content-Type: application/xml
< Transfer-Encoding: chunked
< Date: Tue, 04 Oct 2016 19:35:19 GMT
< Server: AmazonS3
< 
<?xml version="1.0" encoding="UTF-8"?>
* Connection #0 to host mailchimp-api-batch.s3.amazonaws.com left intact
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>E15A53E1C3223996</RequestId><HostId>UlcIl/cpOwDL9glkG7aho7HEpbskm8f/V56U71yfZWyefyALUHW0bvLFU5iRGiAFb+t2fx/77Fo=</HostId></Error>

What's wrong with the cURL request?

Sommereder
  • 904
  • 4
  • 10
  • 32
  • Any MailChimp cookies in your browser? When you clear the cookies and enter the URL does the file still downloads? – Te Ko Oct 04 '16 at 20:43
  • I ran the batch in Chrome and entered the URL in Opera in a private window after cleaning the whole history. The download worked. – Sommereder Oct 04 '16 at 20:52

0 Answers0