How to add in new subscriber using Mailchimp API from Xojo

I have been trying to add in a new subscriber into a list in mail chimp.
hTis is the code i am using.
Do anyone know how to do this??


Dim socket1 As HTTPSecureSocket
Dim form As Dictionary
Dim region As String=[regionid]
Dim vAPIkey As String=[my apikey]
DIM vID as string=[my listid]
socket1 = New HTTPSecureSocket
socket1.Secure = True
form = New Dictionary

form.value("apikey") = vAPIkey
form.value("id") = vID
form.value("email_address")= HomeEmail.Text
form.value("merge_vars[FNAME]")= firstName.text
form.value("merge_vars[LNAME]")= lastName.text
form.value("status")= "subscribed"
form.value("output")="json"

socket1.setFormData form

// this one add an error item on the log
'socket1.post("http://"+region+".api.mailchimp.com/1.3/?method=listSubscribe")

//nothing added but not error in log either
'socket1.post("http://"+region+".api.mailchimp.com/2.0/lists/subscribe.xml")
'socket1.post("http://"+region+".api.mailchimp.com/3.0/?method=listSubscribe")
socket1.post("http://"+region+".api.mailchimp.com/3.0/lists/"+ vID + "/members")

I haven’t used their api yet, but it looks like they’re expecting Json data rather than form fields.

try creating the form data as a JSONItem and use SetRequestContent to set the content with JSONItem.ToString
It also looks like they expect a username/password in the request where password is your APIkey. I think using someName:yourAPIkey@ after http:// should work, but again, I haven’t tried it yet.