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

# Code examples

> Try-on API examples in curl, Node.js, Python, PHP, and Ruby.

# Code examples

## curl

```bash theme={"dark"}
curl -X POST "https://api.wearo.io/functions/v1/tryon-api" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: wearo_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Origin: https://mystore.com" \
  -d '{
    "userPhoto": "https://example.com/customer-photo.jpg",
    "productImage": "https://mystore.com/products/blue-shirt.jpg",
    "clothingType": "T-shirt"
  }'
```

## Node.js

```javascript theme={"dark"}
const response = await fetch(
  'https://api.wearo.io/functions/v1/tryon-api',
  {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-Key': 'wearo_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
      'Origin': 'https://mystore.com'
    },
    body: JSON.stringify({
      userPhoto: 'https://example.com/customer-photo.jpg',
      productImage: 'https://mystore.com/products/blue-shirt.jpg',
      clothingType: 'T-shirt'
    })
  }
);

const data = await response.json();

if (data.success) {
  console.log('Try-on image:', data.resultUrl);
  console.log('Credits remaining:', data.creditsRemaining);
} else {
  console.error('Error:', data.error);
}
```

## Python

```python theme={"dark"}
import requests

response = requests.post(
    'https://api.wearo.io/functions/v1/tryon-api',
    headers={
        'Content-Type': 'application/json',
        'X-API-Key': 'wearo_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        'Origin': 'https://mystore.com'
    },
    json={
        'userPhoto': 'https://example.com/customer-photo.jpg',
        'productImage': 'https://mystore.com/products/blue-shirt.jpg',
        'clothingType': 'T-shirt'
    }
)

data = response.json()

if data.get('success'):
    print(f"Try-on image: {data['resultUrl']}")
    print(f"Credits remaining: {data['creditsRemaining']}")
else:
    print(f"Error: {data.get('error')}")
```

## PHP

```php theme={"dark"}
<?php
$response = file_get_contents('https://api.wearo.io/functions/v1/tryon-api', false, stream_context_create([
    'http' => [
        'method' => 'POST',
        'header' => implode("\r\n", [
            'Content-Type: application/json',
            'X-API-Key: wearo_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
            'Origin: https://mystore.com'
        ]),
        'content' => json_encode([
            'userPhoto' => 'https://example.com/customer-photo.jpg',
            'productImage' => 'https://mystore.com/products/blue-shirt.jpg',
            'clothingType' => 'T-shirt'
        ])
    ]
]));

$data = json_decode($response, true);

if ($data['success']) {
    echo "Try-on image: " . $data['resultUrl'];
} else {
    echo "Error: " . $data['error'];
}
```

## Ruby

```ruby theme={"dark"}
require 'net/http'
require 'json'
require 'uri'

uri = URI('https://api.wearo.io/functions/v1/tryon-api')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Post.new(uri)
request['Content-Type'] = 'application/json'
request['X-API-Key'] = 'wearo_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
request['Origin'] = 'https://mystore.com'
request.body = {
  userPhoto: 'https://example.com/customer-photo.jpg',
  productImage: 'https://mystore.com/products/blue-shirt.jpg',
  clothingType: 'T-shirt'
}.to_json

response = http.request(request)
data = JSON.parse(response.body)

if data['success']
  puts "Try-on image: #{data['resultUrl']}"
else
  puts "Error: #{data['error']}"
end
```
