1. Logs
  2. Retrieve Logs

Logs

Retrieve Logs

Example

GET
`/v1/logs/:log_id`

Retrieve a single log using its id.

js
        const response = await fetch("https://api.packagex.io/v1/logs/log_chsdYjafQbo7tp73a85PeQ", {
  method: "GET",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY
  }
});
const log = await response.json();

      

List Logs

Example

GET
`/v1/logs`

When you want to retrieve list of logs, your data property on the result will always be an array even if you don't have any log entry.

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

const result = await response.json();
const logs = result.data;
const pagination = result.pagination;

      

The results are always ordered by creation timestamp in reverse chronological order.

Pagination

If the has_more property on the pagination object is set to true, you know there are more logs 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 total number of logs in the database.

By default, the page is set to 1 and the limit is 10.

If we want to query for logs 11 - 20, we would request page 2 with a query parameter.

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

const result = await response.json();
const logs = result.data; // the array of exports 11 - 20
const pagination = result.pagination; // the pagination object

      

Query Parameters

resource_id string
The unique identifier of the resource, for example, to get all logs associated to a parcel, pass the ID of the parcel.

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

const result = await response.json();
const logs = result.data; // logs for parcel with id prcl_qMS5roAJNViUps4Y6aztVX

      

Previous <- Model