ItemGroup

ItemGroup

new ItemGroup(definitionopt)

An ItemGroup represents a composite list of Item or ItemGroup. In terms of Postman App, ItemGroup represents a "Folder". This allows one to group Items into subsets that can have their own meaning. An ItemGroup also allows one to define a subset of common properties to be applied to each Item within it. For example, a test event defined on an ItemGroup is executed while testing any Item that belongs to that group. Similarly, ItemGroups can have a common {@RequestAuth} defined so that every Request, when processed, requires to be authenticated using the auth defined in the group.

Essentially, Collection too is a special type of ItemGroup ;-).

Parameters:
Name Type Attributes Description
definition ItemGroup.definition <optional>

While creating a new instance of ItemGroup, one can provide the initial configuration of the item group with the requests it contains, the authentication applied to all requests, events that the requests responds to, etc.

Source:
Example

Add a new ItemGroup to a collection instance

var Collection = require('postman-collection').Collection,
    ItemGroup = require('postman-collection').ItemGroup,
    myCollection;

myCollection = new Collection(); // create an empty collection
myCollection.items.add(new ItemGroup({ // add a folder called "blank folder"
    "name": "This is a blank folder"
}));

Extends

Members

auth :RequestAuth

One can define the default authentication method required for every item that belongs to this list. Individual Requests can override this in their own definitions. More on how to define an authentication method is outlined in the RequestAuth property.

Type:
Source:
Example

Define an entire ItemGroup (folder) or Collection to follow Basic Auth

var fs = require('fs'),
    Collection = require('postman-collection').Collection,
    RequestAuth = require('postman-collection').RequestAuth,
    mycollection;

// Create a collection having two requests
myCollection = new Collection();
myCollection.items.add([
    { name: 'GET Request', request: 'https://postman-echo.com/get?auth=basic' },
    { name: 'PUT Request', request: 'https://postman-echo.com/put?auth=basic' }
]);

// Add basic auth to the Collection, to be applied on all requests.
myCollection.auth = new RequestAuth({
    type: 'basic',
    username: 'postman',
    password: 'password'
});

authorizeRequestsUsing

Sets authentication method for all the items within this group

Source:

disabled :Boolean

This (optional) flag denotes whether this property is disabled or not. Usually, this is helpful when a property is part of a PropertyList. For example, in a PropertyList of Headers, the ones that are disabled can be filtered out and not processed.

Type:
  • Boolean
Inherited From:
Source:

id :String

The id of the property is a unique string that identifies this property and can be used to refer to this property from relevant other places. It is a good practice to define the id or let the system auto generate a UUID if one is not defined for properties that require an id.

Type:
  • String
Inherited From:
Source:

items :PropertyList.<(Item|ItemGroup)>

This is a PropertyList that holds the list of Items or ItemGroups belonging to a Collection or to an ItemGroup. Operation on an individual item in this list can be performed using various functions available to a PropertyList.

Type:
Source:
Example

Fetch empty ItemGroups in a list loaded from a file

var fs = require('fs'), // needed to read JSON file from disk
    Collection = require('postman-collection').Collection,
    myCollection,
    emptyGroups;
// Load a collection to memory from a JSON file on disk (say, sample-collection.json)
myCollection = new Collection(JSON.stringify(fs.readFileSync('sample-collection.json').toString()));

// Filter items in Collection root that is an empty ItemGroup
emptyGroups = myCollection.items.filter(function (item) {
    return item && item.items && (item.items.count() === 0);
});

// Log the emptyGroups array to check it's contents
console.log(emptyGroups);

name :String

A property can have a distinctive and human-readable name. This is to be used to display the name of the property within Postman, Newman or other runtimes that consume collection. In certain cases, the absence of name might cause the runtime to use the id as a fallback.

Type:
  • String
Inherited From:
Source:

protocolProfileBehavior :Object

Set of configurations used to alter the usual behavior of sending the request.

Type:
  • Object
Properties:
Name Type Description
disableBodyPruning Boolean

Disable body pruning for request methods like GET, HEAD etc.

Source:

Methods

(static) isItemGroup(obj) → {Boolean}

Check whether an object is an instance of ItemGroup.

Parameters:
Name Type Description
obj *
Source:
Returns:
Type
Boolean

describe(content, typeopt)

This function allows to describe the property for the purpose of detailed identification or documentation generation. This function sets or updates the description child-property of this property.

Parameters:
Name Type Attributes Default Description
content String

The content of the description can be provided here as a string. Note that it is expected that if the content is formatted in any other way than simple text, it should be specified in the subsequent type parameter.

type String <optional>
"text/plain"

The type of the content.

Inherited From:
Source:
Example

Add a description to an instance of Collection

 var Collection = require('postman-collection').Collection,
    mycollection;

// create a blank collection
myCollection = new Collection();
myCollection.describe('Hey! This is a cool collection.');

console.log(myCollection.description.toString()); // read the description

findInParents(property, customizeropt) → {*|undefined}

Tries to find the given property locally, and then proceeds to lookup in each parent, going up the chain as necessary. Lookup will continue until customizer returns a truthy value. If used without a customizer, the lookup will stop at the first parent that contains the property.

Parameters:
Name Type Attributes Description
property String
customizer function <optional>
Inherited From:
Source:
Returns:
Type
* | undefined

forEachParent(options, iterator)

Invokes the given iterator for every parent in the parent chain of the given element.

Parameters:
Name Type Description
options Object

A set of options for the parent chain traversal.

Properties
Name Type Attributes Default Description
withRoot Boolean <optional>
<nullable>
false

Set to true to include the collection object as well.

iterator function

The function to call for every parent in the ancestry chain.

Inherited From:
Source:
To Do:
  • Cache the results

meta() → {*}

Returns the meta keys associated with the property

Inherited From:
Source:
Returns:
Type
*

oneDeep(idOrName)

Finds the first item with the given name or id in the current ItemGroup.

Parameters:
Name Type Description
idOrName String
Source:

parent() → {*|undefined}

Returns the parent of item

Inherited From:
Source:
Returns:
Type
* | undefined

toJSON()

Returns the JSON representation of a property, which conforms to the way it is defined in a collection. You can use this method to get the instantaneous representation of any property, including a Collection.

Inherited From:
Source:

Type Definitions

definition

The following defines the object (or JSON) structure that one can pass to the ItemGroup while creating a new ItemGroup instance. This is also the object structure returned when .toJSON() is called on an ItemGroup instance.

Properties:
Name Type Attributes Description
item Array.<(ItemGroup.definition|Item.definition)> <optional>
auth RequestAuth.definition <optional>
event Array.<Event.definition> <optional>
Source:
Example
{
    "name": "Echo Get Requests",
    "id": "echo-get-requests",
    "item": [{
        "request": "https://postman-echo.com/get"
    }, {
        "request": "https://postman-echo.com/headers"
    }],
    "auth": {
        "type": "basic",
        "basic": {
            "username": "jean",
            "password": "{{somethingsecret}}"
        }
    },
    "event": [{
        "listen": "prerequest",
        "script": {
            "type": "text/javascript",
            "exec": "console.log(new Date())"
        }
    }]
}