How to correctly format API requests for Mandrill using Fetch plugin? Getting error "you must specify a key value" I want to use the Fetch plugin (v 1.2.0; Craft Pro 3.3.13) to send messages from a Twig template in some circumstances.

To test the setup, I'm just trying to ping Mandrill, according to the /users/ping.json call: https://mandrillapp.com/api/docs/users.JSON.html#method=ping. 

I've tried a bunch of variations, but I keep getting this error:

1 - Server error: 
`GET https://mandrillapp.com/api/1.0/users/ping.json` 
resulted in a `500 Internal Server Error` response:
{
  "status":"error",
  "code":-1,
  "name":"ValidationError",
  "message":"You must specify a key value"
}


According to this answer (admittedly from 2013), "This particular error is common if the JSON is invalid for some reason."

I've looked at Jalen's excellent answer on another Fetch question, but that's for a different API and I'm not sure what to do.

Here's my current code:

      {% set client = {
          base_uri : 'https://mandrillapp.com/api/1.0/',
          timeout : 10
        } %}


        {% set options = {
          key: 'REDACTED',
        } %}

        {% set destination = 'users/ping.json' %}

        {% set request = fetch(client, 'GET', destination, options) %}


I've also tried it with POST, and with various permutations of quotes around the key and api key; same error.
Two things I'm noticing about your code snippet:


You'll want to use POST per the Mandrill API docs.


  All API calls should be made with HTTP POST.

The options object should only contain valid Guzzle request options (key is not an actual request option); I think what you're trying to do is pass your key parameter in the request body. There are multiple options for sending data in the request body (form_params, body, json, or multipart), but since the Mandrill API is expecting a json request body we'll use the json option like so:

{% set options = {
  json: {
    key: 'REDACTED',
  }
} %}





All together, this should give you a working API call:

{% set client = {
  base_uri: 'https://mandrillapp.com/api/1.0/',
  timeout: 10
} %}


{% set options = {
  json: {
    key: 'REDACTED',
  }
} %}

{% set destination = 'users/ping.json' %}

{% set request = fetch(client, 'POST', destination, options) %}