W3Block Docs
  • ๐Ÿš€Start here
    • Welcome to the Docs
    • Integrated Blockchains
  • ๐Ÿ‘จโ€๐Ÿ’ปDev Docs
    • API
      • Getting Started
      • Authentication
      • Commerce API services
        • Company Administration
          • Companies (Admin)
          • Assets (Admin)
          • Tags (Admin)
          • Products (Admin)
            • Order Rules (Admin)
          • Orders (Admin)
          • Faq (Admin)
          • Webhooks (Admin)
        • Products
        • Orders
        • Webhooks
        • Faq
        • Globals
      • Key API Services
        • Authentication
        • Companies
        • Tokens
          • Contracts
            • External Contacts
            • Royalty Eligible
          • Categories
            • Subcategories
          • Token Collections
            • Token Editions
          • Metadata
        • Blockchain
        • Cloudinary
        • Integration
          • Ecommerce
            • Associate Tokens
            • Hooks
        • Users
        • Vouchers
  • ๐Ÿ“˜Knowledge Base
    • First Steps
    • FAQ
    • Glossary
Powered by GitBook
On this page
  1. Dev Docs
  2. API
  3. Commerce API services

Products

Products are basically a kind of "wrapper" around a NFT collection. It can have a set of tokens also known as stocks to be sold grouped in the product. Some characteristics of products:

  • Products can have prices by currency, which means that it can be sold in multiple payment gateways, depending on the currency that should be used in the order creation

  • Products can have a distribution type which is used to select the tokens to be delivered if the token inside the product is not specifically defined in the order purchase creation. The distribution types can be:

    • random: It selects some available token randomly

    • sequential: It selects the next available token by tokenId

    • fixed: You can define for each one product token which user can purchase the token and this kind of match distribute based on that rules.

  • Products can have a pricing type which defines if the price will be applied for all tokens inside the product or if the price is defined by each token. Available price types:

    • product: Its defined by product (one for all tokens)

    • token: Each token must define a price

  • Products can have custom images, name and description instead of just using the blockchain information.

Product Model (Example)
{
    "id": "434d550e-3502-4afb-9a3f-asd13413sad",
    "createdAt": "2022-10-18T17:01:29.867Z",
    "updatedAt": "2022-10-31T22:11:02.422Z",
    "companyId": "asd13413sad-d3af-40d9-a19e-a263fdfe6e92",
    "name": "Teste",
    "description": "Teste descriรงรฃo",
    "images": [
        {
            "thumb": "http://res.cloudinary.com/tropix-dev/image/upload/v1667254203/commerce/010e92ea-d3af-40d9-a19e-a263fdfe6e92/86db28d6-3bf8-4906-9d2a-fdf792dd74b0.png",
            "assetId": "86db28d6-3bf8-4906-9d2a-fdf792dd74b0",
            "original": "http://res.cloudinary.com/tropix-dev/image/upload/v1667254203/commerce/010e92ea-d3af-40d9-a19e-a263fdfe6e92/86db28d6-3bf8-4906-9d2a-fdf792dd74b0.png"
        }
    ],
    "prices": [
        {
            "amount": "1.50",
            "currencyId": "65fe1119-6ec0-4b78-8d30-cb989914bdcb",
            "currency": {
                "id": "65fe1119-6ec0-4b78-8d30-cb989914bdcb",
                "createdAt": "2022-08-02T19:49:36.166Z",
                "updatedAt": "2022-08-02T19:49:36.166Z",
                "name": "BRL",
                "crypto": false,
                "symbol": "R$",
                "code": "BRL"
            }
        }
    ],
    "distributionType": "random",
    "pricingType": "product",
    "contractAddress": "0x5478a7790e45bb08213b9d7384bf50f65fc0a667",
    "chainId": 80001,
    "startSaleAt": null,
    "endSaleAt": null,
    "status": "published",
    "draftData": {
        "range": "1-5",
        "keyCollectionId": "e3517532-4ebd-4b65-98e4-023888f1ccdd"
    },
    "slug": "teste-shark-qa",
    "stockAmount": 30,
    "tokensAmount": 30,
    "canPurchase": true
}

Service Methods

List the products of company/tenant

Using SDK
// init your sdk as defined in main page of Commerce service
import { W3blockCommerceSDK } from '@w3block/sdk-commerce';
const sdk: W3blockCommerceSDK;
...

const tenantId = '<your tenant id>';
const products = await sdk.api.companies.listProducts(tenantId, {page: 1, limit: 100});
console.log('products', products);

Rest API reference:

Gets a product by id

Using SDK
// init your sdk as defined in main page of Commerce service
import { W3blockCommerceSDK } from '@w3block/sdk-commerce';
const sdk: W3blockCommerceSDK;
...

const tenantId = '<your tenant id>';
const productId = '<your product id>';
const product = await sdk.api.companies.getProduct(tenantId, productId);
console.log('product', product);

Rest API reference:

Gets a product by slug

Using SDK
// init your sdk as defined in main page of Commerce service
import { W3blockCommerceSDK } from '@w3block/sdk-commerce';
const sdk: W3blockCommerceSDK;
...

const tenantId = '<your tenant id>';
const productSlug = '<your product slug>';
const product = await sdk.api.companies.getProductBySlug(tenantId, productSlug);
console.log('product', product);

Rest API reference:

Check if some product can be purchased

If this method returns canPurchase=true without authentication, that means the product doesn't have any order rule.

Using SDK
// init your sdk as defined in main page of Commerce service
import { W3blockCommerceSDK } from '@w3block/sdk-commerce';
const sdk: W3blockCommerceSDK;
...

const tenantId = '<your tenant id>';
const productId = '<your product id>';
const { canPurchase } = await sdk.api.companies.canPurchaseProduct(tenantId, productId);
console.log('canPurchase', canPurchase);

Rest API reference:

PreviousWebhooks (Admin)NextOrders

Last updated 2 years ago

๐Ÿ‘จโ€๐Ÿ’ป
get
Authorizations
Path parameters
companyIdstringRequired
Query parameters
pagenumberOptionalDefault: 1
limitnumberOptionalDefault: 10
searchstringOptional
sortBystring ยท enumOptionalExample: createdAtPossible values:
orderBystring ยท enumOptionalPossible values:
sortByPriceCurrencyIdstring ยท uuid Optional
includeMetadatabooleanOptional

Includes first product token found metadata for each product. (Works good if you want to get some common NFT metadata attributes that is applied for all contract tokens)

Default: falseExample: false
tagIdsstring[]Optional
Responses
200Success
get
GET /companies/{companyId}/products HTTP/1.1
Host: commerce.w3block.io
Authorization: Bearer JWT
Accept: */*
200Success

No content

get
Authorizations
Path parameters
companyIdstringRequired
productIdstringRequired
Query parameters
refreshPermissionsbooleanOptional

Forces permission refresh which can affect canPurchase result params

Default: falseExample: false
Responses
200Success
get
GET /companies/{companyId}/products/{productId} HTTP/1.1
Host: commerce.w3block.io
Authorization: Bearer JWT
Accept: */*
200Success

No content

get
Authorizations
Path parameters
companyIdstringRequired
slugstringRequired
Query parameters
refreshPermissionsbooleanOptional

Forces permission refresh which can affect canPurchase result params

Default: falseExample: false
Responses
200Success
get
GET /companies/{companyId}/products/get-by-slug/{slug} HTTP/1.1
Host: commerce.w3block.io
Authorization: Bearer JWT
Accept: */*
200Success

No content

get
Authorizations
Path parameters
companyIdstringRequired
productIdstringRequired
Responses
200Success
get
GET /companies/{companyId}/products/{productId}/can-purchase HTTP/1.1
Host: commerce.w3block.io
Authorization: Bearer JWT
Accept: */*
200Success

No content

  • Service Methods
  • List the products of company/tenant
  • GET/companies/{companyId}/products
  • Gets a product by id
  • GET/companies/{companyId}/products/{productId}
  • Gets a product by slug
  • GET/companies/{companyId}/products/get-by-slug/{slug}
  • Check if some product can be purchased
  • GET/companies/{companyId}/products/{productId}/can-purchase