Raw json body how to add variable?

Hi! I am in a similar situation, but this didn’t completely work for me. I have my request in a folder that contains a pre-request script to calculate an HMAC over the request’s body.

What seems to happen is that the pre-request script of the request is run after the pre-request of the folder, so I tried moving the

pm.collectionVariables.set('shopName', pm.environment.get('shopName'));

to the first line of the folder’s pre-request script but that still didn’t work.

This is what the pre-request script of the folder looks like:

const input = request.data;
const key = pm.environment.get("key");
const hmac = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(input, key));
pm.environment.set("hmac",hmac)

Like I said, using the collectionVariables.set at the beginning of the script didn’t work. What worked was changing the first line to:

const input = request.data.replace("{{shopName}}",pm.environment.get("shopName"));

What is the best approach in a situation like this?