# Decoration placement

<div><figure><img src="https://1051631996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWpWB3PhSXYf1uN1tGGIQ%2Fuploads%2FncfnRdHcDXzBQiJ6DOhX%2FScreenshot%202567-03-11%20at%2015.46.36.png?alt=media&#x26;token=d7320b50-9321-49c7-a4fe-e07aa863f9f9" alt=""><figcaption><p>Before</p></figcaption></figure> <figure><img src="https://1051631996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWpWB3PhSXYf1uN1tGGIQ%2Fuploads%2FjtyvVqOJF1kVhgBC8FBb%2FScreenshot%202567-03-11%20at%2015.46.53.png?alt=media&#x26;token=552103d8-5dc2-4c90-9a77-02810621a79e" alt=""><figcaption><p>After - Decoration placed</p></figcaption></figure></div>

## Description

Add your decoration into the existing room. Spacely AI furniture placement AI will place the furniture into the room, making it smooth, seamless, and realistic. This API is better for a high detail decoration.

## Use cases

1. Visual style experimentation for client proposals.
2. Rapid concept generation for design projects.

## Credit

1 successful decoration placement API call = 1 credit.

## API

<mark style="color:green;">`POST`</mark> `https://api.spacely.ai/api/v1/generate/decoration-placement`

This endpoint is used to standard generate

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-API-KEY<mark style="color:red;">\*</mark> | String |             |

#### Request Body

| Name                                              | Type      | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------------------------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| imageUrl<mark style="color:red;">\*</mark>        | String    | <p>This field contains the URL of the background image where decoration will be placed.</p><p>(e.g., <a href="https://storage.googleapis.com/spacely-dev/product-placement-images/2e53a5ce9664dee4a2177bee61716893.jpg"><https://storage.googleapis.com/spacely-dev/product-placement-images/2e53a5ce9664dee4a2177bee61716893.jpg></a>")</p>                                                                                                                                                                                                                                            |
| productImageUrl<mark style="color:red;">\*</mark> | String    | <p>This field contains the URL of the PNG decoration product image that will be placed within the background image.</p><p>The product should be in PNG format with no background.</p><p> (e.g., <a href="https://storage.googleapis.com/spacely-dev/product-placement-images/1.png"><https://storage.googleapis.com/spacely-dev/product-placement-images/1.png></a>")</p>                                                                                                                                                                                                               |
| productWidth<mark style="color:red;">\*</mark>    | Float     | <p>The actual width of the product image. Must be in the same unit as productHeight and lineLength</p><p></p><p>If the product image has lots of padding, the productWidth might need to be bigger than the actual product width. </p>                                                                                                                                                                                                                                                                                                                                                  |
| productHeight<mark style="color:red;">\*</mark>   | Float     | <p>The actual height of the product image. Must be in the same unit as productWidth and lineLength</p><p></p><p>If the product image has lots of padding, the productHeight might need to be bigger than the actual product height. </p>                                                                                                                                                                                                                                                                                                                                                |
| referenceLine<mark style="color:red;">\*</mark>   | Object\[] | <p>The reference line in the background image that the actual  length is known. </p><p></p><p>The Object has 2 attributes: x, y. </p><p>e.g. </p><p>\[{ "x": 0, "y": 0},{"x":100.2,"y":100.2}]</p><p></p>                                                                                                                                                                                                                                                                                                                                                                               |
| lineLength<mark style="color:red;">\*</mark>      | Float     | <p>The actual length of the referenceLine.</p><p>Must be in the same unit as productWidth and productHeight.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| placement<mark style="color:red;">\*</mark>       | Object    | <p>This object describes the position and size of the decoration within the background image. It includes four attributes:</p><p></p><p>x: The x-coordinate (horizontal position) of the top-left corner of the decoration placement.</p><p></p><p>y: The y-coordinate (vertical position) of the top-left corner of the decoration placement.</p><p></p><p>w: The width of the decoration placement.</p><p></p><p>h: The height of the decoration placement.</p><p></p><p>Please note that the x,y coordinate starts at the top-left corner of the image and can only be positive.</p> |
| isRemove                                          | Boolean   | Whether or not to remove something from the background image before placing the decoration.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| removeArea                                        | Object    | <p>This object defines the area within the background image where there is existing decoration and should be removed. </p><p></p><p>It includes four attributes similar to placement.</p>                                                                                                                                                                                                                                                                                                                                                                                               |

{% tabs %}
{% tab title="200: OK Response ref Id for pulling data" %}

```json
{
  "data": REF_ID
}
```

{% endtab %}

{% tab title="400: Bad Request Not Found: Requested resource not found on the server." %}

{% endtab %}

{% tab title="401: Unauthorized The API key provided was invalid or missing." %}

{% endtab %}

{% tab title="500: Internal Server Error Unexpected condition on the server preventing request fulfillment." %}

{% endtab %}
{% endtabs %}

## Example

{% tabs %}
{% tab title="cURL" %}

```sh
curl --location 'https://api.spacely.ai/api/v1/generate/decoration-placement' \
--header 'X-API-KEY: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
    "imageUrl": IMAGE_URL,
    "productImageUrl": IMAGE_URL,
    "productWidth": 100.1,
    "productHeight": 120.1,
    "referenceLine": [
        {
            "x": 361.1,
            "y": 424.1
        },
        {
            "x": 361.1,
            "y": 289.1
        }
    ],
    "lineLength": 100.1,
    "placement": {
        "x": 85.1,
        "y": 0.1,
        "w": 90.1,
        "h": 250.1
    },
    "isRemove": true,
    "removeArea": {
        "x": 85.1,
        "y": 0.1,
        "w": 90.1,
        "h": 250.1
    }
}'
```

{% endtab %}

{% tab title="JavaScript  " %}

```javascript

const myHeaders = new Headers();
myHeaders.append("X-API-KEY", YOUR_API_KEY);
myHeaders.append("Content-Type", "application/json");

const raw = JSON.stringify({
  "imageUrl": IMAGE_URL,
  "productImageUrl": IMAGE_URL,
  "productWidth": 100.1,
  "productHeight": 120.1,
  "referenceLine": [
    {
      "x": 361.1,
      "y": 424.1
    },
    {
      "x": 361.1,
      "y": 289.1
    }
  ],
  "lineLength": 100.1,
  "placement": {
    "x": 85.1,
    "y": 0.1,
    "w": 90.1,
    "h": 250.1
  },
  "isRemove": true,
  "removeArea": {
    "x": 85.1,
    "y": 0.1,
    "w": 90.1,
    "h": 250.1
  }
});

const requestOptions = {
  method: "POST",
  headers: myHeaders,
  body: raw,
  redirect: "follow"
};

fetch("https://api.spacely.ai/api/v1/generate/decoration-placement", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));
```

{% endtab %}

{% tab title="NodeJs" %}

```javascript
const axios = require('axios');
let data = JSON.stringify({
  "imageUrl": IMAGE_URL,
  "productImageUrl": IMAGE_URL,
  "productWidth": 100.1,
  "productHeight": 120.1,
  "referenceLine": [
    {
      "x": 361.1,
      "y": 424.1
    },
    {
      "x": 361.1,
      "y": 289.1
    }
  ],
  "lineLength": 100.1,
  "placement": {
    "x": 85.1,
    "y": 0.1,
    "w": 90.1,
    "h": 250.1
  },
  "isRemove": true,
  "removeArea": {
    "x": 85.1,
    "y": 0.1,
    "w": 90.1,
    "h": 250.1
  }
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://api.spacely.ai/api/v1/generate/decoration-placement',
  headers: { 
    'X-API-KEY': 'YOUR_API_KEY', 
    'Content-Type': 'application/json'
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.spacely.ai/api/v1/generate/decoration-placement"
  method := "POST"

  payload := strings.NewReader(`{
    "imageUrl": IMAGE_URL,
    "productImageUrl": IMAGE_URL,
    "productWidth": 100.1,
    "productHeight": 120.1,
    "referenceLine": [
        {
            "x": 361.1,
            "y": 424.1
        },
        {
            "x": 361.1,
            "y": 289.1
        }
    ],
    "lineLength": 100.1,
    "placement": {
        "x": 85.1,
        "y": 0.1,
        "w": 90.1,
        "h": 250.1
    },
    "isRemove": true,
    "removeArea": {
        "x": 85.1,
        "y": 0.1,
        "w": 90.1,
        "h": 250.1
    }
}`)

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("X-API-KEY", "YOUR_API_KEY")
  req.Header.Add("Content-Type", "application/json")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://api.spacely.ai/api/v1/generate/decoration-placement"

payload = json.dumps({
  "imageUrl": IMAGE_URL,
  "productImageUrl": IMAGE_URL,
  "productWidth": 100.1,
  "productHeight": 120.1,
  "referenceLine": [
    {
      "x": 361.1,
      "y": 424.1
    },
    {
      "x": 361.1,
      "y": 289.1
    }
  ],
  "lineLength": 100.1,
  "placement": {
    "x": 85.1,
    "y": 0.1,
    "w": 90.1,
    "h": 250.1
  },
  "isRemove": True,
  "removeArea": {
    "x": 85.1,
    "y": 0.1,
    "w": 90.1,
    "h": 250.1
  }
})
headers = {
  'X-API-KEY': 'YOUR_API_KEY',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

{% endtab %}
{% endtabs %}

## Tips and tricks

After receiving the response, use this api to retrieve the data.

{% content-ref url="../other-endpoints/get-resources" %}
[get-resources](https://docs.enterprise.spacely.ai/spacely-ai-enterprise/other-endpoints/get-resources)
{% endcontent-ref %}

## Support

Any question? Contact us at <support@spacely.ai>
