# AI Renovation Services

{% hint style="danger" %}
Kindly bear in mind that this feature is currently available. However, to activate it, please reach out to <noshad@aihomedesign.com>.
{% endhint %}

## Overview&#x20;

The v2 API introduces support for new renovation services, including AI Ceiling Change, AI Furniture Set Restyle, AI Floor Change, AI Wall Change, and AI Backsplash Change. These services allow users to modify specific elements of uploaded images using AI-powered tools. The supported `service_name` values for renovation services are:

* `service-ceiling-change`
* `service-replace-furniture-set`
* `service-change-the-floor`
* `service-change-your-wall`
* `service-backsplash`

Unlike v1, the image upload in v2 does not require specifying a `service_name`, and the returned `image_id` is used to initialize an order with a specific service, providing greater flexibility. Authentication uses an `x-api-key` header for protected endpoints.

The workflow is as follows: upload an image to get an `image_id`, initialize the order with the `image_id` and `service_name` to get an `order_id`, retrieve available spaces and widgets using v1 catalog endpoints, then submit the order with selected configurations.

### Image Upload

#### Uploading Image(s) to Initialize an Order

**Explanation**

This API endpoint allows users to upload images to the server. It is designed to handle image files and store them in the server's storage system. The API supports a wide range of image formats, including JPG, JPEG, PNG, and WEBP, as well as RAW file formats such as DNG, ARW, RAF, NEF, etc.

**POST** `https://api.aihomedesign.com/v2/image`

**Request Body**

Ensure that your request body is in the `multipart/form-data` format.

| Name    | Type | Description                               |
| ------- | ---- | ----------------------------------------- |
| image\* | File | <p>Your image file<br>Max size: 50 MB</p> |

**Headers**

| Key         | Value                |
| ----------- | -------------------- |
| x-api-key\* | your\_api\_key\_here |

**Response**

* **200: OK**; image successfully uploaded
* **400: Bad Request**; no such file

```json
{
    "image_id": "string",
    "image_src": "string"
}
```

If the image uploads successfully, the response will include an `image_id` and `image_src`. Make sure you keep the `image_id`. You’ll need it to initialize the order.

**Example cURL**

```bash
curl --location 'https://api.aihomedesign.com/v2/image' \
--header 'x-api-key: sample_key_1234567890abcdef' \
--form 'image=@"/path/to/your/image.jpg"'
```

### Initialize Order

#### Initializing an Order with Service

**Explanation**

This API endpoint allows users to initialize a new order using the uploaded image and specifying the renovation service.

**POST** `https://api.aihomedesign.com/v2/order`

**Request Body**

Ensure that your request body is in the `application/json` format.

```json
{
    "image_id": "string",
    "service_name": "string"
}
```

* `image_id`: This should match the `image_id` returned by the Image Upload API.
* `service_name`: The name of the renovation service (e.g., `service-ceiling-change`, `service-replace-furniture-set`, `service-change-the-floor`, `service-change-your-wall`, `service-backsplash`).

**Headers**

| Key          | Value                |
| ------------ | -------------------- |
| x-api-key\*  | your\_api\_key\_here |
| accept       | application/json     |
| content-type | application/json     |

**Response**

* **200: OK**

```json
{
    "order_id": "string"
}
```

**Example cURL**

```bash
curl --location 'https://api.aihomedesign.com/v2/order' \
--header 'x-api-key: sample_key_1234567890abcdef' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data-raw '{
    "image_id": "9da9f084-7475-40ed-bf42-0065f2988faa",
    "service_name": "service-ceiling-change"
}'
```

### Get Spaces

#### Explanation

This API endpoint allows users to retrieve available spaces for a given service. A Space refers to a specific area or room associated with the service you’re requesting. For renovation services, the `space_name` field may be required to identify the room type (e.g., living room, bedroom, kitchen) or a specific project associated with the uploaded image.

**GET** `https://api.aihomedesign.com/v1/catalog/spaces?active=true&service_name={service_name}`

**Query Parameters**

| Name            | Type    | Description                                              |
| --------------- | ------- | -------------------------------------------------------- |
| active          | boolean | Filter for active spaces (default: true)                 |
| service\_name\* | string  | The name of the service (e.g., `service-ceiling-change`) |

**Headers**

No authentication required for this endpoint.

**Response**

* **200: OK**

```json
{
    "data": [
        {
            "id": "string",
            "name": "space-bedroom",
            "title": "Bedroom",
            "description": "",
            "prompt": "Bedroom",
            "service_ids": [
                "string"
            ],
            "icon_src": "string",
            "is_active": true,
            "priority": 0,
            "is_premium": false,
            "is_multi_space": false
        }
        // ... more spaces
    ]
}
```

> **Note**: Images shown in this documentation may not reflect the latest updates or design changes on the website.

### Get Widgets and Items

#### Explanation

This API endpoint allows users to retrieve available widgets and their items for a given service and space. Widgets are options that enhance your order. Depending on the service, widgets can either be optional or mandatory. For example, a widget might let you choose a material, style, or specific enhancement.

Items are the specific values or choices available for each widget. For instance, if a widget allows you to select a ceiling material, the items could be options like "Wooden Ceiling," "White Coffered," etc.

**GET** `https://api.aihomedesign.com/v1/catalog/items/filter?service_name={service_name}&space_name={space_name}`

**Query Parameters**

| Name            | Type   | Description                                              |
| --------------- | ------ | -------------------------------------------------------- |
| service\_name\* | string | The name of the service (e.g., `service-ceiling-change`) |
| space\_name\*   | string | The name of the space (e.g., `space-bedroom`)            |

**Headers**

No authentication required for this endpoint.

**Response**

* **200: OK**

```json
{
    "data": [
        {
            "id": "string",
            "title": "Material",
            "description": "Ceiling Change",
            "is_optional": false,
            "items": [
                {
                    "id": "string",
                    "title": "Wooden Ceiling",
                    "prompt": "Wood Ceiling",
                    "icon_src": "string",
                    "is_premium": false
                }
                // ... more items
            ],
            "priority": 20,
            "type": "tile"
        }
        // ... more widgets
    ]
}
```

> **Note**: Images shown in this documentation may not reflect the latest updates or design changes on the website.

### Submit a Renovation Order

#### Explanation

This API endpoint allows users to submit new orders for renovation services such as AI Ceiling Change, AI Furniture Set Restyle, AI Floor Change, AI Wall Change, or AI Backsplash Change. Use the `order_id` from the initialize order step, along with the `space_name` and `selected_widgets` retrieved from the respective endpoints.

Each renovation service requires specific widgets (e.g., "Material" for Ceiling Change).

**PUT** `https://api.aihomedesign.com/v2/order`

**Request Body**

Ensure that your request body is in the `application/json` format.

```json
{
    "order_id": "string",
    "space_name": "string",
    "selected_widgets": [
        {
            "item_id": "string",
            "id": "string"
        }
    ]
}
```

* `order_id`: This should match the `order_id` returned by the Initialize Order API.
* `space_name`: Retrieve from the Get Spaces endpoint (e.g., `space-bedroom`).
* `selected_widgets`:
  * `item_id`: The selected item ID from the Get Widgets and Items endpoint.
  * `id`: The widget ID from the Get Widgets and Items endpoint.

**Headers**

| Key          | Value                |
| ------------ | -------------------- |
| x-api-key\*  | your\_api\_key\_here |
| accept       | application/json     |
| content-type | application/json     |

**Response**

* **200: OK**
* **400: Bad Request**

```json
{
    "order_id": "string",
    "image_id": "string",
    "eta": "integer"
}
```

**Example for AI Ceiling Change**

```bash
curl --location 'https://api.aihomedesign.com/v2/order' \
--header 'x-api-key: sample_key_1234567890abcdef' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--request PUT \
--data-raw '{
    "order_id": "d01500eb-e64f-4b47-a42e-6189cd1a70f3",
    "space_name": "space-bedroom",
    "selected_widgets": [
        {
            "item_id": "6633ac751bce2af20a437be9",
            "id": "65b646a00cb36c6ab337456e"
        }
    ]
}'
```

For other renovation services (e.g., AI Floor Change), use the same endpoint but select appropriate widgets and items from the Get Widgets and Items API. Adjust the `selected_widgets` array accordingly based on the service's requirements.
