1. Groups
  2. Create & Update Groups

Groups

Create & Update Groups

Create Group(s)

POST
`/v1/groups`

This API will allow you to create a single group using a traditional REST approach.

Create Single Group

The only required property for a group is the name and resource type (location or contact)

js
        const data = {
  name: "PackageX Inc",
  type: "contact",
};

fetch(`https://api.packagex.io/v1/groups`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
});

      

Create a Group on a location and add multiple contacts

js
        const data = {
  name: "PackageX Inc Newyork",
  type: "contact",
  location_id: "loc_8zwjFyg4yzNoiphSNB3BhH",
  add: ["ctct_119hckKY7SJeHDdq8SBKXe", "ctct_11pMKTEap3y2kNeJM39qWD", "ctct_13hubA8zve9ibXGkfNiN8m"]
};

fetch(`https://api.packagex.io/v1/groups`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
});

      

Update Group

POST
`/v1/groups/:group`

To update a group, you'll need to pass the group's ID along with any properties that you want to manage.

js
        const data = {
  name: "PackageX Inc.",
};

fetch(`https://api.packagex.io/v1/groups/${group.id}`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
});

      

Update a Group name and add and remove contacts

js
        const data = {
  name: "PackageX Inc Newark",
  remove: ["ctct_119hckKY7SJeHDdq8SBKXe", "ctct_11pMKTEap3y2kNeJM39qWD", "ctct_13hubA8zve9ibXGkfNiN8m"]
  add: ["ctct_1883Qq5jbcxYobLUWo4vqF", "ctct_17U1w1UdmRsC4fCHwU9yJR", "ctct_19PEUtB2C4mAgs571KUA5k"]
};

fetch(`https://api.packagex.io/v1/groups/${group.id}`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
});

      

Override group contacts

js
        const data = {
  set: ["ctct_1883Qq5jbcxYobLUWo4vqF", "ctct_17U1w1UdmRsC4fCHwU9yJR"]
};

fetch(`https://api.packagex.io/v1/groups/${group.id}`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
});

      

Request Body

name string (required)
resource contact|location (required)
location_id location_id
add Array<contact_id|location_id> <br> **remove** Array<contact_id|location_id>
set `Array<contact_id|location_id>
Overrides the children with provided array

Validations

set can not be used with add or remove.
Group resource can not be updated.
location_id can not be set with resource location.
The combination of name and resource must be unique.
If a location_id is provided to a group, only contacts that are associated to that location can be added to the group.
Only contact or locations that are in the group can be removed.