Nutritious Pumpkin Mash

    printful-request

    1.1.1 • Public • Published

    printful-request

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

    Quickstart

    const { PrintfulClient, request } = require("printful-request");
    
    const printful = new PrintfulClient("PRINTFUL_API_KEY");
    
    printful.get("orders").then(({ result }) => console.log(result));
    
    // Or with a simple request
    
    request("orders", {
      apiKey: "PRINTFUL_API_KEY",
      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_KEY");
    
    printful.get("orders").then(({ result }) => console.log(result));
    
    // or using request
    
    request("orders", { apiKey: "PRINTFUL_API_KEY" }).then(({ result }) =>
      console.log(result)
    );

    GET with params

    const { PrintfulClient, request } = require("printful-request");
    
    const printful = new PrintfulClient("PRINTFUL_API_KEY");
    
    printful
      .get("orders", { limit: 5, offset: 10 })
      .then(({ result }) => console.log(result));
    
    // or using request
    
    request("orders", {
      apiKey: "PRINTFUL_API_KEY",
      params: { limit: 5, offset: 10 },
    }).then(({ result }) => console.log(result));

    POST

    const { PrintfulClient, request } = require("printful-request");
    
    const printful = new PrintfulClient("PRINTFUL_API_KEY");
    
    printful
      .get("orders/estimate-costs", {
        recipient: { name: "..." },
        items: [{ id: "..." }],
      })
      .then(({ result }) => console.log(result));
    
    // or using request
    
    request("orders/estimate-costs", {
      apiKey: "PRINTFUL_API_KEY",
      params: { recipient: { name: "..." }, items: [{ id: "..." }] },
    }).then(({ result }) => console.log(result));

    PUT

    const { PrintfulClient, request } = require("printful-request");
    
    const printful = new PrintfulClient("PRINTFUL_API_KEY");
    
    printful
      .get("orders/{id}", {
        id: "...",
        confirm: true,
      })
      .then(({ result }) => console.log(result));
    
    // or using request
    
    request("orders/{id}", {
      apiKey: "PRINTFUL_API_KEY",
      params: { id: "...", confirm: true },
    }).then(({ result }) => console.log(result));

    DELETE

    const { PrintfulClient, request } = require("printful-request");
    
    const printful = new PrintfulClient("PRINTFUL_API_KEY");
    
    printful.delete("orders/{id}").then(({ result }) => console.log(result));
    
    // or using request
    
    request("orders/{id}", {
      apiKey: "PRINTFUL_API_KEY",
      method: "DELETE",
    }).then(({ result }) => console.log(result));

    Install

    npm i printful-request

    DownloadsWeekly Downloads

    106

    Version

    1.1.1

    License

    MIT

    Unpacked Size

    5.99 kB

    Total Files

    5

    Last publish

    Collaborators

    • notrab