Hello, I’m new to Postman and API Testing. I’m trying to create a pre-request script to get access token automatically for a Postman collection using Dropbox APIs. However, it didn’t work well.
From what I understand, first I need an authorization code, and after that using that authorization code to get the access token. However, I can’t find a way to automate these 2 processes in one script.
This is my script in Postman:
pm.sendRequest(
{
url: pm.variables.get("Access_token_url"),
method: "POST",
header: {
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": pm.variables.get("Auth_url"),
},
body: {
mode: "urlencoded",
urlencoded: [
{ key: "grant_type", value: "refresh_token", disabled: false },
{
key: "client_id",
value: pm.variables.get("App_key"),
disabled: false,
},
{
key: "client_secret",
value: pm.variables.get("App_secret"),
disabled: false,
},
{
key: "refresh_token",
value: pm.variables.get("refresh_token"),
disabled: false,
},
],
},
},
(err, res) => {
console.log(res.json());
}
);
If I try this way, I will get an error like this:
error_description: “Can’t use “Authorization” header and “client_secret” arg together.”}
Could anyone help me to fix this problem ? Cause later I need to run this collection with command line using Newman to pass all the tests.
Thanks in advance