Class Item

Direct Known Subclasses:
ItemGroup, Request

public abstract class Item extends CollectionElement
Encapsulates the item object in the postman schema

Postman SDK analog: Item.

 {
    "name": "Get a list of facts",

    "event": [
        {
            "listen": "test",
            "script": {
                "exec": [
                    "pm.test(\"Status code is 200\", function () {",
                    "    pm.response.to.have.status(200);",
                    "});",
                    "",
                    "var latencyTestName = \"Response time is less than \" + pm.collectionVariables.get(\"latencyLimit\") + \" ms\";",
                    "",
                    "pm.test(latencyTestName, function () {",
                    "    pm.expect(pm.response.responseTime).to.be.below(parseInt(pm.collectionVariables.get(\"latencyLimit\")));",
                    "});",
                    "",
                    "pm.test(\"Response contains fact\", function () {",
                    "    var jsonData = pm.response.json();",
                    "    pm.expect(pm.response.json().length).to.be.greaterThan(1);",
                    "});"
                ],
                "type": "text/javascript"
            }
        },
        {
            "listen": "prerequest",
            "script": {
                "exec": [
                    "console.log(\"last fact: \" + pm.collectionVariables.get(\"curFact\"));"
                ],
                "type": "text/javascript"
            }
        }
    ],
    
    "request": {
        "method": "GET",
        "header": [
            {
                "key": "Accept",
                "value": "application/json"
            }
        ],
        "url": {
            "raw": "{{baseUrl}}/facts?max_length=200&limit=2",
            "host": [
                "{{baseUrl}}"
            ],
            "path": [
                "facts"
            ],
            "query": [
                {
                    "key": "max_length",
                    "value": "200"
                },
                {
                    "key": "limit",
                    "value": "2",
                    "description": "limit the amount of results returned"
                }
            ]
        },
        "description": "Returns a a list of facts"
    },
    "response": [
        {
            "name": "successful operation",
            "originalRequest": {
                "method": "GET",
                "header": [],
                "url": {
                    "raw": "{{baseUrl}}/facts?max_length=200&limit=2",
                    "host": [
                        "{{baseUrl}}"
                    ],
                    "path": [
                        "facts"
                    ],
                    "query": [
                        {
                            "key": "max_length",
                            "value": "200"
                        },
                        {
                            "key": "limit",
                            "value": "2"
                        }
                    ]
                }
            },
            "status": "OK",
            "code": 200,
            "_postman_previewlanguage": "json",
            "header": [
                {
                    "key": "Content-Type",
                    "value": "application/json"
                }
            ],
            "cookie": [],
            "body": "[\n  {\n    \"fact\": \"ex ad\",\n    \"length\": 200\n  }, (...)}\n]"
        }
    ]
}
],
"description": "Cat Facts"

}
Hierarchy

Folders and requests are both items. An item with no request property is rendered by the Postman UI as a Folder. Items with a request property are rendered as requests. Folders can contain other items, both folders and requests. Requests are always leaf nodes, they cannot contain other items.

A collection is the top level item in the hierarchy. It can contain a tree of items, but cannot itself be contained.

  • Constructor Details

    • Item

      protected Item()
    • Item

      protected Item(String name, ItemGroup parent)
      Construct an empty item with only a name property and assign it as a child of parent
      Parameters:
      name - The name of the object
      parent - The Item containing this item.
    • Item

      protected Item(String name)
      * Construct an empty item with only a name>; property. Once added to a Collection, the Postman UI will render this object as an empty folder.
      Parameters:
      name - The name of the object
  • Method Details

    • getDescription

      public String getDescription()
      Return the value of the description property
      Returns:
      String The description
    • setDescription

      public void setDescription(String description)
      Set the value of the description property
      Parameters:
      description - The description
    • getEvents

      public ArrayList<Event> getEvents()
      Return the ArrayList<Event> containing the objects comprising the event array
      Returns:
      ArrayList<Event>
    • getEvent

      public Event getEvent(enumEventType evtType)
      Get an event, specifying whether to return the pre-request script or test script associated with this item.
      Parameters:
      evtType - Enumerated value for the event type, eg., pre-request or test.
      Returns:
      Event The event, if it exists
    • setEvents

      public void setEvents(ArrayList<Event> events)
      Set the ArrayList<Event> comprising the values in the event array.
      Parameters:
      events -
    • setParent

      public void setParent(ItemGroup parent)
      Set the parent of this item.
      Parameters:
      parent - The parent item.
    • getParent

      public ItemGroup getParent()
      Get the parent of this item, or null if one is not defined (eg. this item is a collection);
      Overrides:
      getParent in class CollectionElement
      Returns:
      Item The parent item.
    • setPreRequestScript

      public void setPreRequestScript(String code)
      Set the pre-request script for this item in the event array
      Parameters:
      code - The source code for the script
    • getPreRequestScript

      public Event getPreRequestScript()
      Returns:
      Event
    • getTestScript

      public Event getTestScript()
      Returns:
      Event
    • setTestScript

      public void setTestScript(String code)
      Set the test script for this item in the event array
      Parameters:
      code - The source code for the script
    • getName

      public String getName()
      Returns:
      String
    • setName

      public void setName(String name)
      Parameters:
      name -
    • getKey

      public String getKey()
      Specified by:
      getKey in class CollectionElement
      Returns:
      String