Im using the developer platform to build a zapier integration with an API that uses OAuth2 authorisation however am struggling.
The API in question uses 4 bit of information to obtain an access token:
- client_id
- client_secret
- username
- password
The client_id and secret are fixed - they will be set in the Zapier integration and used every time. The username and password will need to be gathered by zapier then added to the request whenever someone wants to authenticate.
I can run a curl request and am successful in returning a result:
curl -XPOST -H 'Accept:application/json' -d 'grant_type=password&client_id=xxxxxxxx&client_secret=xxxxxxxxxxx&username=person@domain.com&password=MyPassword!' https://myAPIdomain.com/v1/auth/token
I have tried configuring this with both Oauthv2 and Session Auth however always get the same error "Invalid grant_type parameter or parameter missing"
My config for Session Auth:
HTTP Headers are content-type = application/x-www-form-urlencoded and accept = application/json.
If i switch to code mode its the following:
const options = {
url: 'https://myAPIdomain.com/v1/auth/token',
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded',
'accept': 'application/json'
},
params: {
'grant_type': 'password',
'client_id': 'xxxxxxx',
'client_secret': 'xxxxxxx',
'username': bundle.authData.username,
'password': bundle.authData.password
},
body: {
}
}
return z.request(options)
.then((response) => {
response.throwForStatus();
const results = response.json;
// You can do any parsing you need for results here before returning them
return {
'sessionKey': results.sessionKey
};
});
What am i doing wrong?! Please help!