<p>The plugin documentation is somewhat lacking, but based on the documentation that exists and looking at the plugin files, I believe a post request should take the following form:</p>

<pre><code>{% set response = craft.rest.request
.url('http://my.api.endpoint')
.method('post')
.headers({
    key: XXXXXXXXX,
    secret: XXXXXXXXX
})
.query({
    name: craft.request.getPost('name'),
    email: craft.request.getPost('email'),
    telephone: craft.request.getPost('telephone'),
    message: craft.request.getPost('message')
})
.send() %}
</code></pre>

<p>Unfortunately, I'm getting a 403 / Access denied response from the API.</p>

<p>I'm posting to the template containing this code from a form, hence the use of the <code>craft.request.getPost()</code> method.</p>

<p>If I send the same request using <a href="https://www.getpostman.com/" rel="nofollow noreferrer">Postman</a>, it works perfectly. So I know the problem is with the request and not the API.</p>

<p>Any advice much appreciated.</p>

<p><strong>Update:</strong> It seems that the headers are not arriving at the API end. If I remove the <code>.method('post')</code> parameter, the request works, albeit as a GET request with the data appended to the URL as a query string. So it seems that adding the <code>method</code> parameter is somehow interfering with the sending of the headers.</p>

CC BY-SA 3.0
2017-12-20T02:53:57.603Z
If it works with postman why don't you use this method instead? It's just that those third party related questions mostly won't receive an answer if it's not from the plugin developer itself
Robin Schambach
CC BY-SA 3.0
2017-12-20T09:17:14.490Z
Postman is a desktop REST client; it can't be used in the way you're suggesting. This is the first method the developer recommends for getting support. If they don't respond, I'll contact them directly.
Pete H
<plugins><post>
How do I send a POST request using the Dukt REST plugin?
# How do I send a POST request using the Dukt REST plugin?

(Asked by: username_0 on 2017-12-19)

The plugin documentation is somewhat lacking, but based on the documentation that exists and looking at the plugin files, I believe a post request should take the following form:
{% set response = craft.rest.request
.url('http://my.api.endpoint')
.method('post')
.headers({
    key: XXXXXXXXX,
    secret: XXXXXXXXX
})
.query({
    name: craft.request.getPost('name'),
    email: craft.request.getPost('email'),
    telephone: craft.request.getPost('telephone'),
    message: craft.request.getPost('message')
})
.send() %}

Unfortunately, I'm getting a 403 / Access denied response from the API.
I'm posting to the template containing this code from a form, hence the use of the craft.request.getPost() method.
If I send the same request using Postman, it works perfectly. So I know the problem is with the request and not the API.
Any advice much appreciated.
Update: It seems that the headers are not arriving at the API end. If I remove the .method('post') parameter, the request works, albeit as a GET request with the data appended to the URL as a query string. So it seems that adding the method parameter is somehow interfering with the sending of the headers.

**Tags:** plugins, post
> **Comments:**
> **username_1**: If it works with postman why don't you use this method instead? It's just that those third party related questions mostly won't receive an answer if it's not from the plugin developer itself  
> **username_0**: Postman is a desktop REST client; it can't be used in the way you're suggesting. This is the first method the developer recommends for getting support. If they don't respond, I'll contact them directly.  

---

## 0 answers

