# Color transfer

<div><figure><img src="https://1051631996-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWpWB3PhSXYf1uN1tGGIQ%2Fuploads%2FkH3ri2eEicoaX15EIVfE%2Fdd57c59f-2ded-11ef-afe9-42004e494300-0.png?alt=media&#x26;token=efbcf536-f438-472f-8872-70b97ae40e92" 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%2FbIwLG0CDuXk6faT6VtK6%2F433a8b4b-2ded-11ef-afe9-42004e494300-0.png?alt=media&#x26;token=20898767-c822-474e-a0ee-c794fd05797a" alt=""><figcaption><p>After</p></figcaption></figure></div>

## Description

Add your custom color into the existing room. Spacely AI color transfer AI will transfer the color into the room, making it smooth, seamless, and realistic.&#x20;

## Use cases

1. Transfer color into wall, floor, ceiling.
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/color-transfer`

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 room image where color will be painted on.</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> |
| area<mark style="color:red;">\*</mark>     | String | <p>This field contains the surface to paint color on.</p><p>Currently supports only "wall", "ceiling", and "floor"</p><p> </p>                                                                                                                                                                                                        |
| color<mark style="color:red;">\*</mark>    | String | The field is the color as a prompt. (e.g., sky blue)                                                                                                                                                                                                                                                                                  |

{% 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/color-transfer' \
--header 'X-API-KEY: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
    "imageUrl": "https://storage.googleapis.com/spacely-dev/product-placement-images/2e53a5ce9664dee4a2177bee61716893.jpg",
    "area": "wall",
    "color": "red"
}'
```

{% 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": "https://storage.googleapis.com/spacely-dev/product-placement-images/2e53a5ce9664dee4a2177bee61716893.jpg",
  "area": "wall",
  "color": "red"
});

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

fetch("https://api.spacely.ai/api/v1/generate/color-transfer", 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": "https://storage.googleapis.com/spacely-dev/product-placement-images/2e53a5ce9664dee4a2177bee61716893.jpg",
  "area": "wall",
  "color": "red"
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://api.spacely.ai/api/v1/generate/color-transfer',
  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/color-transfer"
  method := "POST"

  payload := strings.NewReader(`{
    "imageUrl": "https://storage.googleapis.com/spacely-dev/product-placement-images/2e53a5ce9664dee4a2177bee61716893.jpg",
    "area": "wall",
    "color": "red"
}`)

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

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("X-API-KEY", "sk-DVSWM_bh33ge6gcjNwfQnKG68rY")
  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>
