Data
Type: Record<string, unknown> (get/set)
Mutable object bag for sharing structured, ephemeral data between scripts within one send. Starts as {} at the beginning of each send and threads through every script slot in execution order: collection pre-request → request pre-request → HTTP send → collection post-request → request post-request. Resets to {} on the next send.
Use hc.data for objects, arrays, mock fixtures, and other non-string state you want later scripts in the same send to read. Use variable bags when you need string values, {{key}} substitution in URLs/headers/body, or persistence to collection/environment/globals after the send.
You can mutate properties in place (hc.data.mocks = { user: { id: 123 } }) or replace the whole object (hc.data = { replaced: true }). Only structured data is supported — functions, class instances, and other non-cloneable values are not intended for this bag.
hc.data (get)
Available since v2.0.0
Returns the current data object. Mutations on the returned object are visible to later scripts in the same send.
hc.data.mocks = { user: { id: 123, name: "Ada" } };
hc.data.token = "abc";hc.data (set)
Available since v2.0.0
Replaces the entire data object. Non-object values reset the bag to {}.
Post-request script reading data set in an earlier pre-request script:
hc.data = { mocks: { user: { id: 123 } } };const user = hc.data.mocks.user;
hc.test("mock user name", function () {
hc.expect(user.name).to.equal("Ada");
});