Parameter with "-" character in name throwing error

I am writing a script to set environmental variables for a step 2 request.

This is giving me an error claiming “ReferenceError: amz is not defined”.

let response = pm.response.json();
 pm.environment.set("encryption", response.form_data.x-amz-server-side-encryption);
pm.environment.set("url",response.url);
pm.environment.set("key", response.form_data.key);

It will set the url and key if I comment out the attempt to set encryption.
Is there a way to escape or deal with the minus sign? I am assuming it is attempting to do math on my parameter name?

The body of the request comes back looking like this:

{
    "url": "https://salsify-dandelion.s3-external-1.amazonaws.com",
    "form_data": {
        "key": "1/20858/user_data_import/1/2024/10/15/18:42:34-ca73333010",
        "x-amz-server-side-encryption": "aws:kms",
        "acl": "private",
        "policy": "xxxhiddenfromyourviewxxx",
        "x-amz-credential": "xxxnotshowingthiseitherxxx",
        "x-amz-algorithm": "AWS4-HMAC-SHA256",
        "x-amz-date": "20241015T1842114Z",
        "x-amz-signature": "xxxreplacedxxx"
    }
}

Hey @AIRWIN :wave:t2:

When you have characters such as - in the property names, you need to use bracket notation to reference those:

pm.environment.set("encryption", response.form_data["x-amz-server-side-encryption"]);
1 Like

Thank you. I will give this a try.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.