Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
19
rated 0 times [  26] [ 7]  / answers: 1 / hits: 26393  / 11 Years ago, wed, october 30, 2013, 12:00:00

When making this request:



// Subscribe a new account holder to a MailChimp list
function subscribeSomeoneToMailChimpList()
{
var options =
{
apikey: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
id: xxxxxx,
email:
{
email: [email protected]
},
send_welcome: false
};
var mcSubscribeRequest = UrlFetchApp.fetch(https://us4.api.mailchimp.com/2.0/lists/subscribe.json, options);
var mcListObject = Utilities.jsonParse(mcSubscribeRequest.getContentText());
}


This response is returned:




Request failed for https://us4.api.mailchimp.com/2.0/lists/subscribe.json returned code 500. Truncated server response: {status:error,code:-100,name:ValidationError,error:You must specify a apikey value} (use muteHttpExceptions option to examine full response) (line 120, file v2)




Line 120 is the line on which UrlFetchApp.fetch is called.



The API key is valid (I have tested with simpler API calls that don't include associative arrays). When I append the API key directly to the base URL and remove it from the options, I get an error saying that the list ID is invalid. When I then append the list ID directly to the base URL and remove it from options, I get an error saying that the email address must be in associative array form.



My question is: Using the above format, how does one send requests that contain associative arrays?



The relevant API documentation can be found here.


More From » api

 Answers
1

After further research & tinkering, I was able to solve this:



https://<dc>.api.mailchimp.com/2.0/lists/subscribe.json?apikey=<my_api_key>&id=<my_list_id>&email[email][email protected]&merge_vars[FNAME]=John&merge_vars[LNAME]=Doe&double_optin=false&send_welcome=false


Where <dc> should be replaced with the portion after the dash in your API Key. e.g. us1, us2, uk1, etc.


[#74627] Tuesday, October 29, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jadyngraysons

Total Points: 455
Total Questions: 109
Total Answers: 98

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
jadyngraysons questions
Thu, Apr 23, 20, 00:00, 4 Years ago
Sat, Jan 18, 20, 00:00, 4 Years ago
Tue, Dec 31, 19, 00:00, 4 Years ago
;