![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@woocommerce/api
Advanced tools
A simple interface for interacting with a WooCommerce installation.
An isometric API client for interacting with WooCommerce installations. Here are the current and planned features:
npm install @woocommerce/api --save-dev
Depending on what you're intending to get out of the API client there are a few different ways of using it.
The simplest way to use the client is directly:
import { HTTPClientFactory } from '@woocommerce/api';
// You can create an API client using the client factory with pre-configured middleware for convenience.
let client = HTTPClientFactory.build( 'https://example.com' )
.withBasicAuth( 'username', 'password' )
.create();
// You can also create an API client configured for requests using OAuth.
client = HTTPClientFactory.build( 'https://example.com' )
.withOAuth( 'consumer_secret', 'consumer_password' )
.create();
// You can then use the client to make API requests.
httpClient.get( '/wc/v3/products' ).then( ( response ) => {
// Access the status code from the response.
response.statusCode;
// Access the headers from the response.
response.headers;
// Access the data from the response, in this case, the products.
response.data;
}, ( error ) => {
// Handle errors that may have come up.
} );
As a convenience utility we've created repositories for core data types that can simplify interacting with the API:
SimpleProduct
ExternalProduct
GroupedProduct
VariableProduct
Coupon
Order
SettingsGroup
ProductVariation
Setting
These repositories provide CRUD methods for ease-of-use:
import { HTTPClientFactory, SimpleProduct } from '@woocommerce/api';
// Prepare the HTTP client that will be consumed by the repository.
// This is necessary so that it can make requests to the REST API.
const httpClient = HTTPClientFactory.build( 'https://example.com' )
.withBasicAuth( 'username', 'password' )
.create();
const repository = SimpleProduct.restRepository( httpClient );
// The repository can now be used to create models.
const product = repository.create( { name: 'Simple Product', regularPrice: '9.99' } );
// The response will be one of the models with structured properties and TypeScript support.
product.id;
The following methods are available on all repositories if the corresponding method is available on the API endpoint:
create( {...properties} )
- Create a single object of the model typedelete( objectId )
- Delete a single object of the model typelist( {...parameters} )
- Retrieve a list of the existing objects of that model typeread( objectId )
- Read a single object of the model typeupdate( objectId, {...properties} )
- Update a single object of the model typeIn child model repositories, each method requires the parentId
as the first parameter:
import { HTTPClientFactory, VariableProduct, ProductVariation } from '@woocommerce/api';
const httpClient = HTTPClientFactory.build( 'https://example.com' )
.withBasicAuth( 'username', 'password' )
.withIndexPermalinks()
.create();
const productRepository = VariableProduct.restRepository( httpClient );
const variationRepository = ProductVariation.restRepository( httpClient );
const product = await productRepository.create({
"name": "Variable Product with Three Attributes",
"defaultAttributes": [
{
"id": 0,
"name": "Size",
"option": "Medium"
},
{
"id": 0,
"name": "Colour",
"option": "Blue"
}
],
"attributes": [
{
"id": 0,
"name": "Colour",
"isVisibleOnProductPage": true,
"isForVariations": true,
"options": [
"Red",
"Green",
"Blue"
],
"sortOrder": 0
},
{
"id": 0,
"name": "Size",
"isVisibleOnProductPage": true,
"isForVariations": true,
"options": [
"Small",
"Medium",
"Large"
],
"sortOrder": 0
}
]
});
const variation = await variationRepository.create( product.id, {
"regularPrice": "19.99",
"attributes": [
{
"name": "Size",
"option": "Large"
},
{
"name": "Colour",
"option": "Red"
}
]
});
FAQs
A simple interface for interacting with a WooCommerce installation.
We found that @woocommerce/api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 15 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.