0

I have a code in zapier:

var username = "username"
var password = "password"
var grant_type = "password"
var client_id = "id"
var ENDPOINT="someUrl"
var json = {
      "grant_type": grant_type,
      "username": username,
      "password": password,
      "client_id": client_id
};
var options={
  method:"POST",
  headers: {
   'Accept': 'application/json',
   'Content-Type': 'application/json'
  },
  payload:json
}
const result = await fetch(WAVITY_ENDPOINT,options)
const content = await result.json()
output={response:content}

But I am always getting Unauthorized error. I do the same through request module and it works. I think fetch is not sending the data. Any help would be appreciated.In my request module code, I have following options:

headers: {
        connection: "Keep-Alive",
        timeout: 5000
      },
      url: ENDPOINT,
      method: 'POST',
      formData: {
        'grant_type': grant_type,
        'username': username,
        'password': password,
        'client_id': client_id
      }

NOTE: Changing the headers of fetch to headers like in request also does not work for me.

Ujwal
  • 73
  • 1
  • 12
  • 1
    Just want a small check first that your variable for the endpoint used in fetch is the same as the variable stated at line 5 (you stated "ENDPOINT" at line 5, and then later referred to it as WAVITY_ENDPOINT) – will-yama Jul 15 '18 at 15:17

1 Answers1

1

Per this question about fetch, I believe the key for the data should be body, not payload.

Zapier uses node-fetch (source), so if you can get it working locally with that, you'll be able to paste it into Zapier successfully.

xavdid
  • 5,092
  • 3
  • 20
  • 32