@sociate/sociate-api-sdk
Version:
Javascript client for Sociate AI APIs
47 lines (46 loc) • 1.69 kB
JavaScript
export class ProductsAPI {
httpClient;
constructor(httpClient) {
this.httpClient = httpClient;
}
/**
* Create Products
* @description Create a list of products in the inventory
* @param products - The list of products to create
* @returns The response indicating the success of the operation
*/
async create(products) {
return await this.httpClient.post('/products', products);
}
/**
* Upload Products
* @description Upload products data via a form-data request
* @param product - The product data to upload
* @returns The response indicating the success of the operation
*/
async upload(product) {
const formData = new FormData();
formData.append('file', product.file);
// TODO - Test this method using form-data
return await this.httpClient.post('/products/upload', formData);
}
/**
* Delete Products
* @description Delete a list of products from the inventory
* @param products - The list of product IDs to delete
* @returns The response indicating the success of the operation
*/
async delete(products) {
return await this.httpClient.delete('/products', products);
}
/**
* Fetches the attributes of a product based on the provided parameters.
*
* @param params - The parameters required to get the product attributes.
* @param params.id - The unique identifier of the product.
* @returns A promise that resolves to the attributes of the product.
*/
async getAttributes(params) {
return await this.httpClient.get(`/products/${params.id}/attributes`);
}
}