1.1.0 • Published 3 years ago

@cocart/cocart-rest-api v1.1.0

Weekly downloads
77
License
MIT
Repository
github
Last release
3 years ago

🍴 Forked from WooCommerce JavaScript Library and modified to support CoCart REST API instead. Authentication is optional.

JavaScript library for CoCart, supports CommonJS (CJS) and ECMAScript Modules (ESM).

Requests are made with Axios library with support to promises.

build status npm version

⚠️This library will NOT support the LEGACY API of CoCart.

Installation

npm install --save @cocart/cocart-rest-api

Getting started

Check out the CoCart API endpoints and data that can be manipulated in https://docs.cocart.xyz/.

Setup

ESM example

import CoCartAPI from "@cocart/cocart-rest-api";

const CoCart = new CoCartAPI({
  url: "https://example.com",
});

CJS example

const CoCartAPI = require("@cocart/cocart-rest-api").default;

const CoCart = new CoCartAPI({
  url: "https://example.com",
});

Options

OptionTypeRequiredDescription
urlStringyesYour Store URL, example: https://example.com/
consumerKeyStringnoYour API consumer key, username or email address.
consumerSecretStringnoYour API consumer secret or password.
wpAPIPrefixStringnoCustom WP REST API URL prefix, used to support custom prefixes created with the rest_url_prefix filter.
versionStringnoAPI version, default is cocart/v2
encodingStringnoEncoding, default is 'utf-8'
queryStringAuthBoolnoWhen true and using under HTTPS force Basic Authentication as query string, default is false
portstringnoProvide support for URLs with ports, eg: 8080
oauthBoolnoWhen true authorize via OAuth 1.0a, default is false
timeoutIntegernoDefine the request timeout
axiosConfigObjectnoDefine the custom Axios config, also override this library options.

Methods

GET

  • .get(endpoint)
  • .get(endpoint, params)
ParamsTypeDescription
endpointStringCoCart API endpoint, example: cart or products/32
paramsObjectQuery strings params, example: { per_page: 20 }

POST

  • .post(endpoint, data)
  • .post(endpoint, data, params)
ParamsTypeDescription
endpointStringCoCart API endpoint, example: cart/add-item or cart/item
dataObjectJS object to be converted into JSON and sent in the request
paramsObjectQuery strings params

PUT

  • .put(endpoint, data)
  • .putt(endpoint, data, params)
ParamsTypeDescription
endpointStringCoCart API endpoint, example: cart/item/<item_key>
dataObjectJS object to be converted into JSON and sent in the request
paramsObjectQuery strings params

DELETE

  • .delete(endpoint)
  • .delete(endpoint, params)
ParamsTypeDescription
endpointStringCoCart API endpoint, example: cart/item or coupon
paramsObjectQuery strings params, example: { force: true }

Bug Reporting

If you think you have found a bug in the library, please open a new issue and I will do my best to help you out.

CoCart Channels

We have different channels at your disposal where you can find information about the CoCart project, discuss it and get involved:

Twitter: cart_co CoCart JS Lib Github Stars

I'm not seeing X-COCART-API header returning

If you want this header to return then you need to enable CORS. Simply install CoCart CORS plugin for quick activation.

Changelog

See changelog for details

Credits

CoCart is developed and maintained by Sébastien Dumont.


sebastiendumont.com  ·  GitHub @seb86  ·  Twitter @sebd86