Answers.Body: <p>Two things I'm noticing about your code snippet:</p>
  
  <ol>
  <li><p>You'll want to use <code>POST</code> per the <a href="https://mandrillapp.com/api/docs/index.JSON.html" rel="nofollow noreferrer">Mandrill API docs</a>.</p>
  
  <blockquote>
    <p>All API calls should be made with HTTP POST.</p>
  </blockquote></li>
  <li><p>The options object should only contain <a href="http://docs.guzzlephp.org/en/stable/request-options.html" rel="nofollow noreferrer">valid Guzzle request options</a> (<code>key</code> is not an actual request option); I think what you're trying to do is pass your <code>key</code> parameter in the request body. There are multiple options for sending data in the request body (<code>form_params</code>, <code>body</code>, <code>json</code>, or <code>multipart</code>), but since the Mandrill API is expecting a json request body we'll use the <code>json</code> option like so:</p>
  
  <pre><code>{% set options = {
    json: {
      key: 'REDACTED',
    }
  } %}
  </code></pre></li>
  </ol>
  
  <hr>
  
  <p>All together, this should give you a working API call:</p>
  
  <pre><code>{% 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) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-01T17:46:09.210Z
Answers.Text: That did the trick! Thank you so much.
Answers.UserDisplayName: Katie Fritz
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-31T16:20:36.317Z
Answers.LastActivityDate: 2019-10-31T16:20:36.317Z
Answers.UserDisplayName: Jalen Davenport
Body: <p>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.</p>
  
  <p>To test the setup, I'm just trying to ping Mandrill, according to the /users/ping.json call: <a href="https://mandrillapp.com/api/docs/users.JSON.html#method=ping" rel="nofollow noreferrer">https://mandrillapp.com/api/docs/users.JSON.html#method=ping</a>. </p>
  
  <p>I've tried a bunch of variations, but I keep getting this error:</p>
  
  <pre><code>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"
  }
  </code></pre>
  
  <p>According to <a href="https://stackoverflow.com/questions/17700002/mandrill-validationerror">this answer</a> (admittedly from 2013), "This particular error is common if the JSON is invalid for some reason."</p>
  
  <p>I've looked at <a href="https://craftcms.stackexchange.com/questions/29630/fetching-displaying-an-api-request-using-fetch">Jalen's excellent answer on another Fetch question</a>, but that's for a different API and I'm not sure what to do.</p>
  
  <p>Here's my current code:</p>
  
  <pre><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) %}
  </code></pre>
  
  <p>I've also tried it with POST, and with various permutations of quotes around the key and api key; same error.</p>
  
Tags: <templating><craft3><mandrill><api>
Title: How to correctly format API requests for Mandrill using Fetch plugin? Getting error "you must specify a key value"
ThreadText: # How to correctly format API requests for Mandrill using Fetch plugin? Getting error "you must specify a key value"
  
  (Asked by: username_0 on 2019-10-31)
  
  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](https://stackoverflow.com/questions/17700002/mandrill-validationerror) (admittedly from 2013), "This particular error is common if the JSON is invalid for some reason."
  
  I've looked at [username_1's excellent answer on another Fetch question](https://craftcms.stackexchange.com/questions/29630/fetching-displaying-an-api-request-using-fetch), 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.
  
  **Tags:** templating, craft3, mandrill, api
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-10-31. Score: 2 | Accepted answer
  
  Two things I'm noticing about your code snippet:
  
  1. You'll want to use `POST` per the [Mandrill API docs](https://mandrillapp.com/api/docs/index.JSON.html).
  
     > All API calls should be made with HTTP POST.
  2. The options object should only contain [valid Guzzle request options](http://docs.guzzlephp.org/en/stable/request-options.html) (`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) %}
  
  ```
  
  > **Comments:**
  > **username_0**: That did the trick! Thank you so much.  
  
  ---
  
  