# Shopify Integration via LowCodeAPI

## Overview

Shopify is a leading e-commerce platform for building online stores and selling products. The Shopify Admin API provides comprehensive functionality for:

- **Products** - Manage products, variants, and inventory
- **Orders** - Handle orders, transactions, and fulfillment
- **Customers** - Manage customer information and accounts
- **Collections** - Organize products into collections
- **Inventory** - Track and manage inventory levels
- **Discounts** - Create and manage discount codes
- **Shop** - Manage store settings and configuration

## Base Endpoint

```
https://api.lowcodeapi.com/shopify/
```

## Authentication

LowCodeAPI handles authentication automatically using OAuth2.0. You only need to:

1. **Create an app** at [Shopify Partners](https://partners.shopify.com) to get your Client ID and Secret
2. **Connect your account** in the LowCodeAPI dashboard
3. **Use your `api_token`** in all requests

The `api_token` is your LowCodeAPI authentication token. LowCodeAPI will automatically:
- Fetch your Shopify access token
- Apply it to each request as a Bearer token

**Auth Type**: OAuth2.0 (Bearer Token)
**Scopes**: Read/Write access for products, orders, customers, inventory, etc.

## API Categories

- **E-commerce** - Online store management and sales

## Common Endpoints

### Category: Products

#### Get Products

**Method**: `GET` | **LowCodeAPI Path**: `/admin/api/2024-10/products`

**Full URL**:
```
https://api.lowcodeapi.com/shopify/admin/api/2024-10/products?api_token={api_token}
```

**Description**: Retrieve all products with pagination.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `limit` | integer | No | Number of products to retrieve (default: 50, max: 250) |
| `since_id` | integer | No | Restrict results to after the specified ID |
| `fields` | string | No | Comma-separated list of fields to include |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/shopify/admin/api/2024-10/products?limit=50&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Get Products](https://shopify.dev/docs/api/admin-rest)

---

#### Get Product

**Method**: `GET` | **LowCodeAPI Path**: `/admin/api/2024-10/products/product_id`

**Full URL**:
```
https://api.lowcodeapi.com/shopify/admin/api/2024-10/products/product_id?id={product_id}&api_token={api_token}
```

**Description**: Retrieve a specific product by ID.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `id` | integer | Yes | Product ID |

**Example Request**:
```bash
# Replace PRODUCT_ID with actual product ID
curl -X GET "https://api.lowcodeapi.com/shopify/admin/api/2024-10/products/product_id?id=PRODUCT_ID&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Get Product](https://shopify.dev/docs/api/admin-rest)

---

#### Create Product

**Method**: `POST` | **LowCodeAPI Path**: `/admin/api/2024-10/products`

**Full URL**:
```
https://api.lowcodeapi.com/shopify/admin/api/2024-10/products?api_token={api_token}
```

**Description**: Create a new product.

**Request Body**:
```json
{
  "product": {
    "title": "Custom T-Shirt",
    "body_html": "<p>High-quality cotton t-shirt</p>",
    "vendor": "MyBrand",
    "product_type": "Apparel",
    "status": "active",
    "variants": [
      {
        "option1": "Small",
        "price": "29.99",
        "sku": "TSHIRT-S",
        "inventory_quantity": 100
      }
    ]
  }
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `title` | string | Yes | Product title |
| `body_html` | string | No | Product description in HTML |
| `vendor` | string | No | Product vendor |
| `product_type` | string | No | Product type |
| `status` | string | No | Product status (active, draft, archived) |
| `variants` | array | No | Product variants |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/shopify/admin/api/2024-10/products?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "product": {
      "title": "Custom T-Shirt",
      "body_html": "<p>High-quality cotton t-shirt</p>",
      "vendor": "MyBrand",
      "status": "active",
      "variants": [{"option1": "Small", "price": "29.99", "inventory_quantity": 100}]
    }
  }'
```

**Official Documentation**: [Create Product](https://shopify.dev/docs/api/admin-rest)

---

### Category: Orders

#### Get Orders

**Method**: `GET` | **LowCodeAPI Path**: `/admin/api/2024-10/orders`

**Full URL**:
```
https://api.lowcodeapi.com/shopify/admin/api/2024-10/orders?api_token={api_token}
```

**Description**: Retrieve all orders with pagination.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `status` | string | No | Filter by order status (open, closed, cancelled) |
| `limit` | integer | No | Number of orders to retrieve (default: 50, max: 250) |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/shopify/admin/api/2024-10/orders?status=open&limit=50&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Get Orders](https://shopify.dev/docs/api/admin-rest)

---

#### Create Order

**Method**: `POST` | **LowCodeAPI Path**: `/admin/api/2024-10/orders`

**Full URL**:
```
https://api.lowcodeapi.com/shopify/admin/api/2024-10/orders?api_token={api_token}
```

**Description**: Create a new order.

**Request Body**:
```json
{
  "order": {
    "line_items": [
      {
        "product_id": 123456789,
        "quantity": 1
      }
    ],
    "customer": {
      "first_name": "John",
      "last_name": "Doe",
      "email": "[email protected]"
    },
    "billing_address": {
      "first_name": "John",
      "last_name": "Doe",
      "address1": "123 Main St",
      "city": "New York",
      "zip": "10001",
      "country": "US"
    }
  }
}
```

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/shopify/admin/api/2024-10/orders?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "order": {
      "line_items": [{"product_id": 123456789, "quantity": 1}],
      "customer": {"first_name": "John", "last_name": "Doe", "email": "[email protected]"}
    }
  }'
```

**Official Documentation**: [Create Order](https://shopify.dev/docs/api/admin-rest)

---

### Category: Customers

#### Get Customers

**Method**: `GET` | **LowCodeAPI Path**: `/admin/api/2024-10/customers`

**Full URL**:
```
https://api.lowcodeapi.com/shopify/admin/api/2024-10/customers?api_token={api_token}
```

**Description**: Retrieve all customers with pagination.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `limit` | integer | No | Number of customers to retrieve (default: 50, max: 250) |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/shopify/admin/api/2024-10/customers?limit=100&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Get Customers](https://shopify.dev/docs/api/admin-rest)

---

#### Create Customer

**Method**: `POST` | **LowCodeAPI Path**: `/admin/api/2024-10/customers`

**Full URL**:
```
https://api.lowcodeapi.com/shopify/admin/api/2024-10/customers?api_token={api_token}
```

**Description**: Create a new customer.

**Request Body**:
```json
{
  "customer": {
    "first_name": "John",
    "last_name": "Doe",
    "email": "[email protected]",
    "phone": "+1234567890"
  }
}
```

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/shopify/admin/api/2024-10/customers?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": {
      "first_name": "John",
      "last_name": "Doe",
      "email": "[email protected]"
    }
  }'
```

**Official Documentation**: [Create Customer](https://shopify.dev/docs/api/admin-rest)

---

### Category: Batch

#### Batch Request

**Method**: `POST` | **LowCodeAPI Path**: `/admin/api/2024-10/batch`

**Full URL**:
```
https://api.lowcodeapi.com/shopify/admin/api/2024-10/batch?api_token={api_token}
```

**Description**: Execute multiple API requests in a single batch.

**Request Body**:
```json
{
  "requests": [
    {
      "method": "GET",
      "path": "/admin/api/2024-10/products/123456789"
    },
    {
      "method": "GET",
      "path": "/admin/api/2024-10/orders/987654321"
    }
  ]
}
```

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/shopify/admin/api/2024-10/batch?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "requests": [
      {"method": "GET", "path": "/admin/api/2024-10/products/123456789"},
      {"method": "GET", "path": "/admin/api/2024-10/orders/987654321"}
    ]
  }'
```

**Official Documentation**: [Batch Requests](https://shopify.dev/docs/api/admin-rest)

---

## Usage Examples

### Example 1: Manage Products

Create and retrieve products:

```bash
# Step 1: Create a new product
# No ID needed - creates new product
curl -X POST "https://api.lowcodeapi.com/shopify/admin/api/2024-10/products?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "product": {
      "title": "New Product",
      "body_html": "<p>Product description</p>",
      "variants": [{"price": "49.99", "inventory_quantity": 50}]
    }
  }'

# Step 2: Get all products
# No ID needed - lists all products
curl -X GET "https://api.lowcodeapi.com/shopify/admin/api/2024-10/products?limit=50&api_token=YOUR_API_TOKEN"

# Step 3: Get specific product
# Replace PRODUCT_ID with actual product ID
curl -X GET "https://api.lowcodeapi.com/shopify/admin/api/2024-10/products/product_id?id=PRODUCT_ID&api_token=YOUR_API_TOKEN"
```

### Example 2: Process Orders

Create and retrieve orders:

```bash
# Step 1: Create an order
# No ID needed - creates new order
curl -X POST "https://api.lowcodeapi.com/shopify/admin/api/2024-10/orders?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "order": {
      "line_items": [{"product_id": 123456789, "quantity": 2}],
      "customer": {"email": "[email protected]"},
      "financial_status": "paid"
    }
  }'

# Step 2: Get all orders
# No ID needed - lists all orders
curl -X GET "https://api.lowcodeapi.com/shopify/admin/api/2024-10/orders?status=open&api_token=YOUR_API_TOKEN"
```

### Example 3: Batch Operations

Execute multiple requests efficiently:

```bash
# Execute batch requests
# No ID needed - processes all requests
curl -X POST "https://api.lowcodeapi.com/shopify/admin/api/2024-10/batch?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "requests": [
      {"method": "GET", "path": "/admin/api/2024-10/products"},
      {"method": "GET", "path": "/admin/api/2024-10/customers"},
      {"method": "GET", "path": "/admin/api/2024-10/orders"}
    ]
  }'
```

## Complete Endpoint Reference

For a complete list of all 321 endpoints and their parameters, refer to:

- **OpenAPI Definition**: https://backend.lowcodeapi.com/shopify/definition
- **Official Shopify Documentation**: https://shopify.dev/docs/api/admin-rest

## Rate Limits & Best Practices

- **Rate Limit**: 40 calls per second (leaky bucket algorithm)
- **Best Practices**:
  - Use batch requests for multiple operations
  - Implement pagination for large result sets
  - Store Shopify IDs for efficient updates
  - Use webhooks for real-time updates
  - Cache frequently accessed data
  - Handle rate limiting with exponential backoff
  - Use appropriate scopes for security

## Error Handling

All responses are wrapped in a `data` key:
```json
{
  "data": {
    // Actual response from Shopify
  }
}
```

Common errors:
- **400**: Invalid request parameters
- **401**: Invalid or expired access token
- **402**: Payment required (API limit exceeded)
- **404**: Resource not found
- **422**: Unprocessable entity (validation error)
- **429**: Rate limit exceeded