product-groups-client
v5.0.0
Published
Client library for fetching product groups from API
Readme
Product Groups Client
A client library for fetching product groups from the API.
Installation
npm install product-groups-clientUsage
In your React application:
import { ProductGroupClient } from 'product-groups-client';
// Create a new instance with your business unit key
const client = new ProductGroupClient('your-business-unit-key');
// Example usage in a React component
function ProductList() {
const [products, setProducts] = useState([]);
const [error, setError] = useState(null);
useEffect(() => {
async function fetchProducts() {
try {
const data = await client.getProductGroups();
setProducts(data.products);
} catch (err) {
setError(err.message);
}
}
fetchProducts();
}, []);
if (error) return <div>Error: {error}</div>;
if (!products) return <div>Loading...</div>;
return (
<div>
{products.map(product => (
<div key={product.slug}>
<h2>{product.name}</h2>
<p>ID: {product.friendlyID}</p>
{product.asset && <img src={product.asset.url} alt={product.name} />}
</div>
))}
</div>
);
}API
ProductGroupClient
The main class for interacting with the product groups API.
Constructor
const client = new ProductGroupClient(businessUnitKey);businessUnitKey(string): Your business unit key for API authentication
Methods
getProductGroups()
Fetches the list of product groups from the API.
Returns: Promise with the following structure:
products: Array of product objectsslug: Stringname: StringfriendlyID: StringbarID: Numberdescription: Stringasset: Object (contains url and is3DFile)readme: StringreadMeHtml: Stringhome: Booleanprice: Number
totalPages: Number
