i’m trying to automate our mailing list subscriptions with Xojo. I got some goals but still i’m not able to manage a single email registration…
My code looks like this…
Socket.Secure = True
Dim emailData As New Dictionary
emailData.Value("email") = "theNewEmail@gmail.com"
Dim addEmailRequest As New Dictionary
addEmailRequest.Value("apikey") = "myAPIKey"
addEmailRequest.Value("id") = "myListId"
addEmailRequest.Value("email") = emailData
Socket.SetFormData(addEmailRequest)
Socket.Post("https://us3.api.mailchimp.com/2.0/lists/subscribe/")
i use another dictionary for the email fields as Mailchimp needs it to be an associative array (API returned error says “Please enter a struct/associative array”) but
in this way i get a TypeMismatchException when trying to set the form data…
Anyone had luck in this and willing to share some ideas ?
It has a great foundation for interacting with Temboo. It doesn’t support every service they support but its extremely easy to add new services on. If you add additional services please issue a pull request!
I wrote a mail chimp integration back in the day for a product we still occasionally sell. I’ll flag this post and see what I can share tomorrow - I’m off to the gym now.
The problem is that the Email Data has to be a JSON item - not a Xojo dictionary
Probably more like (I’d hard code one to start with)
[code]Socket.Secure = True
// note this REALLY probably should be a JSONitem but lets hard code this to prove it works at all
Dim addEmailRequest As String = "{ ““apikey””: ““myAPIKey””, ““id””: ““myListId””, ““email””: { ““email””: ““theNewEmail@gmail.com”” } } "
I had a look at Temboo and tembookit and they lost me a bit (I am a very part-time developer) so I looked at Brock’s code and it sort of worked for me but although I now know a lot more about dictionaries than I did I still had trouble with the JSON stuff so I tried the basic build a url method with the code below.
It works (and in my head makes sense) but is there a reason why I should not do it this way (security etc>)?
[code]Socket.Secure = True
Dim strinfo As String
Dim result As String
Dim url As String
// Build the string to send to MailChimp
strinfo = “apikey=” + txtAPI.Text
// Check for the api option selected
Select Case cmbType.text
Case “Subscribe”
// Basic required data
strinfo = strinfo + “&id=” + txtList.text
strinfo = strinfo + “&email[email]=” + txtEmail.text
// Add some optional data
'If txtFName.text <> “” Then
strinfo = strinfo + “&merge_vars[FNAME]=” + txtFName.text
'End If
If txtLName.text <> “” Then
strinfo = strinfo +"&merge_vars[LNAME]=" + txtLName.text
End If
// Add the optional double optin and update settings
strinfo = strinfo + “&double_optin=false&update_existing=true”
// Create the full URL with the base web address, the selected API option and string info
url = txtURL.text + “lists/subscribe.xml?” + strinfo
Case “List Lists”
url = txturl.text + “lists/list.xml?”+ strinfo
End Select
I had a look at Temboo and tembookit and they lost me a bit (I am a very part-time developer) so I looked at Brock’s code and it sort of worked for me but although I now know a lot more about dictionaries than I did I still had trouble with the JSON stuff so I tried the basic build a url method with the code below.
It works (and in my head makes sense) but is there a reason why I should not do it this way (security etc>)?[/quote]
Always happy to help the community
The only problem I see with your method is that you’re not calling EncodeURLComponent. If there is anything remotely special in your customer’s data then it will fail. (This function encodes special characters. In addition, it encodes the following characters: , / ? : @ & = + $ #)