1. Users
  2. Retrieve Users

Users

Retrieve Users

Retrieve User

GET
`/v1/users/:user`

Get a single user using its id.

js
        const response = await fetch("https://api.packagex.io/v1/user/rEMzyCyxJzuBzN4LyurAJV", {
  method: "GET",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
}).then((res) => res.json());

const user = response.data;

      

List Users

Example

GET
`/v1/users`

When you want to retrieve multiple users, your data property on the result will always be an array even if you don't have any users. The users are returned in alphabetical order by first name.

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

const users = response.data;
const pagination = response.pagination;

      

Pagination

If the has_more property on the pagination object is set to true, you know there are more users in the database that have not been returned to you. The pagination object also has a page property indicating your current offset and a limit property. The total_count property in pagination returns the the total number of users in the database.

By default the page is set to 1 and the limit is 25.

If we want to query for users 26 - 50, we would request page 2 with a query parameter.

js
        const response = await fetch("https://api.packagex.io/v1/users?page=2&limit=25", {
  method: "GET",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
}).then((res) => res.json());

const users = response.data; //the array of users 25 - 50
const pagination = response.pagination; //the pagination object