Getting syntax error only on linux

Are there any syntax differences I should be aware of with Newman on Linux?

I can run my collection in the collection runner on the Windows app, with the Windows Newman cli, but when I try to run in on Linux I get

  1. SyntaxError
    Unexpected token .
    at prerequest-script
    inside “Collection Utilities / Auth / Retrieve New Token”
    There is nothing in the pre-request tab on Auth, or Retrieve New Token, however I have a ton of code in the collection level pre-request tab. It runs fine from the app, and I really have no idea what could be causing the issue.

Hello, I am having the same issue. Some code in pre-request script and everything works like a charm on my Windows computer (Postman and Newman) but once I try to execute with Newman inside a Linux Jenkins Server Pipeline it raises an “Unexepected { token”.

Have you managed to solve it?

Thank you in advance.

@daviddealvaradolacru

Without seeing the code, it will be difficult to give you any guidance.

My first through would be file paths if you have any.

Can you get it to run on Linux outside of a pipeline?

I don’t have access to a Linux machine ATM but I will try to get access to one of them to test it.

This is the code. The first part are global functions I placed here to reuse them. The second part is the JWT token generation part.

Thank you in advance

/******************************************
     GLOBAL FUNCTIONS USED IN ALL TESTS
******************************************/

utils = {

    validate_response_code: function(pm, expected_code) {
        pm.response.to.have.status(expected_code)
    },

    validate_response_is_json: function validate_response_is_json(pm)
    {
        var json_response = null;
        try
        {
            json_response = pm.response.json();
        } catch {
            json = null;
        } finally {
            console.log(json_response);
            pm.expect(json_response).not.eq(null);
        }
    },

    validate_response_is_not_json: function validate_response_is_not_json(pm)
    {
        var json_response = null;
        try
        {
            json_response = pm.response.json();
        } catch {
            json = null;
        } finally {
            console.log(json_response);
            pm.expect(json_response).eq(null);
        }
    },

    validate_schema: function validate_schema(pm, schema)
    {
        var response_data = pm.response.json();
        var Ajv = require("ajv");
        var ajv = new Ajv({logger: console}, schema);
        pm.expect(ajv.validate(schema, pm.response.json()), JSON.stringify(ajv.errors)).to.be.true;
    },

    get_error_schema: function get_error_schema()
    {
        const schema = {
	        "type": "object",
	        "properties": {
                "timestamp": {
                    "type": "string"
                },
                "status": {
                    "type": "integer"
                },
                "error": {
                    "type": "string"
                },
                "message": {
                    "type": "string"
                },
                "path": {
                    "type": "string"
                }
            },
            "required": [
                "timestamp",
                "status",
                "error",
                "message",
                "path"
            ]
        };
        return schema;
    }
}

/******************************************
END OF GLOBAL FUNCTIONS USED IN ALL TESTS
******************************************/

// Local use variables
var is_patch_ok = false;
var is_post_ok = false;
var token = null;

// Environment variables
var debug = pm.environment.get("debug");
var host_sts = pm.environment.get("host_sts");
var client_id = pm.environment.get("client_id");
var client_secret = pm.environment.get("client_secret");
var admin_user_id_sts = pm.environment.get("admin_user_id_sts");
var admin_user_password_sts = pm.environment.get("admin_user_password_sts");

// Iteration data variables
// If not set in iteration data, we are executing this in Postman, so we get the value from environment
var user_global_id = pm.iterationData.get("user_global_id");
if (user_global_id === undefined)
{
    user_global_id = pm.environment.get("user_global_id");
}

// Calculated variables
var url = host_sts + "/admin/client/" + client_id;
var basic_auth = admin_user_id_sts + ":" + admin_user_password_sts;
var auth_header = "Basic " + CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(basic_auth));

// Variable logs
if (debug == "true")
{
    console.log(client_id);
    console.log(client_secret);
    console.log(admin_user_id_sts);
    console.log(admin_user_password_sts);
    console.log(basic_auth);
    console.log(url);
    console.log(auth_header);
}
// START STEP 1 (PATCH) EXECUTION
pm.sendRequest({
    url: url,
    method: 'PATCH',
    header: {
        'Authorization': auth_header,
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    body: {
        mode: 'raw',
        raw: JSON.stringify(
            {
                userId: user_global_id,
                extraClaims: {
                    sec_mode: "platform",
                    country: "XXX",
                    local_realm: "XXX"
                },
                audience: [
                    "XXX"
                ]
            }
        )
    }
}, function (err, res) {
    if(res.code === 204)
    {
        if (debug == "true")
        {
            console.log("\tPATCH execution succeeded");
        }
        // Execute Step 2 of authentication once the first request is complete and correct
        // Calculated variables
        let url = host_sts + "/tokens/jwt/generic";
        let basic_auth = client_id + ":" + client_secret;
        let auth_header = "Basic " + CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(basic_auth));
        if (debug == "true")
        {
            console.log(basic_auth);
            console.log(url);
            console.log(auth_header);
        }
        pm.sendRequest({
        url: url,
        method: 'POST',
        header: {
            'Authorization': auth_header,
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
        body: {
            mode: 'raw',
            raw: JSON.stringify(
                {
                    userId: client_id,
                    extraClaims: {
                        sec_mode: "platform",
                        country: "XXX",
                        local_realm: "XXX"
                    },
                    audience: [
                        "XXX"
                    ]
                }
            )
        }
        }, function (err, res) {
            if(res.code === 200)
            {
                let response = res.json();
                is_post_ok = true;
                let token = response.token;
                // Save the token to environment for further uses
                token = "Bearer " + token;
                pm.environment.set("token", token);
                if (debug == "true")
                {
                    console.log(token);
                }
            } else {
                console.log("\t\tError executing POST.")
                console.log(res);
                console.log(err);
            }
        });
    } else {
        console.log("\tError executing PATCH.")
        console.log(res);
        console.log(err);
    }
});

I can’t see anything obvious. You don’t have any paths as far as I can tell.

You are writing a fair bit to the console.

Is anything getting output in the console history to tell you which part of the code its failing on, or is the script just failing to run altogether.