npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

woocommerce-api-client

v1.0.1

Published

Woocommerce REST API client, provides oAuth1.0 and Basic authentications

Downloads

18

Readme

Minimal WooCoommerce REST API Client

Since I wasn't able to find any - here's simple implementation with ZERO dependecies of authenticated client for WooCommerce REST API.

Usage

GET

const WoocommerceApiClient = require("woocommerce-api-client").default;

const client = new WoocommerceApiClient({
    url: "http://localhost",
    consumerKey: "ck_XXXXXXXXXXXXXXXXXXXXXXXX",
    consumerSecret: "cs_XXXXXXXXXXXXXXXXXXXXXXX",
});

async function getCustomers() {
    const response = await client.get("/wp-json/wc/v1/custormes");
    if (response.statusCode != 200) {
        console.error(response.statusMessage);
        return null;
    }
    return JSON.parse(await response.content());
}

getCustomers().then(console.log); // Should print array of customers

POST

const { default: WoocommerceRestApiClient } = require("woocommerce-api-client").default;

const api = new WoocommerceRestApiClient({
    consumerKey: "ck_40d1c02af01eba0dbc55238b3feeb0093d0bbe22",
    consumerSecret: "cs_27d03c8a61b6203adc3c1da1db17d61e90d8d225",
    url: "http://localhost"
});

async function createCustomer() {
    const request = await api.post("/wp-json/wc/v1/customers", {
        body: JSON.stringify({
            email: "[email protected]",
            username: "test",
            firstName: "test",
            lastName: "testifisberg",
        }),
    });
    if (request.statusCode != 201) {
        console.error(JSON.parse(await request.content()));
        return null;
    }
    const customer = JSON.parse(await request.content());
    return customer;
}

createCustomer();

PUT (etc.)

const { default: WoocommerceRestApiClient } = require("woocommerce-api-client");

const api = new WoocommerceRestApiClient({
    consumerKey: "ck_40d1c02af01eba0dbc55238b3feeb0093d0bbe22",
    consumerSecret: "cs_27d03c8a61b6203adc3c1da1db17d61e90d8d225",
    url: "http://localhost"
});

async function updateCustomer() {
    const customer_id = 15;
    const request = await api.request(`/wp-json/wc/v1/customers/${customer_id}`, {
        method: "PUT",
        body: JSON.stringify({
            firstName: "test",
            lastName: "testifisberg",
        }),
    });
    if (request.statusCode != 200) {
        console.error(JSON.parse(await request.content()));
        return null;
    }
    const customer = JSON.parse(await request.content());
    return customer;
}

updateCustomer();