Creating a Mandrill service

I am trying to connect to the Mandrill API, as a test I am setting up the ‘Ping2’ API call (https://mandrillapp.com/api/docs/users.JSON.html#method=ping2) to work through the API docs in dreamfactory. But I am struggling a bit.

I have taken the following steps:

  • Created a ‘Remote Web Service’, setting the ‘API Name’, ‘Name’, ‘Description’ and the ‘Base URL’ is https://mandrillapp.com/api/1.0

  • I have added an ‘Additional Parameters’ for the Mandrill API key, the values are Name = ‘key’ - Value = MY_API_KEY

  • I have added some Swagger in the ‘Service Definition’:

    {
    “apiVersion”: “1.0”,
    “swaggerVersion”: “1.1”,
    “basePath”: “https://mandrillapp.com/api/1.0/”,
    “apis”: [
    {
    “path”: “users/ping2.json”,
    “description”: “Users resources”,
    “operations”: [
    {
    “httpMethod”: “POST”,
    “summary”: “Ping test the Mandrill server”,
    “nickname”: “Ping2”,
    “parameters”: []
    }
    ]
    }
    ]
    }

When I go the the API Docs in my DPS I can see my service is defined with one POST method, inside that POST method there is only a ‘Try it out!’ button. When I click the button I would expect to get the correct response from the Mandrill server which is “PING”: “PONG!”. What I get though is:
‘Request URL’ = ‘https://mandrillapp.com:443/api/1.0/users/ping2.json
‘Response Body’ = ‘no content’
‘Response Code’ = ‘0’
‘Response Headers’ = ‘{}’

To test what is happening I have used the Postman extension for Chrome, I have made a simple request using: https://mandrillapp.com:443/api/1.0/users/ping2.json?key=MY_API_KEY - this gives me the desired results.

I do want to build more of the Mandrill API into my DSP but I figure I need to get the connection working first.

I would really appreciate any help getting this to work through dreamfactory.

Do you need to use Mandrill via their API rather than via SMTP? I signed up for Mandrill and got SMTP working within about 2 minutes. I will work on using the API as a remote web service and post here again with my results.

Tested sending an email via Mandrill’s API also. No issues calling /messages/send.json according to their API docs.

  1. Configured Remote Web Service:

  2. Called POST /rest/mandrillapi/messages/send.json with the following body:

     {
     "key": "hYn7IsUYWE7H6UlIfT_OEr",
     "message": {
         "html": "<p>Here is some text in the body.</p>",
         "subject": "This email was sent from DreamFactory",
         "from_email": "sender@dreamfactory.com",
         "from_name": "Jeffrey's DreamFactory",
         "to": [
             {
                 "email": "recipient@dreamfactory.com",
                 "name": "Jeffrey",
                 "type": "to"
             }
         ]
       }
     }
    
  3. Received the following response:

     [
        {
     	"email": "recipient@dreamfactory.com",
     	"status": "sent",
     	"_id": "45a30d2f8a5044618d40a8d24d7457b3",
     	"reject_reason": null
        }
     ]
    

The record of sending this email via the API is found in my Mandrill Dashboard.

Now I’ll try calling /users/ping2.json.

Also had no issues calling /users/ping2.json according to the Mandrill documentation.

  1. Using same Remote Web Service config as in #1 above.

  2. Called POST /rest/mandrillapi/users/ping2.json with the following body:

     {
         "key": "hYn7IsUYWE7H6UlIfT_OEr"
     }
    
  3. Received the following response:

     {
         "PING": "PONG!"
     }
    

The record of this API call is also found in my Mandrill Dashboard’s API Logs.

If you prefer to code these calls into Swagger, I recommend you check Swagger specifications. Note that "path" is based off the Base URL you’ve already specified, and that "basePath" does not need to be specified as all paths are relative. I believe by defining full paths for both values, you’re ending up calling https://mandrillapp.com/api/1.0/https://mandrillapp.com/api/1.0/users/ping2.json. This however is a Swagger issue, not a DreamFactory issue, as I’ve tested all functionality and DreamFactory is able to make the calls successfully.

To the first comment, the SMTP was not the correct option for what I needed. That was my initial thought.

I also had no issue sending via the API when I pass the ‘key’ as part of the json data. But it would be better if I didn’t have to have the API key in the client side of the application.
I have tried this: ‘https://mandrillapp.com/api/1.0/users/ping2.json?key=hYn7IsUYWE7H6UlIfT_OEr’ (with a valid API key) in the Postman chrome extension and it returns the desired result, I thought if I then set the API key as a parameter in dreamfactory I wouldn’t need to pass it with the json sent form the client application? (Although I could be completely wrong as I kind of new to this.)

Really appreciate all you have done to try and find me an answer.

I couldn’t find anywhere in the Mandrill API docs that they allowed passing parameters in the URL. In fact, all of their examples involved POSTing a JSON body. However, you’re right! It does work. In fact, it worked right away for me, so I’m not sure what may be causing your issue.

Using the exact same Remote Web Service config as this post above, calling the same /users/ping2.json endpoint as this post above, instead of passing any JSON body I added this config to the service:

It immediately worked when I called /rest/mandrillapi/users/ping2.json

{
    "PING": "PONG!"
}

I recommend checking your config again, because this was almost too easy to get working!