Hi Bob,
thank you for your reply!
I have entered the the right API key from Mailchimp as described in their documentation.
In the cURL Action I have entered some test-informations as followed:
Target URL:
https://us13.api.mailchimp.com/3.0/lists/MYLISTID/members
Fields map:
user = "anystring:MYAPIKEY"
header = "content-type: application/json"
data = "{"email_address":"urist.mcvankab+3@freddiesjokes.com", "status":"subscribed"}"
I got the following response from the mailchim server:
Array
(
[7] => Array
(
[Curl] => Array
(
[0] => CURL OK : the CURL function was found on this server.
[1] => $curl_values: user=anystring%MYAPIKEY&header=content-type%3A+application%2Fjson&data=%22email_address%22%3A%22urist.mcvankab%2B3%40freddiesjokes.com%22%2C+%22status%22%3A%22subscribed%22
[2] => curl_target_url: https://us13.api.mailchimp.com/3.0/lists/MYLISTID/members
[3] => curl_errors:
[4] => curl_info: Array
(
[url] => https://us13.api.mailchimp.com/3.0/lists/MYLISTID/members
[content_type] => application/problem+json; charset=utf-8
[http_code] => 401
[header_size] => 371
[request_size] => 363
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.203538
[namelookup_time] => 0.000795
[connect_time] => 0.005355
[pretransfer_time] => 0.034184
[size_upload] => 203
[size_download] => 193
[speed_download] => 948
[speed_upload] => 997
[download_content_length] => 193
[upload_content_length] => 203
[starttransfer_time] => 0.203504
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 104.96.153.35
[certinfo] => Array
(
)
)
)
)
)
I think there is a problem when transmitting the user credentials to the Mailchimp Server with the cURL action from CF5.
Do you know any other way how i can transmit the necessary data in a JSON Format with CF5?
I have found a good example which should work, but i dont get any output from the debugger to find the errors when i put the following code in a Custom Code action:
<?php
$data = [
'email' => 'johndoe@example.com',
'status' => 'subscribed',
'firstname' => 'john',
'lastname' => 'doe'
];
$apiKey = 'c72f8b0cfb094bb0ab442079d35015eb-us13';
$listId = '8e9efd48d7';
$memberId = md5(strtolower($data['email']));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listId . '/members/' . $memberId;
$json = json_encode([
'email_address' => $data['email'],
'status' => $data['status'],
'merge_fields' => [
'FNAME' => $data['firstname'],
'LNAME' => $data['lastname']
]
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
?>
Source: http://stackoverflow.com/a/32956160
Thank you