1.1.10 • Published 5 years ago

react-native-wc-api v1.1.10

Weekly downloads
11
License
MIT
Repository
github
Last release
5 years ago

WooCommerce API - React-Native Client

A React-Native wrapper for the WooCommerce REST API. Easily interact with the WooCommerce REST API using this library.

dependency status npm version

Installation

To install the module using NPM:

npm install react-native-wc-api --save

To install the module using Yarn:

yarn add react-native-wc-api

Getting started

Generate API credentials (Consumer Key & Consumer Secret) following this instructions http://docs.woocommerce.com/document/woocommerce-rest-api/ .

Check out the WooCommerce API endpoints and data that can be manipulated in http://woocommerce.github.io/woocommerce-rest-api-docs/.

Setup

Setup for the new WP REST API integration (WooCommerce 2.6 or later):

import WooCommerceAPI from 'react-native-wc-api';

const WooCommerce = new WooCommerceAPI({
  url: 'http://example.com',
  consumerKey: 'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  consumerSecret: 'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  wpAPI: true,
  version: 'wc/v1'
});

Setup for the old WooCommerce legacy API:

import WooCommerceAPI from 'react-native-wc-api';

const WooCommerce = new WooCommerceAPI({
  url: 'http://example.com',
  consumerKey: 'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  consumerSecret: 'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  version: 'v3'
});

Options

OptionTypeRequiredDescription
urlStringyesYour Store URL, example: http://woo.dev/
consumerKeyStringyesYour API consumer key
consumerSecretStringyesYour API consumer secret
wpAPIBoolnoAllow requests to the WP REST API (WooCommerce 2.6 or later)
wpAPIPrefixStringnoCustom WP REST API URL prefix, used to support custom prefixes created with the rest_url_prefix filter
versionStringnoAPI version, default is v3
verifySslBoolnoVerify SSL when connect, use this option as false when need to test with self-signed certificates
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
timeoutIntegernoDefine the request timeout

Methods

ParamsTypeDescription
endpointStringWooCommerce API endpoint, example: customers or order/12
dataObjectJS object, will be converted to JSON

Instantiating a WooCommerceAPI instance without a url, consumerKey or secret will result in an error being thrown

GET

  • .get(endpoint)

POST

  • .post(endpoint, data)

PUT

  • .put(endpoint, data)

DELETE

  • .delete(endpoint)

OPTIONS

  • .options(endpoint)

Example include Here