Pre-Script call API

My question: Hi I have 2 API:

  1. Autentication API in which i fill all variables in the test section, expecially a _tokenAuth
  2. an api that use that token

My purpose is that any time I run the second API, the Api 1 is run before to the token variables.
Is possible to do this in Pre-Request Script? i didn’t find any function that allow me to call another API in the collection from there?

Hi @carlodellanno

You could try using something like this in your pre-req;

const options = {
    url: 'https://randomuser.me/api/',
    method: 'GET',
    header: {
        'Content-Type': 'application/json'
    }
}

pm.sendRequest(options, (error, response) => {
    if (error) throw new Error(error);
});
1 Like