0.2.0 • Published 7 months ago
printful-client
Licence
MIT
Version
0.2.0
Deps
1
Size
47 kB
Vulns
0
Weekly
0
printful-client
Request wrapper for Printful, with authorization management. Not to be used client-side.
Install
# Npm:
npm install printful-client
# Yarn:
yarn add printful-client
# Pnpm: 💝
pnpm add printful-client
Get Product
const { PrintfulClient } = require("printful-client");
const printful = new PrintfulClient("PRINTFUL_API_TOKEN");
printful.products.get("PRODUCT_ID").then((response: Response) => {
response.json().then((value) => {
console.log(JSON.stringify(val));
});
});
Get all store products
const { PrintfulClient } = require("printful-client");
const printful = new PrintfulClient("PRINTFUL_API_TOKEN");
printful.products.getAll().then((response: Response) => {
response.json().then((val) => {
console.log(JSON.stringify(val));
});
});
Get product variant
const { PrintfulClient } = require("printful-client");
const printful = new PrintfulClient("PRINTFUL_API_TOKEN");
printful.products.variants.get("VARIANT_ID").then((response: Response) => {
response.json().then((val) => {
console.log(JSON.stringify(val));
});
});
Calculate Shipping Rate
const shippingRequest = {
recipient: {
address1: "5246 US Hwy 98 N",
city: "Lakeland",
country_code: "US",
state_code: "FL",
zip: "33809"
},
items: [
{
variant_id: "11566",
quantity: 10
},
],
currency: "USD",
locale: "en_US",
};
printful.shipping.calculate(shippingRquest).then((response: Response) => {
response.json().then((val) => {
console.log(JSON.stringify(val));
});
});
Get Tax Rate
const taxRequest = {
recipient: {
"country_code": "US",
"state_code": "FL",
"city": "Lakeland",
"zip": "33809"
}
};
printful.tax.getRate(taxRequest).then((response: Response) => {
response.json().then((val) => {
console.log(JSON.stringify(val));
});
});
Request JSON with error handling
requestJson parses the JSON body and throws a PrintfulApiError on non-2xx responses.
const { PrintfulClient } = require("printful-client");
const printful = new PrintfulClient("PRINTFUL_API_TOKEN");
printful
.requestJson("/products")
.then((data) => {
console.log(JSON.stringify(data));
})
.catch((error) => {
console.error(error.status, error.message);
});
Refer to the Printful API Documentation
Links
Contributions
New contributors welcome! just create a PR
Todo
- Re-organize types
- Add more endpoints
- Unit testing