1. Threads And Channels
  2. Retrieve

Threads And Channels

Retrieve

Typically you will be retrieving a thread related to a specific resource. Because the thread has a predictable ID (the resource's ID prefixed with thrd_), you'll typically just retrieve a single thread.

Channels on the other hand are not tied to a specific resource. Instead, you'll typically query the channel based on the third party subscribers on a resource.

Retrieve Thread

GET
`/v1/threads/:thread`

Get a single thread using its id.

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

const thread = response.data;

      

List Threads

Example

GET
`/v1/threads`

When you want to retrieve multiple threads, your data property on the result will always be an array even if you don't have any threads.

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

const threads = 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 threads 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 threads in the database.

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

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

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

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

      

Retrieve Channel

GET
`/v1/channels/:channel`

Get a single thread using its id.

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

const thread = response.data;

      

List Channels

Example

GET
`/v1/channels`

When you want to retrieve multiple threads, your data property on the result will always be an array even if you don't have any channels.

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

const threads = response.data;
const pagination = response.pagination;

      

Find by subscribers

Sometimes you may want to find a channel by the subscribers on a resource. You can do this by passing in a subscriber_ids query parameter with all of the subscriber ids you want to find a channel for.

Typically, you'll only have one subscriber, and you do not need to include your own organization.

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

const channels = response.data;

      

Pagination

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

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

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

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

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