Purchase Invoice API
The Purchase Invoice API allows you to create purchase invoices that can either create new products or update existing products with additional inventory. This endpoint supports file uploads for product variant images and handles brand creation automatically.This endpoint uses
multipart/form-data format to support file uploads. Make sure to include the proper headers when making requests.Endpoint Details
Endpoint:POST /purchase-invoicesContent-Type:
multipart/form-dataBase URL:
https://jethings-backend.fly.dev
Required Headers
Request Structure
The request usesmultipart/form-data format with:
jsonData: A JSON string containing the purchase invoice data- Files: Product variant images uploaded with specific field names
Action Types
The API supports two action types:- CREATE
- UPDATE
Use Required fields for CREATE:
CREATE when introducing a brand new product to your inventory.actionType:"CREATE"product.title: Product namevariants: Array of variant objectswarehouseId,supplierId,purchaseDate,referenceNumber,amountPaid,productTypeId,isShipped,isPaid
Data Structures
Product Object
Theproduct object is used in CREATE actions to define product details.
Variant Structure
Thevariants array contains items and their sizes with quantities.
Pointer Structure
Each pointer represents a size with quantity:File Upload Mechanism
Naming Convention
Product variant images must be uploaded using this naming pattern:- CREATE Actions
- UPDATE Actions
Upload images for all variants:
Multiple Images per Variant
You can upload multiple images for each variant by sending multiple files with the same field name:Supported Image Formats
- jpg, jpeg, png, gif, webp
Complete Examples
This section provides detailed examples for both CREATE and UPDATE action types.CREATE Examples
Examples for creating new products
UPDATE Examples
Examples for adding inventory
CREATE Action Examples
Example 1: CREATE - New Product with Brand Creation
This example creates a new product with auto-brand creation.- Use Case: CREATE
Use when: You’re introducing a brand new product to your inventory that doesn’t exist yet.
Example 2: CREATE - Using Existing Brand
This example creates a new product using an existing brand ID instead of creating a new brand.- Use Case: CREATE
Use when: Creating a new product and want to link to an existing brand in your system.
UPDATE Action Examples
Example 3: UPDATE - Add Inventory to Existing Item
Use this when adding more stock to an existing color/variant.- Use Case: UPDATE with itemId
Use when: Adding inventory to an existing item variant. No file uploads needed.
itemId for existing items.
Example 4: UPDATE - Create New Item (Different Color)
Use this when adding a new color variant to an existing product.- Use Case: UPDATE without itemId
Use when: Creating a new item variant (new color) for an existing product. Requires file uploads.
itemName and upload images using variant_0_images.
Example 5: UPDATE - Mixed (Existing + New Items)
Adding inventory to Blue item and creating Red and Green items.- Use Case: UPDATE Mixed
Use when: Adding inventory to existing items AND creating new item variants in the same request.
Response Structure
Success Response
Error Responses
400 Bad Request
403 Forbidden
404 Not Found
Important Notes
CREATE vs UPDATE
CREATE Action
CREATE Action
- Creates a new product and its items/variants
- All variants get new items with the provided
itemName - Requires uploading images for all variants
- Use when introducing completely new products
UPDATE Action
UPDATE Action
- Updates an existing product
- Can add to existing items (with
itemId) or create new items (withoutitemId) - Only upload images for new items (without
itemId) - Use when restocking existing products
itemName Field
- Always required for all variants in both CREATE and UPDATE actions
- This name is stored in the
itemVariant.namecolumn in the database - Examples: “Blue T-Shirt”, “Red Shirt”, “Green Variant”
itemId Usage in UPDATE
With itemId
Add inventory to an existing item
No file uploads neededWithout itemId
Create a new item
Requires file uploadsFile Upload Rules
- CREATE Actions
- UPDATE with itemId
- UPDATE without itemId
Upload images for ALL variants:
Stock Management
- Quantities (
qtyin pointer) automatically update warehouse stock - Stock is distributed across warehouse bins
updateStock: trueenables real-time stock updates
Brand Handling
- Using Existing Brand
- Auto-Create Brand
- Priority Rule
brandId to reference an existing brandBarcode Assignment
The API supports two methods for barcode assignment:- Individual barcodes in pointer values - Specific to each size
- Global barcodes array - Applied to all item variants
Summary
1
Choose Action Type
Select CREATE for new products or UPDATE for existing products
2
Prepare Data
Structure your JSON data with product info, variants, and inventory details
3
Upload Files
Follow the naming convention for variant images based on your action type
4
Send Request
Use multipart/form-data with proper headers
5
Handle Response
Receive complete purchase invoice, product, and stock information
App Configuration
Configure your store settings
Store Management
Manage stores and permissions