> ## Documentation Index
> Fetch the complete documentation index at: https://watermelon.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Woocommerce template

The WooCommerce Custom Action connects your Agent to your WooCommerce store so it can retrieve product information and use it when answering customer questions.

This setup includes:

* A predefined OpenAPI schema for WooCommerce
* API key authentication
* Query parameters for your WooCommerce credentials
* A health check configuration

After setting up the Action, you can validate it, activate it, and test it in the Playground.

## Set up the action

1. Go to **Actions** in Watermelon.
2. In the **Actions catalog**, click **Custom action**.
3. Click **Create new Action**.
4. Fill in the fields below.

### General details

**Action name**<br />`WooCommerce product retrieval`

**Description**<br />`This action lets you get product information and use it in your chatbot when customers ask for it.`

**BaseURL**<br />`[YOUR WOOCOMMERCE API URL]`

Use your WooCommerce REST API URL, for example:

`https://yourdomain.com/wp-json/wc/v3/`

### Authentication

For **Authorization Header**, select **API key**.

For **Auth Type**, select **Custom**.

For **Add to**, select **Query parameters**.

Add the following query parameters:

**Query name #1**<br />`consumer_key`

**Query value #1**<br />`[YOUR CONSUMER KEY]`

**Query name #2**<br />`consumer_secret`

**Query value #2**<br />`[YOUR CONSUMER SECRET]`

Replace these values with the Consumer Key and Consumer Secret from your WooCommerce REST API credentials.

### Health check

**Health check URL**<br />`https://www.yourdomain.com/health_check`

Replace this URL with the health check endpoint you want Watermelon to use.

**Instruction**

> You should respond with the following message or a similar variation: Sorry, something went wrong on our end. Can I assist you with anything else? Please let me know how I can help.

### Schema

Paste the WooCommerce schema into the **Schema** field:

```text theme={null}
openapi: 3.0.3
info:
  title: Order API
  description: API for managing orders.
  version: 1.0.0
servers:
  - url: https://example.com/wp-json/wc/v3
    description: Production server
paths:
  /orders/{id}:
    get:
      summary: Retrieve an order by ID
      description: Fetch an order by its unique identifier.
      parameters:
        - name: id
          in: path
          description: Unique identifier for the order
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Order details retrieved successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'
        '404':
          description: Order not found
        '500':
          description: Internal server error
components:
  securitySchemes:
    CustomerKey:
      type: apiKey
      name: X-Customer-Key
      in: header
    ClientSecretKey:
      type: apiKey
      name: X-Client-Secret
      in: header
  schemas:
    Order:
      type: object
      properties:
        id:
          type: integer
          description: Unique identifier for the resource.
          readOnly: true
        parent_id:
          type: integer
          description: Parent order ID.
        number:
          type: string
          description: Order number.
          readOnly: true
        order_key:
          type: string
          description: Order key.
          readOnly: true
        created_via:
          type: string
          description: Shows where the order was created.
        version:
          type: string
          description: Version of WooCommerce which last updated the order.
        status:
          type: string
          description: >
            Order status. Options: pending, processing, on-hold, completed, cancelled,
            refunded, failed, trash. Default is pending.
        currency:
          type: string
          description: Currency the order was created with, in ISO format.
        date_created:
          type: string
          format: date-time
          description: The date the order was created, in the site's timezone.
        date_created_gmt:
          type: string
          format: date-time
          description: The date the order was created, as GMT.
        date_modified:
          type: string
          format: date-time
          description: The date the order was last modified, in the site's timezone.
        date_modified_gmt:
          type: string
          format: date-time
          description: The date the order was last modified, as GMT.
        discount_total:
          type: string
          description: Total discount amount for the order.
        discount_tax:
          type: string
          description: Total discount tax amount for the order.
        shipping_total:
          type: string
          description: Total shipping amount for the order.
        shipping_tax:
          type: string
          description: Total shipping tax amount for the order.
        cart_tax:
          type: string
          description: Sum of line item taxes only.
        total:
          type: string
          description: Grand total.
        total_tax:
          type: string
          description: Sum of all taxes.
        prices_include_tax:
          type: boolean
          description: True if the prices included tax during checkout.
        customer_id:
          type: integer
          description: User ID who owns the order.
        customer_note:
          type: string
          description: Note left by customer during checkout.
        payment_method:
          type: string
          description: Payment method ID.
        payment_method_title:
          type: string
          description: Payment method title.
        date_paid:
          type: string
          format: date-time
          description: The date the order was paid, in the site's timezone.
        billing:
          $ref: '#/components/schemas/Billing'
        shipping:
          $ref: '#/components/schemas/Shipping'
        line_items:
          type: array
          description: List of line items in the order.
          items:
            $ref: '#/components/schemas/LineItem'
        tax_lines:
          type: array
          description: List of tax lines in the order.
          items:
            $ref: '#/components/schemas/TaxLine'
        shipping_lines:
          type: array
          description: List of shipping lines in the order.
          items:
            $ref: '#/components/schemas/ShippingLine'
        meta_data:
          type: array
          description: List of meta data entries.
          items:
            $ref: '#/components/schemas/MetaData'
    Billing:
      type: object
      properties:
        first_name:
          type: string
        last_name:
          type: string
        company:
          type: string
        address_1:
          type: string
        address_2:
          type: string
        city:
          type: string
        state:
          type: string
        postcode:
          type: string
        country:
          type: string
        email:
          type: string
        phone:
          type: string
    Shipping:
      type: object
      properties:
        first_name:
          type: string
        last_name:
          type: string
        company:
          type: string
        address_1:
          type: string
        address_2:
          type: string
        city:
          type: string
        state:
          type: string
        postcode:
          type: string
        country:
          type: string
    LineItem:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        product_id:
          type: integer
        quantity:
          type: integer
        subtotal:
          type: string
        total:
          type: string
    TaxLine:
      type: object
      properties:
        id:
          type: integer
        rate_code:
          type: string
    ShippingLine:
      type: object
      properties:
        id:
          type: integer
        method_title:
          type: string
        total:
          type: string
    MetaData:
      type: object
      properties:
        id:
          type: integer
        key:
          type: string
        value:
          type: string
security:
  - CustomerKey: []
  - ClientSecretKey: []
```

Click **Validate** to check the schema.

### Example in Watermelon

<Frame>
  <img src="https://mintcdn.com/watermelon/U1o80ZmdmQTd06X6/images/WooCommerce-action-template.png?fit=max&auto=format&n=U1o80ZmdmQTd06X6&q=85&s=945d09386bf15feaa2bb7607ee92d016" alt="Woo Commerce Action Template" width="3838" height="1876" data-path="images/WooCommerce-action-template.png" />
</Frame>

When everything is configured correctly, click **Save** and then **Activate**.

Finally, test the Action in the **Playground** to make sure your Agent can retrieve the expected WooCommerce product information.

## Editing an Action Template

After setting up an Action, you can adjust it to your use case. For example, you can add endpoints to the schema, change parameters, or update the name and description.

Be careful when changing authentication settings or existing endpoints, as this can prevent the Action from connecting to the API.

## Troubleshooting

| Issue                                        | Likely cause                            | What to check                                             |
| :------------------------------------------- | :-------------------------------------- | :-------------------------------------------------------- |
| **Validation failed**                        | Invalid OpenAPI schema                  | Check the schema for missing or unsupported fields.       |
| **401 Unauthorized**                         | Incorrect WooCommerce credentials       | Check your Consumer Key and Consumer Secret.              |
| **404 Not Found**                            | Incorrect store URL or endpoint         | Check the BaseURL and endpoint path.                      |
| **Action does not return the expected data** | Schema or parameter mismatch            | Check the endpoint parameters and API response structure. |
| **Health check fails**                       | Health check endpoint cannot be reached | Check the Health check URL and authentication.            |
