1
votes

I'm trying to create an environment file in Postman using the Postman API by referring to their API documentation

POST route - https://api.getpostman.com/environments

Request Headers - Content-type and API key

Request Body -

{
    "type": "object",
    "properties": {
        "environment": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string",
                    "maxLength": 254,
                    "minLength": 1
                },
                "values": {
                    "type": "array",
                    "maxItems": 100,
                    "additionalItems": false,
                    "items": {
                        "type": "object",
                        "properties": {
                            "key": {
                                "type": "string",
                                "maxLength": 254
                                "minLength": 1
                            },
                            "value": { "type": "string" },
                            "enabled": { "type": "boolean" }
                        },
                        "required": ["key", "value"]
                    }
                }
            },
            "required": ["name"]
        }
    },
    "required": ["environment"]
}

But the response is returning this message:

{
    "error": {
        "name": "malformedRequestError",
        "message": "Missing required property: environment"
    }
}

Am I missing anything?

2

2 Answers

3
votes

If you use the other sample body on the API docs and edit the details, this should work for you. The example you used is just telling you the schema information from what I can see.

{
    "environment": {
        "name": "My New Environment",
        "values": [
            {"key": "variable_name_1", "value": "my_value"},
            {"key": "variable_name_2", "value": "my_other_value"}
        ]
    }
}

enter image description here

0
votes
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("token", jsonData.token);