Pm is not defined?

When I type the script into the pre-request script tab then show this message:
there was an error evaluating the pre-request script pm is not defined

My script is:

let tokenUrl = '****/connect/token';
let clientId = " ****";
let clientSecret = ' ****';

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' }
        ]
    }
};

pm.sendRequest(getTokenRequest, (err, response) => {
    let newAccessToken = response.json().access_token;
    pm.environment.set('accessToken', newAccessToken);
    pm.variables.set('accessToken', newAccessToken);
});

How to or where use my code? Please help me.

Hey @gain-server,

Welcome to the Community! :wave:

Are you able to attached some screenshots to the question please? You can mask the sensitive data before posting, it’s just to get a view on what’s going on in the app.

Which version of the app and on what platform are you using?

Thank you for reply @dannydainton. It’s solved by desktop app used.

1 Like