因此,我尝试使用curl请求将用户订阅mailchimp。我遵循了一些集成指南。该请求有效。我只是布尔false的响应,不确定我在这里错过了什么。
$apiKey = *mailchimp api Key*;
$server = *server*;
$list = *mailchimp list id*;
public function index(Request $request){
$auth = base64_encode( 'user:'.$apiKey);
$post = array(
'apikey'=> $apiKey,
'email_address' => $request->input('EMAIL'),
'status' => 'subscribed',
'merge_fields' => array(
'FNAME' => $request->input('FNAME'),
'BIZNAME' => $request->input('BIZNAME')
)
);
$json_data = json_encode($post);
$url = "https://".$server.".api.mailchimp.com/3.0/lists/".$list."/members/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Basic '.$auth));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$json_response = curl_exec($ch);
header("Content-Type: application/json;charset=utf-8");
curl_close($ch);
return response()->json($json_response);
}
答案 0 :(得分:0)
因此想出了问题所在@kerbholz,感谢您指出了正确的方向。服务器属性是从API密钥派生的。
// get the server data center
$server= substr($apiKey,strpos($apiKey,'-')+1);
// set the url
$url = "https://".$server.".api.mailchimp.com/3.0/lists/".$list."/members";