Creates a new product
import Fragment from '@fragment-dev/ts-node';
const client = new Fragment({
clientId: process.env['FRAGMENT_CLIENT_ID'],
clientSecret: process.env['FRAGMENT_CLIENT_SECRET'],
});
const response = await client.products.create(
{
code: 'PROD_001',
description: 'Premium subscription service',
paid_by_roles: [{ name: 'buyer' }],
paid_to_roles: [{ name: 'seller' }]
}
);{
"data": {
"id": "product_1234567890",
"workspace_id": "ws_1234567890",
"code": "PROD_001",
"description": "Premium subscription service",
"paid_by_roles": [
{
"name": "buyer",
"id": "role_def123"
}
],
"paid_to_roles": [
{
"name": "buyer",
"id": "role_def123"
}
],
"update_version": 1,
"created": "2024-01-13T00:00:00Z"
}
}Lists all products for the workspace
import Fragment from '@fragment-dev/ts-node';
const client = new Fragment({
clientId: process.env['FRAGMENT_CLIENT_ID'],
clientSecret: process.env['FRAGMENT_CLIENT_SECRET'],
});
const response = await client.products.list();{
"data": [
{
"id": "product_1234567890",
"workspace_id": "ws_1234567890",
"code": "PROD_001",
"description": "Premium subscription service",
"paid_by_roles": [
{
"name": "buyer",
"id": "role_def123"
}
],
"paid_to_roles": [
{
"name": "buyer",
"id": "role_def123"
}
],
"update_version": 1,
"created": "2024-01-13T00:00:00Z"
}
]
}Gets a product by code
import Fragment from '@fragment-dev/ts-node';
const client = new Fragment({
clientId: process.env['FRAGMENT_CLIENT_ID'],
clientSecret: process.env['FRAGMENT_CLIENT_SECRET'],
});
const response = await client.products.retrieve('PROD_001');{
"data": {
"id": "product_1234567890",
"workspace_id": "ws_1234567890",
"code": "PROD_001",
"description": "Premium subscription service",
"paid_by_roles": [
{
"name": "buyer",
"id": "role_def123"
}
],
"paid_to_roles": [
{
"name": "buyer",
"id": "role_def123"
}
],
"update_version": 1,
"created": "2024-01-13T00:00:00Z"
}
}