1

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.

  • 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 – Robin Schambach Dec 20 '17 at 2:53
  • 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 Dec 20 '17 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.