Manufacturing and Production Quickstart Guide

Welcome to the Stateset One Manufacturing and Production Quickstart Guide! This guide will walk you through setting up your environment and using Stateset to manage your entire manufacturing process, from Bills of Materials (BOMs) to production execution and inventory management. Let’s imagine we are a mid-sized manufacturer looking to improve efficiency and reduce costs. By the end of this guide you will understand how to use Stateset to help us achieve these goals.

Table of Contents

  1. Introduction
  2. Getting Started
  3. Core Concepts
  4. API Walkthrough: End-to-End Manufacturing Workflow
  5. Manufacturing Process Optimization
  6. Real-Time Monitoring and Integration
  7. Error Handling and Logging
  8. Troubleshooting and Maintenance
  9. Support Resources
  10. Conclusion

Introduction

Stateset One provides a robust API for managing manufacturing and production operations. This guide will help you set up your environment, understand core concepts, use the API to handle workflows, implement optimization strategies and handle errors effectively.

What You’ll Learn:

  • How to set up your Stateset environment and use the SDK.
  • Core manufacturing concepts like BOMs, Work Orders, and Manufacturing Orders.
  • How to use the Stateset API to manage your production process from start to finish.
  • Strategies for optimizing your manufacturing workflow with data-driven decisions.
  • How to handle errors gracefully and integrate with other systems.

Getting Started

Let’s get your environment ready.

1. Sign Up for Stateset One

2. Generate an API Key

  • After signing in, go to the Stateset Cloud Console to generate a new API key. This key will authenticate your API requests.

3. Install the Stateset Node.js SDK

Integrate Stateset’s SDK into your project to simplify API interactions.

Using npm:

npm install stateset-node

Using yarn:

yarn add stateset-node

4. Set Up Environment Variables

Store your API key securely using environment variables. (Note: This example is for bash shell, adapt as needed for your environment)

export STATESET_API_KEY=your_api_key_here

5. Initialize the Stateset Client

Initialize the Stateset client in your application using the generated API key. (Note: Requires Node.js 16 or higher)

import { stateset } from 'stateset-node';

// Initialize with your API key
const client = new stateset(process.env.STATESET_API_KEY);

// Verify connection
async function verifyConnection() {
  try {
    const status = await client.system.healthCheck();
    console.log('Connection status:', status);
  } catch (error) {
    console.error('Failed to connect:', error);
  }
}

verifyConnection();

Note: The above example uses async/await which requires a Javascript engine that supports it.


Core Concepts

Before we start using the API, let’s get a handle on some key manufacturing concepts. Understanding these terms will make working with the API much clearer. Here is a simplified diagram to help visualize the key concepts:

  • Product: The end item you are producing, whether it is a final product ready for sale or a subassembly.

  • Bill of Materials (BOM): A structured list of all the raw materials, components, and assemblies required to manufacture a specific product. It’s essentially a recipe for your product. Think of it as the ingredients list for your product.

  • Work Order: A document that authorizes the production of a specific quantity of a product. It specifies the product to be produced, quantity and the associated BOM.

  • Manufacturing Order: Derived from a Work Order, the Manufacturing Order tracks the actual progress of production. It includes information about when production starts, what resources are used (machines, personnel), and materials consumed. It’s where you track the production process.

  • Picks: The process of selecting and preparing the necessary components from inventory for production. This process is tracked to make sure the correct items are used and ensures traceability.

  • Cycle Counts: Regular inventory audits, done periodically. This is used to verify that the inventory data is accurate.

  • Waste & Scrap: Tracking materials that are lost due to defects, errors, or other production issues. This is vital to understanding production efficiency and reducing losses.

  • Machines: The equipment used to produce your items. Tracking machine usage and maintenance is key to optimal operations.

  • Maintenance: Scheduled or ad-hoc tasks performed on machinery to prevent failures and ensure reliability.

  • Kitting: The process of creating a kit of components that are gathered together to assemble in a manufacturing step. This can make the production process more efficient.

  • Inventory: Tracking the components you have in stock. Accurate inventory data is necessary for effective production planning.

These concepts form the backbone of the manufacturing process and are key to understanding how the Stateset API helps manage it.


API Walkthrough: End-to-End Manufacturing Workflow

Now that we have a foundational understanding of core concepts, let’s walk through the process of using the Stateset API in a real-world scenario.

Workflow 1: Creating Products & BOMs

First, let’s define a product and its Bill of Materials.

Example 1: Creating a Product

async function createProduct(){
    try {
        const newProduct = await client.product.create({
          name: 'Advanced Widget',
          description: 'A high-performance widget for industrial applications',
          sku: 'AW-001'
        });
        console.log('New product created:', newProduct);
        return newProduct
    } catch (error) {
        console.error("Error creating product", error)
        throw error
    }
}

const product = await createProduct()

This creates a product named Advanced Widget which you can then use in BOMs.

Example 2: Creating a BOM

async function createBOM(product) {
    try {
        const newBOM = await client.billofmaterials.create({
           name: 'Advanced Widget BOM',
          description: 'Bill of Materials for our advanced widget',
          product_id: product.id,
          version: '1.0',
           components: [
            { item_id: 'item_001', quantity: 2, unit: 'pcs' },
            { item_id: 'item_002', quantity: 1, unit: 'kg' },
             { item_id: 'item_003', quantity: 0.5, unit: 'l' }
          ]
        });
       console.log('New BOM created:', newBOM);
       return newBOM
    } catch (error) {
       console.error("Error creating BOM", error)
        throw error
   }

}

const bom = await createBOM(product)

This code creates a new BOM for our “Advanced Widget” product, specifying the component items (identified by item_id) and their quantities. In this example we are using the product.id from the previous step to associate the BOM with the product.

Workflow 2: Planning Production

Now that we have a BOM, we can plan our production.

Example 1: Creating a Work Order

async function createWorkOrder(bom){
    try {
      const workOrder = await client.workorder.create({
        type: 'production',
        status: 'planned',
        priority: 'high',
        number: 'WO-2024-001',
        site: 'main_factory',
        bill_of_material_id: bom.id,
        work_order_line_items: [
          { item_id: 'item_001', quantity: 100 },
           { item_id: 'item_002', quantity: 50 }
       ]
     });
    console.log('Work Order created:', workOrder);
    return workOrder
    } catch (error) {
      console.error("Error creating work order", error)
        throw error
    }
}

const workOrder = await createWorkOrder(bom)

This code creates a Work Order for our “Advanced Widget,” associated with the BOM created previously using the bom.id. This signifies that we plan to manufacture 100 of item 001 and 50 of item 002.

Workflow 3: Executing Production

With our Work Order created, let’s begin the actual manufacturing process.

Example 1: Creating a Manufacturing Order

async function createManufacturingOrder(workOrder) {
  try {
    const manufacturingOrder = await client.manufacturingorder.create({
      type: 'production',
      status: 'in_progress',
      priority: 'high',
      number: 'MO-2024-001',
      site: 'main_factory',
      work_order_id: workOrder.id,
       manufacturing_order_line_items: workOrder.work_order_line_items
    });
     console.log('Manufacturing Order created:', manufacturingOrder);
    return manufacturingOrder
   } catch (error) {
      console.error("Error creating manufacturing order", error)
        throw error
    }
}
const manufacturingOrder = await createManufacturingOrder(workOrder)

This creates a Manufacturing Order based on the Work Order. In our example, the Manufacturing Order copies the work_order_line_items from the Work Order for reference. This signifies the start of production.

Example 2: Creating a Pick

Now that production has started, you’ll need to pick the materials.

async function createPick(manufacturingOrder) {
    try {
        const newPick = await client.picks.create({
            manufacturing_order_id: manufacturingOrder.id,
             status: 'pending',
              picker_id: 'user_789',
           items: [
                { inventory_item_id: 'inv_001', quantity: 10 },
                { inventory_item_id: 'inv_002', quantity: 5 }
            ]
         });

        console.log('New Pick created:', newPick);
        return newPick;
    } catch (error) {
      console.error("Error creating pick", error)
        throw error
    }
}
const pick = await createPick(manufacturingOrder);

This code initiates a new pick task to gather required inventory items inv_001 and inv_002 needed for production.

Example 3: Completing a Pick

Once a pick is complete, you can update it.

async function completePick(pick) {
    try {
      const completedPick = await client.picks.complete(pick.id, {
          completed_items: [
              { inventory_item_id: 'inv_001', quantity: 10 },
              { inventory_item_id: 'inv_002', quantity: 5 }
           ]
         });
      console.log('Pick completed:', completedPick);
      return completedPick
    } catch (error) {
        console.error("Error completing pick", error)
        throw error
    }
}

const completedPick = await completePick(pick);

This shows how to mark the pick as completed and specify the quantities that were actually picked. In this case we are assuming all items were picked and match the original requested quantities.

Example 4: Tracking Machine Time

During production you’ll want to track how long machines are being used.

async function logMachineRuntime(manufacturingOrder){
     try {
        const runtimeLog = await client.machines.logRuntime('machine_001', { // Replace machine_001 with a valid machine id
             start_time: new Date().toISOString(),
             end_time: new Date(new Date().getTime() + 3600000).toISOString(), // 1 hour from now
              manufacturing_order_id: manufacturingOrder.id
        });

        console.log('Machine runtime logged:', runtimeLog);
        return runtimeLog
     } catch (error) {
       console.error("Error logging machine runtime", error)
         throw error
     }
}

const runtimeLog = await logMachineRuntime(manufacturingOrder)

This example shows how to log the machine usage for a specific Manufacturing Order. Replace 'machine_001' with the actual ID of your machine

Example 5: Tracking Waste

If waste occurs during production, you can track that as well.

async function recordWaste(manufacturingOrder){
  try {
    const wasteRecord = await client.wasteAndScrap.create({
        manufacturing_order_id: manufacturingOrder.id,
        item_id: 'inv_001',
        quantity: 2,
        type: 'scrap', // or 'waste'
        reason: 'Quality control rejection',
        recorded_by: 'user_123'
       });
    console.log('Waste/Scrap recorded:', wasteRecord);
    return wasteRecord
  } catch (error) {
    console.error("Error recording waste", error)
    throw error
  }
}
const waste = await recordWaste(manufacturingOrder)

This code logs 2 units of inv_001 as scrap due to a quality control rejection.

Example 6: Completing a Manufacturing Order

Finally when production is done, the Manufacturing Order can be completed.

async function completeManufacturingOrder(manufacturingOrder){
  try{
      const updatedMO = await client.manufacturingorder.update(manufacturingOrder.id, {
         status: 'completed'
        });
    console.log('Manufacturing Order updated:', updatedMO);
    return updatedMO
  } catch (error) {
      console.error("Error updating manufacturing order", error)
      throw error
    }

}

const completedMO = await completeManufacturingOrder(manufacturingOrder)

This marks the Manufacturing Order as complete and closes the production loop.

Workflow 4: Inventory Management

Regular inventory checks are needed to maintain accurate data.

Example 1: Performing a Cycle Count

async function scheduleCycleCount(){
  try {
      const newCycleCount = await client.cycleCounts.create({
           scheduled_date: new Date(new Date().getTime() + 86400000).toISOString(), // one day from now
           location_id: 'loc_456',
          items: ['inv_001', 'inv_002', 'inv_003']
       });

      console.log('New Cycle Count scheduled:', newCycleCount);
      return newCycleCount
  } catch (error) {
    console.error("Error creating cycle count", error)
      throw error
  }

}

const cycleCount = await scheduleCycleCount()

This example shows how to schedule a cycle count for a set of items and location. This is a regular process to confirm inventory.


Manufacturing Process Optimization

Optimizing your manufacturing processes is key to reducing waste, minimizing costs, and improving efficiency. Stateset gives you the data needed to implement optimization strategies. Here are some key techniques:

  • Just-in-Time (JIT) Manufacturing: Optimize inventory levels to reduce waste and ensure timely delivery of raw materials.
  • Overall Equipment Effectiveness (OEE): Track machine uptime, performance, and quality to identify areas for improvement.
  • Pick Route Optimization: Calculate optimal routes for pickers in the warehouse to reduce the time it takes to complete picks.
  • Predictive Maintenance: Analyze machine runtime data to predict and prevent potential failures.
  • Waste Reduction: Use insights from waste and scrap data to improve processes and reduce losses.

Here’s an example of how you might calculate OEE with data from the Stateset API.

async function calculateOEE(manufacturingOrderId) {
    try {
        const mo = await client.manufacturingorder.get(manufacturingOrderId);
        const plannedProductionTime = 8; // Hours - this should come from Work Order details or other data
        const actualProductionTime = 7.5; // Hours - calculate actual time from Machine log entries for MO
        const idealCycleTime = 0.1; // Hours - this would come from manufacturing specifications
         const totalPieces = 100; // number of pieces from work order
        const goodPieces = 95; // pull from completed manufacturing order items

       const availability = actualProductionTime / plannedProductionTime;
        const performance = (idealCycleTime * totalPieces) / actualProductionTime;
         const quality = goodPieces / totalPieces;

        const oee = availability * performance * quality;
         console.log(`OEE for Manufacturing Order ${manufacturingOrderId}:`, oee);
         return oee;
     } catch(error) {
          console.error("Error calculating OEE", error)
        throw error
     }
 }
// Example usage. You would need to integrate with your data gathering to get the
//   real values
const oee = await calculateOEE('mo_example')

This snippet uses placeholder values but demonstrates how to calculate the Overall Equipment Effectiveness of a Manufacturing Order with the API data. You will want to expand on the gathering of the data to make sure your values are accurate.


Real-Time Monitoring and Integration

Real-time monitoring is key to ensuring that manufacturing operations are running smoothly and to identify areas for improvement. Stateset uses a combination of REST, GraphQL, and webhooks to provide updates on your systems.

Webhooks:

Webhooks are automated messages that are sent when something happens in Stateset. This enables you to get immediate feedback on system events without having to constantly request updates. When an event occurs, Stateset will notify an endpoint you’ve configured. You could use webhooks to track changes in order status, inventory levels, or new maintenance requests.

Examples of How to use Real-time Data and Integration

  • BI Dashboard Integration: Connect Stateset with a Business Intelligence tool to build a dashboard for production metrics, waste analysis, machine status, and more. This allows managers and decision-makers to have a comprehensive view of operations.
  • ERP Integration: Connect to your Enterprise Resource Planning (ERP) to automatically update inventory levels and supply chain data in response to manufacturing orders. This ensures the systems stay aligned.

Error Handling and Logging

Robust error handling and logging are necessary for stable operations. Here are some best practices:

  • API Error Responses: The Stateset API returns descriptive error messages. Always inspect the response when errors occur and handle the errors accordingly (e.g. bad request, missing fields, invalid keys, etc). Consult the API documentation for a full list of the error codes.

  • Retry Logic: Implement a retry mechanism for transient errors like network issues.

  • Centralized Logging: Send logs to a centralized logging service to assist with debugging and monitoring of the system.

async function safeManufacturingOperation(operation) {
  try {
    const result = await operation();
    console.log(`Operation successful: ${JSON.stringify(result)}`);
    return result;
  } catch (error) {
    console.error(`Error in manufacturing operation: ${error.message}`);
    // Log to external logging service
    // Placeholder for logging
     console.error("External Log:", {
       level: 'error',
       message: error.message,
       stack: error.stack,
      timestamp: new Date().toISOString()
      })
     // Placeholder for notification to personnel
     console.error("Notify Personnel:", error.message)
      throw error;
    }
  }

// Usage Example
const newWorkOrder = await safeManufacturingOperation(() =>
  client.workorder.create({
    type: 'production',
     status: 'planned',
    priority: 'high',
    number: 'WO-2024-002'
  })
);

In this example, we wrap the API call in a try/catch to catch any errors and add additional logging.


Troubleshooting and Maintenance

Here are some solutions for common issues and suggestions for maintaining your systems:

  • API Connection Failures:

    • Solution: Verify your API key is correct and active, check your internet connectivity, and verify the API endpoint is correct.
  • Data Inconsistencies:

    • Solution: Use regular cycle counts to verify inventory accuracy, ensure all processes are followed. Verify all API calls respond as expected.
  • Machine Downtime:

    • Solution: Implement a predictive maintenance schedule using data from the Stateset API (such as machine runtime).
  • Slow Performance:

    • Solution: Use the API to monitor your data, identify slow operations, make database and query optimization adjustments as needed.
  • SDK Updates:

    • Action: Regularly update your Stateset SDK to take advantage of the latest improvements. Be sure to review the change logs for potential compatibility issues.
  • Data Backups:

    • Action: Set up regular backups to prevent data loss.

Support Resources

If you encounter any issues, here are the resources to help:


Conclusion

By working through this quickstart guide, you should now have a better understanding of how to use the Stateset API to manage your manufacturing processes. You’ve learned how to set up your environment, plan your production, execute manufacturing orders, optimize processes, handle errors, integrate with other systems and maintain the health of your system. By following these steps, you can improve the efficiency and reduce the costs of your manufacturing process. For any additional help, please make sure to utilize the support resources.