Send a request in pre-request with the API Key in the header

Ivonne
Wed, 10 Jan 2024 23:38:09 +0000
Help Hub

Hi

I want to send a request from the pre-request Script but my endpoint uses API Key as headers to access, so I have next:

and the next code

function sendRequest(name){
   pm.sendRequest({
        url:  (pm.collectionVariables.get("baseUrl") + "/companies"),
        method: 'POST',
        headers: {
            'sn-api-key': pm.collectionVariables.get("snApiKeyInternal"),
            'sn-api-secret': pm.collectionVariables.get("snApiSecretExternal")
  },
        body: {
            mode: 'raw',
            raw:JSON.stringify(name)
        }
    },(err,response) => {
        console.log(response);
    });
}

but I’m getting a 401 error. Any idea?

Thanks in advance.

4 posts - 4 participants