Calling Mailchimp - Mandrill API

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Calling Mailchimp - Mandrill API

Post by serge_girard »

Hello,

Anybody has experience with calling API from Mandrill (see https://www.mandrill.com/) ?
I will need to send email through this API and I don't know how to start.


Thx,

Serge
There's nothing you can do that can't be done...
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Calling Mailchimp - Mandrill API

Post by edk »

Hi Serge.

I think, you can use cUrl to connect with Mandrill API.
I don't have a valid API key to check it out, but maybe try this, on the example https://mandrillapp.com/api/docs/users. ... thod=ping2

Code: Select all

#include "hmg.ch"
#include "hbcurl.ch"
#include "common.ch"

Function Main()

DEFINE WINDOW Mandrill_Curl AT 0 , 0 WIDTH 0 HEIGHT 0 TITLE "" MAIN;
   ON INIT (Mandrill_Curl(), ThisWindow.Release);
   NOSHOW; 
   NOMINIMIZE; 
   NOMAXIMIZE; 
   NOSIZE; 
   NOSYSMENU; 
   NOCAPTION
END WINDOW
ACTIVATE WINDOW Mandrill_Curl

QUIT 
Return Nil

****************************************************************************************
Function Mandrill_Curl()

Local cURL:="https://mandrillapp.com/api/1.0/users/ping2.json"
Local cAPIKey:='example key'
Local cPOSTdata:='{"key":"' + cAPIKey + '"}'

//Init
Local curlHandle := curl_easy_init()
IF EMPTY(curlHandle)
	MsgStop("Error while init cURL lib.")
	RETURN 
ENDIF


curl_easy_reset( curlHandle )

curl_easy_setopt(curlHandle, HB_CURLOPT_URL, cURL)
curl_easy_setopt(curlHandle, HB_CURLOPT_SSL_VERIFYPEER, 0 )
//curl_easy_setopt(curlHandle, HB_CURLOPT_PORT, nPort)
	
curl_easy_setopt(curlHandle, HB_CURLOPT_USERAGENT, "Mandrill-Curl/1.0" )
curl_easy_setopt(curlHandle, HB_CURLOPT_POSTFIELDSIZE, LEN( cPOSTdata ) )
curl_easy_setopt(curlHandle, HB_CURLOPT_POSTFIELDS, cPOSTdata )
 
curl_easy_setopt(curlHandle, HB_CURLOPT_DOWNLOAD )
curl_easy_setopt(curlHandle, HB_CURLOPT_DL_BUFF_SETUP )

/* Do everything */
curlErr := curl_easy_perform(curlHandle)
	
/* Report any errors */
IF !EMPTY( curlErr )
	MsgStop(curl_easy_strerror(curlErr))
ELSE
	//Response from the server
	MsgInfo(curl_easy_dl_buff_get( curlHandle ))
ENDIF

//Close
curl_global_cleanup( curlHandle )


RETURN 
*****************************************************************************************
mandrill.7z
(2.34 MiB) Downloaded 206 times
I get a response from the server that I did not provide the valid API key.


If you just want to send an emails, maybe just use SMTP: https://mandrill.zendesk.com/hc/en-us/a ... -Languages

It looks like a simple mechanism for sending email messages.
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Calling Mailchimp - Mandrill API

Post by serge_girard »

Thanks a lot !

I will receive my key this afternoon. The meaning is to send daily some 100-200 emails. Do you advice API or SMTP solution?

Serge
There's nothing you can do that can't be done...
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Calling Mailchimp - Mandrill API

Post by edk »

It depends on what you want to achieve, e.g. whether you want to receive statistics or just send email messages. I think that just SMTP is enough to send messages.
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Calling Mailchimp - Mandrill API

Post by serge_girard »

Hi Krzysztof,

See private messages !

Greetings, Serge
There's nothing you can do that can't be done...
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Calling Mailchimp - Mandrill API

Post by edk »

Serge, I'm attaching binary of curl.
I also receive the same message from my tests:
c: \ curl-7.53.1-win32-mingw \ bin> curl -A 'Mandrill-Curl / 1.0' -d '{"key": "example key"}' https://mandrillapp.com/api/1.0 /users/ping2.json

{"status": "error", "code": - 1, "name": "ValidationError", "message": "You must specify
a key value "}
c: \ curl-7.53.1-win32-mingw \ bin>
Instead of "example key" use your key.

'https://mandrillapp.com/api/1.0/users/ping.json' can not be in apostrophes, as shown in the example.

It looks as if the example from https://mandrillapp.com/api/docs/users. ... ethod=ping did not work, try to contact the support.
Attachments
curl-7.53.1-win32-mingw.7z
(1.67 MiB) Downloaded 194 times
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Calling Mailchimp - Mandrill API

Post by serge_girard »

OK, thanks!

I keep you informed!

Serge
There's nothing you can do that can't be done...
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Calling Mailchimp - Mandrill API

Post by serge_girard »

Hello Krzysztof,

It seems my MailChimp account is not OK for Mandrill use.... I wait till next week!
Thanks !

Serge
There's nothing you can do that can't be done...
Post Reply