printful-request
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

printful-request

Simple Node.js request wrapper for Printful, with authorization management. Not to be used client-side.

VERSION 2.0 USERS: You will want to use Printful API Tokens, and NOT API KEYS. Read migration guide.

Quickstart

const { PrintfulClient, request } = require("printful-request");

const printful = new PrintfulClient("PRINTFUL_API_TOKEN");

printful.get("orders").then(({ result }) => console.log(result));

// Or with a simple request

request("orders", {
  token: "PRINTFUL_API_TOKEN",
  params: { limit: 1 },
}).then(({ result }) => console.log(result));

Examples

Refer to the Printful API Documentation for possible URLs. This library acts as a small layer for parsing JSON, and passing API keys as authorization headers.

GET

const { PrintfulClient, request } = require("printful-request");

const printful = new PrintfulClient("PRINTFUL_API_TOKEN");

printful.get("orders").then(({ result }) => console.log(result));

// or using request

request("orders", { token: "PRINTFUL_API_TOKEN" }).then(({ result }) =>
  console.log(result)
);

GET with params

const { PrintfulClient, request } = require("printful-request");

const printful = new PrintfulClient("PRINTFUL_API_TOKEN");

printful
  .get("orders", { limit: 5, offset: 10 })
  .then(({ result }) => console.log(result));

// or using request

request("orders", {
  token: "PRINTFUL_API_TOKEN",
  params: { limit: 5, offset: 10 },
}).then(({ result }) => console.log(result));

POST

const { PrintfulClient, request } = require("printful-request");

const printful = new PrintfulClient("PRINTFUL_API_TOKEN");

printful
  .get("orders/estimate-costs", {
    recipient: { name: "..." },
    items: [{ id: "..." }],
  })
  .then(({ result }) => console.log(result));

// or using request

request("orders/estimate-costs", {
  token: "PRINTFUL_API_TOKEN",
  params: { recipient: { name: "..." }, items: [{ id: "..." }] },
}).then(({ result }) => console.log(result));

PUT

const { PrintfulClient, request } = require("printful-request");

const printful = new PrintfulClient("PRINTFUL_API_TOKEN");

printful
  .get("orders/{id}", {
    id: "...",
    confirm: true,
  })
  .then(({ result }) => console.log(result));

// or using request

request("orders/{id}", {
  token: "PRINTFUL_API_TOKEN",
  params: { id: "...", confirm: true },
}).then(({ result }) => console.log(result));

DELETE

const { PrintfulClient, request } = require("printful-request");

const printful = new PrintfulClient("PRINTFUL_API_TOKEN");

printful.delete("orders/{id}").then(({ result }) => console.log(result));

// or using request

request("orders/{id}", {
  token: "PRINTFUL_API_TOKEN",
  method: "DELETE",
}).then(({ result }) => console.log(result));

Dependencies (1)

Dev Dependencies (3)

Package Sidebar

Install

npm i printful-request

Weekly Downloads

263

Version

1.3.0

License

MIT

Unpacked Size

21.5 kB

Total Files

9

Last publish

Collaborators

  • notrab