/** * Internal dependencies */ const { getRequest, postRequest, putRequest, deleteRequest, } = require( '../utils/request' ); const { getExampleVariation, shared } = require( '../data' ); /** * WooCommerce Product Variation endpoints. * * https://woocommerce.github.io/woocommerce-rest-api-docs/#product-variations */ const variationsApi = { name: 'Product variations', create: { name: 'Create a product variation', method: 'POST', path: 'products//variations', responseCode: 201, payload: getExampleVariation(), variation: async ( productId, variation ) => postRequest( `products/${ productId }/variations`, variation ), }, retrieve: { name: 'Retrieve a product variation', method: 'GET', path: 'products//variations/', responseCode: 200, variation: async ( productId, variationId ) => `products/${ productId }/variations/${ variationId }`, }, listAll: { name: 'List all product variations', method: 'GET', path: 'products//variations', responseCode: 200, variations: async ( productId, queryString = {} ) => getRequest( `products/${ productId }/variations`, queryString ), }, update: { name: 'Update a product variation', method: 'PUT', path: 'products//variations/', responseCode: 200, payload: getExampleVariation(), variation: async ( productId, variationId, variationDetails ) => putRequest( `products/${ productId }/variations/${ variationId }`, taxRateDetails ), }, delete: { name: 'Delete a product variation', method: 'DELETE', path: 'products//variations/', responseCode: 200, payload: { force: false, }, variation: async ( productId, variationId, deletePermanently ) => deleteRequest( `products/${ productId }/variations/${ variationId }`, deletePermanently ), }, batch: { name: 'Batch update product variations', method: 'POST', path: 'products//variations/batch', responseCode: 200, payload: shared.getBatchPayloadExample( getExampleVariation() ), variations: async ( batchUpdatePayload ) => postRequest( `products/${ productId }/variations/${ variationId }`, batchUpdatePayload ), }, }; module.exports = { variationsApi };