'Postman pre-script into codeigniter web development script (pm.sendrequest)
actually i tried to automate the access token of POST api using Postman. so the pre-request script is working well in Postman.
So, now i'm trying to use the code in my web application that using a codeigniter framework. Below is the code that i'm using.
let getTokenRequest = {
method: 'POST',
url: tokenUrl,
auth: {
type: "basic",
basic: [
{ key: "username", value: clientId },
{ key: "password", value: clientSecret }
]
},
body: {
mode: 'formdata',
formdata: [
{ key: 'grant_type', value: 'client_credentials' },
{ key: 'scope', value: scope }
]
}
};
pm.sendRequest(getTokenRequest, (err, response) => {
let jsonResponse = response.json(),
newAccessToken = jsonResponse.access_token;
console.log({ err, jsonResponse, newAccessToken });
pm.environment.set('accessToken', newAccessToken);
pm.variables.set('accessToken', newAccessToken);
});
but then i ended up with this error.
Uncaught ReferenceError: pm is not defined
Tried to figure out but couldn't find the solution. hope someone can guide me well because i'm still learning in web development.
or maybe someone can show me how to get the pre-request script into the curl if that even possible?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
