当前位置:网站首页>Adding subscribers to a list using mailchimp's API V3
Adding subscribers to a list using mailchimp's API V3
2022-06-24 21:04:00 【Technology feast】
problem :
I'm trying to add users to a list I've created in Mailchimp but I can't find any code examples anywhere. I'm trying to add users to my Mailchimp In the list created in , But you can't find any code samples anywhere .I've tried figuring out how to use the API but I'm very much a "Look at an example and learn" kind of person. I have tried to find out How to use API, But I am very much like “ Learn from examples ” People who .
I've tried using version 2 of the API but nothing seems to be working despite working from examples on the net and Mailchimp says the following about earlier versions of their API on their website: I try to use API Of the 2 edition , But despite the work done through examples on the network , But it doesn't seem to have any effect ,Mailchimp Said on its website about its API Earlier versions of the following :
Versions 2.0 and earlier are deprecated. It is not recommended to use 2.0 And earlier .Only minimal support—bug fixes, security patches—will be available for those versions. These versions provide minimal support ( Bug fix , Security Patch ).
UPDATE 1 : I did some further research based on TooMuchPete's answer with regards to the link on Managing Subscribers and altered some code I found here , but it won't work because the function http_build_query() doesn't deal with nested arrays. to update 1 : be based on TooMuchPete Of answer , I am right. “ Manage subscribers ” The links on , And changed my in here Found some code , But because of the function http_build_query() Cannot handle nested arrays , So it doesn't work .I'm not sure how to deal with the 'merge_fields' portion of adding a subscriber. I'm not sure how to handle adding subscribers “ merge_fields” part .My current code is below: My current code is as follows :
$postdata = http_build_query( array( 'apikey' => $apikey, 'email_address' => $email, 'status' => 'subscribed', 'merge_fields' => array( 'FNAME' => $name ) ) ); $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ) ); $context = stream_context_create($opts); $result = file_get_contents('https://us2.api.mailchimp.com/3.0/lists/<list_id>/members/', false, $context); var_dump($result); die('Mailchimp executed');UPDATE 2 : I've now resorted to using curl and I've managed to get something almost working. to update 2 : I now resort to the use of curl, And I try to make something almost work .The data sends through to Mailchimp but I'm receiving the error "Your request did not include an API key." Data sent to Mailchimp, But I got an error message “ Your request does not contain API secret key ”.I'm guessing I need to authenticate as mentioned here . I guess I need to follow here Authentication as described in .I've tried adding it to the http header which hasn't worked. I try to add it to a that doesn't work http In the head .See my code below: See the code below :
$apikey = '<api_key>'; $auth = base64_encode( 'user:'.$apikey ); $data = array( 'apikey' => $apikey, 'email_address' => $email, 'status' => 'subscribed', 'merge_fields' => array( 'FNAME' => $name ) ); $json_data = json_encode($data); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://us2.api.mailchimp.com/3.0/lists/<list_id>/members/'); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json/r/n Authorization: Basic '.$auth)); curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); $result = curl_exec($ch); var_dump($result); die('Mailchimp executed');Solution :
Reference resources : https://stackoom.com/en/question/23tkp边栏推荐
- "Super point" in "Meng Hua Lu", is the goose wronged?
- Where is 5g really powerful? What is the difference with 4G?
- JMeter parameterization
- Second understanding permutation and combination
- The JS method parameter passed a number beginning with 0. A magical problem occurred and bothered me for a long time
- C語言實現掃雷(簡易版)
- 伯克利、MIT、劍橋、DeepMind等業內大佬線上講座:邁向安全可靠可控的AI
- Shrimp skin test surface treated
- VXLAN 与 MPLS:从数据中心到城域以太网
- List set Introduction & common methods
猜你喜欢

Sleep revolution - find the right length of rest

Create a multithreaded thread class

二叉树的基本性质与遍历

Apple, Microsoft and Google will no longer fight each other. They will work together to do a big thing this year

Bean lifecycle flowchart

Intermediary model -- collaboration among departments

JMeter response assertion

Vant component used in wechat applet

After screwing the screws in the factory for two years, I earned more than 10000 yuan a month by "testing" and counterattacked

Implement the redis simple client customized based on socket
随机推荐
I feel that I am bald again when I help my children with their homework. I feel pity for my parents all over the world
在Dialog中使用透明的【X】叉叉按钮图片
Selenium crawl notes
科创人·味多美CIO胡博:数字化是不流血的革命,正确答案藏在业务的田间地头
Sequence stack version 1.0
Postman assertion
Mapstacks: data normalization and layered color layer loading
Basic properties and ergodicity of binary tree
微信小程序自定义tabBar
CVPR 2022缅怀孙剑!同济、阿里获最佳学生论文奖,何恺明入围
Map跟object 的区别
主数据建设的背景
Leetcode(135)——分发糖果
DAPP system customization of full chain hash game (scheme design)
刚购买了一个MYSQL数据库,提示已有实例,控制台登录实例要提供数据库账号,我如何知道数据库账号。
Camera rental management system based on qt+mysql
Image panr
The JS method parameter passed a number beginning with 0. A magical problem occurred and bothered me for a long time
Common member methods of the calendar class
Comprehensive comparison of the most popular packet capturing tools in the whole network
