### Full Code Example Source: https://scayle.dev/documentation/welcome-to-scayle/quick-start-guide/importing-product-data?sourceText=Importing%2520Product%2520Data This comprehensive example demonstrates the complete process of creating a warehouse, attaching it to a merchant, and then attaching it to a shop country. It includes all necessary setup and error handling. ```APIDOC ## Full Code Example ### Description This script creates a new warehouse, attaches it to a default merchant, and then associates it with a specific shop country, setting its priority. It utilizes the Scayle Admin API client. ### Setup Ensure you have the `swagger-client` and `dotenv` packages installed, and your `ADMIN_API_TOKEN` and `TENANT_SPACE` are configured in your `.env` file. ### Code ```javascript const SwaggerClient = require("swagger-client"); require("dotenv").config(); async function createAndAttachWarehouse() { const client = await new SwaggerClient({ url: `https://${process.env.TENANT_SPACE}.admin.api.scayle.cloud/api/admin/v1/admin-api.json`, authorizations: { accessToken: { value: process.env.ADMIN_API_TOKEN, }, }, }); // 1. Create Warehouse const newWarehouse = { referenceKey: "Warehouse11", }; let createdWarehouse = null; try { const response = await client.apis.Warehouses.createWarehouse( {}, { requestBody: newWarehouse } ); createdWarehouse = response.body; console.log("Created Warehouse", createdWarehouse); } catch (error) { console.error( "Unable to create warehouse", error.response.body.errors ); process.exit(1); } // 2. Attach Warehouse to Merchant try { const response = await client.apis.Warehouses.attachMerchantWarehouse({ merchantIdentifier: 1, // default merchant warehouseIdentifier: createdWarehouse.id, }); console.log("Attached Merchant to Warehouse", response.body); } catch (error) { console.error( "Unable to attach merchant to warehouse", error.response.body.errors ); process.exit(1); } // 3. Attach Warehouse to Shop Country try { const newShopCountryWarehouse = { referenceKey: "Warehouse11", priority: 100, }; const response = await client.apis.Warehouses.createShopCountryWarehouse( { shopKey: "k2", countryCode: "de", }, { requestBody: newShopCountryWarehouse, } ); const createdShopCountryWarehouse = response.body; console.log("Created Shop Country Warehouse", createdShopCountryWarehouse); } catch (error) { console.error("Unable to create shop country warehouse", error.response.body.errors); process.exit(1); } } createAndAttachWarehouse(); ``` ``` -------------------------------- ### Initialize Admin API SDK/Client in JavaScript Source: https://scayle.dev/documentation/welcome-to-scayle/readme/apis Initialize the Admin API SDK/client for JavaScript. This example shows the basic setup required to start making requests to the Admin API. ```javascript // Install with npm npm install swagger-client // Install with yarn yarn add swagger-client // Some code ``` -------------------------------- ### Run Storefront CLI Setup Source: https://scayle.dev/documentation/storefront/storefront-application/storefront-cli/setup Use this command to initiate the interactive setup process for your Storefront Application. Provide your tenant space and admin API token for authentication. ```bash $ sfcli setup -t -a ``` -------------------------------- ### Run Storefront CLI Setup Command Source: https://scayle.dev/documentation/storefront/storefront-application/storefront-cli/setup?sourceText=SCAYLE%2520Storefront%2520CLI%2520setup%2520command Use this command to initiate the interactive setup process for your Storefront Application. Provide your tenant space and admin API token for authentication. ```bash sfcli setup -t -a ``` -------------------------------- ### Install Dependencies with pnpm Source: https://scayle.dev/documentation/storefront/storefront-application/integrations/storybook?sourceText=Storybook Run this command to install all necessary project dependencies before starting Storybook or the application. ```bash pnpm install ``` -------------------------------- ### Run Storefront CLI Setup Source: https://scayle.dev/documentation/storefront/storefront-application/getting-started/set-up-your-storefront?sourceText=Basic%2520Theming Initializes the Storefront Application configuration by fetching shops from the SCAYLE Admin API using provided credentials. ```bash # Run setup with your Admin API token and tenant space pnpm dlx @scayle/storefront-cli setup --admin-api-token= --tenant-space= ``` -------------------------------- ### Start Redis Server Source: https://scayle.dev/documentation/welcome-to-scayle/quick-start-guide/storefront-setup?sourceText=previous%2520steps Start a locally installed Redis server. This is used for local development and may not be necessary in all environments. ```bash redis-server ``` -------------------------------- ### Start Local Redis Server Source: https://scayle.dev/documentation/welcome-to-scayle/quick-start-guide/storefront-setup Start a locally installed Redis server. This is an alternative to using a Docker image for local development. ```bash redis-server ``` -------------------------------- ### Full Example: Initialize Client and Create Shop Source: https://scayle.dev/documentation/welcome-to-scayle/quick-start-guide/importing-product-data?sourceText=Admin%2520API%2520%28Option%25202%29 This comprehensive example demonstrates initializing the Swagger client with API credentials and then creating a shop using the `createShop` method. It includes error handling and logs the created shop details. ```javascript const SwaggerClient = require("swagger-client"); require("dotenv").config(); async function addShop() { const client = await new SwaggerClient({ url: `https://${process.env.TENANT_SPACE}.admin.api.scayle.cloud/api/admin/v1/admin-api.json`, authorizations: { accessToken: { value: process.env.ADMIN_API_TOKEN, }, }, }); const shop = { name: "The Kernel Kiosk 2", key: "k2", // Must be 2 chars long countries: [ { countryCode: "de", // en, gb, de, fr, es defaultLanguageCode: "en_GB", // en_GB, en_US, de_DE, fr_FR, es_ES currencyCode: "EUR", // USD, EUR, GBP, JPY, CHF url: "http://www.kernel_kiosk.com", }, ], }; try { let response = await client.apis.Shops.createShop( {}, { requestBody: shop } ); let createdShop = response.body; console.log("Created Shop", createdShop); } catch (error) { console.error("Errors", error.response.body.errors); } } addShop(); ``` -------------------------------- ### Example: Get a Product Master Attribute Source: https://scayle.dev/documentation/the-basics/products/manage-products-via-api/manage-products-master-data?sourceText=GetProductMasterAttribute An example demonstrating how to fetch a specific product master attribute, such as 'material', for a given product master. ```javascript let response = await adminApi.apis.Masters.getProductMasterAttribute({ productMasterIdentifier: 1, attributeGroupName: "material" }); let productMasterAttribute = response.body; ``` -------------------------------- ### Create Product Example Source: https://scayle.dev/documentation/the-basics/products/manage-products-via-api/manage-products?sourceText=Creating%2520Products Demonstrates the structure for creating a new product, including details like SKU, name, description, pricing, and custom data. Ensure all required fields are populated. ```json { "sku": "EXAMPLE-SKU-123", "name": "Example Product Name", "description": "This is an example product description.", "brandId": "example-brand-id", "categories": [ { "id": "example-category-id" } ], "attributes": [ { "name": "example-attribute-name", "value": "example-attribute-value" } ], "isSellableWithoutStock": false } ``` -------------------------------- ### Copy .env.example to .env Source: https://scayle.dev/documentation/welcome-to-scayle/quick-start-guide/storefront-setup Create a .env file from the example configuration to set up your environment variables. ```bash cp .env.example .env ``` -------------------------------- ### Get A List Of Products Source: https://scayle.dev/documentation/the-basics/products/manage-products-via-api/manage-products?sourceText=%2523product-sellable-timeframes Retrieves a list of products, with the ability to apply filters such as color and variant EAN. This example shows how to get 10 products filtered by color. ```APIDOC ## Get A List Of Products ### Description Retrieves a list of products, with the ability to apply filters such as color and variant EAN. This example shows how to get 10 products filtered by color. ### Method GET ### Endpoint /products ### Query Parameters - **limit** (integer) - Optional - The maximum number of products to return. - **filters[attributes]** (object) - Optional - Filters products based on attribute values. Example: `{color: "green,red"}`. - **filters[variantEan]** (string) - Optional - Filters products by variant EAN. Example: `"01010101,01010102"`. ### Request Example ```javascript let response = await adminApi.apis.Products.getProducts({ "limit": 10, "filters[attributes]": {color: "green,red"}, "filters[variantEan]": "01010101,01010102" }); let products = response.body.entities; products.forEach( product => console.log(product.referenceKey) ); ``` ### Response #### Success Response (200) - **entities** (Product[]) - A list of product objects. #### Response Example ```json { "entities": [ { "id": 1, "problems": [], "referenceKey": "product-1", "name": {"en_GB": "Example Product"}, "state": "live", "attributes": [], "variants": [], "images": [], "productSortings": [], "isComposite": false, "merchantReferenceKeys": ["merchant-1"] } ] } ``` ``` -------------------------------- ### Get A List Of Products Source: https://scayle.dev/documentation/the-basics/products/manage-products-via-api/manage-products?sourceText=GetProductAttribute Retrieves a list of products, with the ability to apply filters such as color. This example shows how to get 10 products filtered by green and red colors. ```APIDOC ## Get A List Of Products ### Description Retrieves a list of products, with the ability to apply filters such as color. This example shows how to get 10 products filtered by green and red colors. ### Method GET ### Endpoint /products ### Query Parameters - **limit** (Integer) - Optional - The maximum number of products to return. - **filters[attributes]** (Object) - Optional - Filters products based on their attributes. Example: `{"color": "green,red"}`. - **filters[variantEan]** (String) - Optional - Filters products by variant EANs. Example: `"01010101,01010102"`. ### Response #### Success Response (200) - **entities** (Array) - A list of product objects. - **referenceKey** (String) - A key that uniquely identifies the product. - **name** (Object) - The localized product name. ### Response Example ```json { "entities": [ { "referenceKey": "product-1", "name": {"en_GB": "Green T-Shirt"} }, { "referenceKey": "product-2", "name": {"en_GB": "Red T-Shirt"} } ] } ``` ``` -------------------------------- ### Example .env Configuration Source: https://scayle.dev/documentation/welcome-to-scayle/quick-start-guide/storefront-setup This is a comprehensive example of the .env file, including settings for base URL, CDN, caching, session management, API endpoints, authentication, checkout, and local HTTPS. Replace placeholders like {TENANT_SPACE}, {STOREFRONT_API_TOKEN}, {OAUTH_CLIENT_ID}, {OAUTH_CLIENT_API_KEY}, {SHOP_ID}, and {COUNTRY_ID} with your specific values. ```dotenv # Where to launch the server BASE_URL=http://localhost:3000 # Where to find product and other images NUXT_PUBLIC_CDN_URL='https://{TENANT_SPACE}.cdn.scayle.cloud/' # Redis configuration for caching and session management # Cache NUXT_STOREFRONT_STORAGE_CACHE_PROVIDER=redis NUXT_STOREFRONT_STORAGE_CACHE_HOST=localhost NUXT_STOREFRONT_STORAGE_CACHE_PORT=6379 NUXT_STOREFRONT_STORAGE_CACHE_USERNAME= NUXT_STOREFRONT_STORAGE_CACHE_PASSWORD= NUXT_STOREFRONT_STORAGE_CACHE_TLS=false # Session NUXT_STOREFRONT_STORAGE_SESSION_PROVIDER=redis NUXT_STOREFRONT_STORAGE_SESSION_HOST=localhost NUXT_STOREFRONT_STORAGE_SESSION_PORT=6379 NUXT_STOREFRONT_STORAGE_SESSION_USERNAME= NUXT_STOREFRONT_STORAGE_SESSION_PASSWORD= NUXT_STOREFRONT_STORAGE_SESSION_TLS=false # Storefront API configuration NUXT_STOREFRONT_BAPI_HOST=https://{TENANT_SPACE}.storefront.api.scayle.cloud/v1/ NUXT_STOREFRONT_BAPI_TOKEN={STOREFRONT_API_TOKEN} # Login/Registration Configuration NUXT_STOREFRONT_OAUTH_API_HOST=https://{TENANT_SPACE}.auth.scayle.cloud NUXT_STOREFRONT_OAUTH_CLIENT_ID={OAUTH_CLIENT_ID} NUXT_STOREFRONT_OAUTH_CLIENT_SECRET={OAUTH_CLIENT_API_KEY} # Checkout configuration NUXT_STOREFRONT_STORES_{SHOP_ID}_CHECKOUT_USER={SHOP_ID} NUXT_STOREFRONT_STORES_{SHOP_ID}_CHECKOUT_TOKEN=token_{SHOP_ID} # this only works on demo environments, your SCAYLE contact can give you real credentials NUXT_STOREFRONT_STORES_{SHOP_ID}_CHECKOUT_SECRET=secret_{SHOP_ID} # this only works on demo environments, your SCAYLE contact can give you real credentials NUXT_STOREFRONT_STORES_{SHOP_ID}_CHECKOUT_HOST=https://{TENANT_SPACE}.checkout.api.scayle.cloud # HTTPS Configuration for local development HTTPS_KEY=localhost.pem HTTPS_CERT=localhost.crt # Google Tag Manager Configuration NUXT_PUBLIC_GTM_ID='GTM-123' # Storyblok Configuration NUXT_PUBLIC_STORYBLOK_ACCESS_TOKEN=SXHjiBBXemgHRENlt7kYrQtt # Ask your SCAYLE Contact for a test token ``` -------------------------------- ### Build and Preview Application Source: https://scayle.dev/documentation/storefront/storefront-application/getting-started/set-up-your-storefront Build the application for production and then run a preview server to simulate the production environment. This is useful for testing before deployment. ```bash # Build the application pnpm build # Run production preview pnpm preview ``` -------------------------------- ### Build and Preview Application Source: https://scayle.dev/documentation/storefront/storefront-application/getting-started/set-up-your-storefront?sourceText=Basic%2520Theming Builds the application for production and starts a local preview server. Ensure Redis is running. ```bash # Build the application pnpm build # Run production preview pnpm preview ``` -------------------------------- ### Example JWT Payload for Checkout Initialization Source: https://scayle.dev/documentation/storefront/checkout/implementation/headless-checkout/integration/initialize-checkout This is an example of the JWT payload required to authenticate the request for starting or continuing a checkout session. Ensure all required fields are present and correctly formatted. ```json { "iss": "https://scale.dev", "aud": "https://scayle.dev", "iat": 1744699678, "nbf": 1744699678, "exp": 1744706883, "basketId": "1404-b0d2336c-74cd" } ``` -------------------------------- ### Get the full category tree Source: https://scayle.dev/documentation/the-basics/shops/shop-categories/deeper-understanding-of-shop-categories?sourceText=ShopCategoryProperty Retrieves the entire shop category tree, starting from root categories. ```APIDOC ## Get Full Category Tree ### Description Retrieves the full shop category tree, which is typically used for navigation in an online shop. Root categories have a `parentId` of 0. ### Method GET ### Endpoint `/categories/roots` ### Query Parameters - **with** (object) - Optional - Specifies related data to include. Use `children: 1` to include child categories. - **depth** (integer) - Optional - Limits the number of levels to retrieve. ### Request Example ```typescript // Get full category tree const categories = await client.categories.getRoots({ with: { children: 1 }, }); for (const category of categories) { console.log(category.name) } ``` ### Response #### Success Response (200) - **categories** (array) - An array of category objects, each potentially containing `name`, `slug`, `path`, `description`, `parentId`, and `childrenIds`. #### Response Example ```json [ { "id": 1, "name": "Clothing", "parentId": 0, "childrenIds": [2, 3], "children": [ { "id": 2, "name": "Women", "parentId": 1, "childrenIds": [6], "children": [ { "id": 6, "name": "Shirts", "parentId": 2, "childrenIds": [] } ] }, { "id": 3, "name": "Men", "parentId": 1, "childrenIds": [] } ] } ] ``` ``` -------------------------------- ### Create a Complete Product via Admin API Source: https://scayle.dev/documentation/the-basics/products/manage-products-via-api/import-products?sourceText=Admin%2520API This JavaScript example demonstrates creating a comprehensive product, including variants, prices, images, custom data, and merchant references. The product is set to 'live' state. ```javascript let newProduct = { referenceKey: "myReferenceKey", name: { "de_DE": "Mein Produkt", "en_GB": "My Product" }, state: "live", master: { referenceKey: "myMasterReferenceKey", categories: { paths: [ [ "Fashion", "Women", "Shirts" ] ] } }, attributes: [ { name: "color", type: "localizedStringList", value: [ { de_DE: "rot", en_GB: "red" }, { de_DE: "blau", en_GB: "blue" } ] } ], variants: [ { referenceKey: "myVariantKey", attributes: [ { name: "size", type: "simple", value: "M" } ], prices: [ { price: 2499, tax: 19, currencyCode: "EUR", countryCode: "DE", } ] } ], images: [ { source: { url: "https://example.com/image.jpg" } } ], customData: { "additionalDetails": "details" }, merchantReferenceKeys: ["merchant-1", "merchant-2"] }; let response = await adminApi.apis.Products.createProduct({}, {requestBody: newProduct}); let createdProduct = response.body; ```