1. Locations
  2. Manage Users

Locations

Manage Users

We have dedicated endpoints to help you manage which users should have access to which locations. Keep in mind that the owner and developer roles will always have access to all locations. Only admin and user roles can be scoped to specific locations.

Add Users To Location

Add Many Users

POST
`/v1/locations/:location/users`

You'll be able to add many users at once by providing an array of user IDs in the request body. You can also add an overwrite property to ensure that any user not on this list will be deleted. Keep in mind that the owner and developer role users will still be injected to the list even if they are not included in the users list. Only a user who has access to a location is able to add users to that location.

js
        const data = {
  users: ["2xFv1aJTgQTGGK6nWQeZ44P7hUR2", "hDfpP0P90gOuMgLOOCfdcvcyJiB3"],
  overwrite: true,
};

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

//We'll still respond with the location with the new users nested inside of it
const location = response.data;

      

Add One User

POST
`/v1/locations/:location/users/:user`

While the previous API would work for all situations, we're also adding a more syntactically correct API route for adding a single user for those developer who prefer it done this way.

js
        const data = {
  overwrite: false,
};

const response = await fetch(
  `https://api.packagex.io/v1/locations/loc_8GiCVuqZqBJi43v2WebaME/users/2xFv1aJTgQTGGK6nWQeZ44P7hUR2`,
  {
    method: "POST",
    headers: {
      "PX-API-KEY": process.env.PX_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(data),
  }
);

//We'll still respond with the location with the new users nested inside of it
const location = response.data;

      

Delete Users

Delete Many Users

DELETE
`/v1/locations/:location/users`

You'll be able to delete many users at once by providing an array of user IDs in the request body.

js
        const data = {
  users: ["2xFv1aJTgQTGGK6nWQeZ44P7hUR2", "hDfpP0P90gOuMgLOOCfdcvcyJiB3"],
};

const response = await fetch(`https://api.packagex.io/v1/locations/loc_8GiCVuqZqBJi43v2WebaME/users`, {
  method: "DELETE",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
});

//We'll still respond with the location with the new users nested inside of it
const location = response.data;

      

Delete One User

DELETE
`/v1/locations/:location/users/:user`

You can delete a single user from a location using just the URL scheme with the location ID and user UD.

js
        const response = await fetch(
  `https://api.packagex.io/v1/locations/loc_8GiCVuqZqBJi43v2WebaME/users/2xFv1aJTgQTGGK6nWQeZ44P7hUR2`,
  {
    method: "DELETE",
    headers: {
      "PX-API-KEY": process.env.PX_API_KEY,
      "Content-Type": "application/json",
    },
  }
).then((res) => res.json());

//We'll still respond with the location with the new users nested inside of it
const location = response.data;