Get dan Set Variable Header Postman Request
Berikut ini adalah contoh set header sebelum request:
const this_data = JSON.parse(pm.request.body.raw)
const ref_id = this_data.ref_id
const merchant_id = pm.variables.get('merchant_id');
const secret = pm.variables.get('secret');
const sign_str = `${secret}-${merchant_id}-${ref_id}`;
const signature = CryptoJS.MD5(sign_str).toString();
pm.request.headers.add({
key: "HTTP-X-APPAPI-AUTHORIZATION",
value: signature
});
Berikut ini adalah contoh set variable setelah request, bisa digunakan untuk men-set token yang didapat dari authentikasi sebelumnya:
var jsonData = JSON.parse(responseBody);
pm.collectionVariables.set('token', jsonData.token);
Berikut ini adalah contoh untuk memasukkan request header untuk basic auth dengan custom header name ApiKey
// Define your login and password
const login = pm.variables.get('login');
const password = pm.variables.get('password');
// Encode the login and password in Base64
const encodedCredentials = btoa(`${login}:${password}`);
console.log(encodedCredentials)
// Set the ApiKey header with the encoded value
pm.request.headers.add({
key: 'ApiKey',
value: encodedCredentials
});