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.