Usage Example

Since there's a lot of combinations of the preferences that you can use, so we've prepared an code example that will help you understand how to work with them.

Let's repeat the process of creating and uploading images, but with all of the Basic Enhancements.

You can freely edit the preferences in any way you want. The only requirement is to follow our Image Settings guide or API specification, which will help you find the appropriate values.

const apiKey = 'YOUR_API_KEY';
const preferences = {
    enhance_type: 'property',
    sky_replacement: true,
    cloud_type: 'CLEAR',
    vertical_correction: true,
    auto_privacy: true,
};

const createImage = async (apiKey, preferences) => {
    const createImageResponse = await fetch('https://api.autoenhance.ai/v3/images/', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'x-api-key': apiKey,
        },
        body: JSON.stringify({
            image_name: 'your-image-name',
            contentType: 'image/jpeg',
            ...preferences
        }),
    });

    const { s3PutObjectUrl, order_id, image_id } = await createImageResponse.json();

    const uploadImageResponse = await fetch(s3PutObjectUrl, {
        method: 'PUT',
        headers: {
            'Content-Type': 'image/jpeg',
            'x-api-key': apiKey,
        },
        body: blob,
    });

    if (uploadImageResponse.ok) {
        console.log('Image successfully uploaded');
    } else {
        console.log('Error uploading image');
    }
};

Last updated