OnModel

Introduction


OnModel is an application that enables clothing stores to:

  1. Change models in images
  2. Convert product images of clothes to model photos.

Company and App links: OnModel Shopify App OnModel Web Application Trendage, Inc.

Web Iframe Integration


<aside> ➡️ The following iframe integration is designed for partners with Web Apps.

</aside>

Demo

An iframe integration demo is linked. It contains a log section on the right side of the page to view events as they occur.

Installation

To integrate the OnModel iframe inside your web app, please follow the instructions below.

  1. Create an iframe element to load the OnModel application inside. The iframe is placed in sandbox mode with minimal required permissions for app functionality. Style the iframe for width, height, borders as needed.
<iframe id="onmodel-iframe" sandbox="allow-top-navigation allow-scripts allow-forms allow-popups-to-escape-sandbox"></iframe>
  1. Create a button in your web app to trigger loading the iframe.
<button id="btn-change-model">Change Model</button>
  1. Load the OnModel application in the iframe and send data once the button above is clicked using the javascript below. The data will be sent between the parent document and iframe using the postMessage API.

Note: The functionality of the application will be limited to test data until your partner ID and associated domain are approved by an OnModel staff member.

<script>

// Identify iframe element
onmodel_iframe = document.getElementById('onmodel-iframe');

// Identify button or element on your page to trigger opening the OnModel application
btn_change_model = document.getElementById('btn-change-model');

// When the user clicks the button above
btn_change_model.addEventListener('click', function() {

	// Load OnModel application URL inside iframe
	onmodel_iframe.src = 'https://shpint.onmodel.ai/modelswap_web/';

	// Create an object with your data to send to the iframe
	const jsonData = {
		partner: 'your_partner_company_name', // Your company name
    unique_session_id: 'unique_string', // Optional: a unique string to identify the session
		product_id: '123456789', // Optional: an internal product ID whose images you're sending
		product_imgs: [ // These are absolute image URLs whose models the user wants to change
				"https://i.imgur.com/Zeq7bii.jpg",
				"https://i.imgur.com/UaI3R5P.jpg",
				"https://i.imgur.com/LGPT8aT.jpg",
				"https://i.imgur.com/qXTHGyG.jpg"
				], 
		action: "change_model"
	};

	// Once the iframe is fully loaded, send the json data using postMessage
	onmodel_iframe.onload = function() {
		onmodel_iframe.contentWindow.postMessage(JSON.stringify(jsonData), '*');
	}

});

</script>
  1. The iframe will now load the OnModel application where the user can generate images and finalize their selections. When the user clicks “Finalize Images”, the OnModel application will send URLs of the generated images back to the parent document using postMessage.
{
  "status": "images_finalized",
  "unique_session_id": "unique_string",
  "product_id": "123456789",
  "new_generated_images": [
    "https://shpint.onmodel.ai/model_swap/img/set1-outputs/3e90c0-93729f.png",
    "https://shpint.onmodel.ai/model_swap/img/set1-outputs/8f9cb4-fdd609.png",
    "https://shpint.onmodel.ai/model_swap/img/set1-outputs/9de5b2-a4335e.png",
    "https://shpint.onmodel.ai/model_swap/img/set1-outputs/384e04-952b74.png"
  ]
}

  1. Add the following javascript to receive JSON data from the iframe.
<script>
window.addEventListener('message', function(event) {

    // Trigger only when event is coming from the approved domain
    var onmodel_iframe = document.getElementById('onmodel-iframe');
    
    if (event.origin !== "null" && event.source !== onmodel_iframe.contentWindow) {
        return;
    } else {
        console.log("Message received from the iframe: " + event.data); // Message received from child
				// Add functionality here as needed to use the generated image URLs provided from the iframe
    }

});
</script>

At this point, you can store the generated image URLs and display them to the user as needed.

Shopify App Iframe Integration


<aside> <img src="https://cdn3.iconfinder.com/data/icons/popular-services-brands-vol-2/512/shopify-512.png" alt="https://cdn3.iconfinder.com/data/icons/popular-services-brands-vol-2/512/shopify-512.png" width="40px" /> The following iframe integration is designed for partners with Shopify Apps

</aside>

Demo

A Shopify App Iframe integration demo is linked. It contains a log section on the right side of the page to view events as they occur.

Installation

To integrate the OnModel iframe inside your web app, please follow the instructions below.

  1. Create an iframe element to load the OnModel application inside.
<iframe id="onmodel-iframe" sandbox="allow-top-navigation allow-scripts allow-forms allow-popups-to-escape-sandbox"></iframe>

We recommend to style the iframe with a 1200px width, 100% max-width and 725px min-height. Although, it’s up to your discretion.

<style>
	#onmodel-iframe { 
	    width: 1200px; 
	    min-height: 725px; 
	    max-width: 100%;
	}
</style>
  1. Create a button in your web app to trigger loading the iframe.
<button id="btn-change-model">Change Model</button>
  1. Add the OnModel iframe script to your web application.
<script src="[https://shpint.onmodel.ai/onmodel_iframe.js](https://shpint.onmodel.ai/onmodel_iframe.js)"></script>
  1. Send data to the iframe once the button above is clicked. The data will be sent between the parent document and iframe using the postMessage API.
<script>

// Identify iframe element
onmodel_iframe = document.getElementById('onmodel-iframe');

// Identify button or element on your page to trigger opening the OnModel application
btn_change_model = document.getElementById('btn-change-model');

// When the user clicks the button above
btn_change_model.addEventListener('click', function() {

	// Load OnModel application URL inside iframe
	onmodel_iframe.src = 'https://shpint.onmodel.ai/modelswap_shopify/';

	// Create an object with your data to send to the iframe
	const jsonData = {
		partner: 'your_partner_company_name', // Your company name
		shopify_merchant: 'example_newmerchant.myshopify.com', // Shopify merchant's domain
		product_id: '123456789', // This is your internal product ID whose images you're sending
		product_imgs: [ // These are absolute image URLs whose models the user wants to change
				"https://i.imgur.com/Zeq7bii.jpg",
				"https://i.imgur.com/UaI3R5P.jpg",
				"https://i.imgur.com/LGPT8aT.jpg",
				"https://i.imgur.com/qXTHGyG.jpg"
				], 
		action: "change_model"
	};

	// Once the iframe is fully loaded, send the json data using postMessage
	onmodel_iframe.onload = function() {
		onmodel_iframe.contentWindow.postMessage(JSON.stringify(jsonData), '*');
	}

});

</script>
  1. At this point, the OnModel application will check if your partner_name and associated domain that is loading the iframe is authorized. It will respond with one of the following messages:

{"status": "authorization_success"}

{"status": "authorization_failed"}

If the authorization is successful, the user will be asked to install the OnModel app through the Shopify App Store. The OnModel app will send a message to the parent document:

{"status": "waiting_for_merchant_install"}

Once the user has installed the OnModel app on Shopify, they will be asked to return to your app.

{"status": "onmodel_app_installed"}

There is no action to take based on the messages above. Feel free to log or interact with them as desired.

  1. The user will then be redirected to the OnModel app where they can generate images and finalize their selections. When the user clicks “Finalize Images”, the OnModel application will send URLs of the generated images back to the parent document using postMessage.
{
  "status": "images_finalized",
  "shopify_merchant": "example_newmerchant.myshopify.com",
  "product_id": "123456789",
  "new_generated_images": [
    "https://shpint.onmodel.ai/model_swap/img/set1-outputs/3e90c0-93729f.png",
    "https://shpint.onmodel.ai/model_swap/img/set1-outputs/8f9cb4-fdd609.png",
    "https://shpint.onmodel.ai/model_swap/img/set1-outputs/9de5b2-a4335e.png",
    "https://shpint.onmodel.ai/model_swap/img/set1-outputs/384e04-952b74.png"
  ]
}

At this point, you can store the generated image URLs and display them to the user as needed.

API Integration


Use the following API endpoints to integrate OnModel’s tool into your application.

The base URL for all production API requests is:

https://api.onmodel.ai

The base URL for all development API requests is: https://api.dev.onmodel.ai

POST /model-swap/generate

Generates new model images

Parameters

Response

Returns a JSON object with the generated image URLs

Example

Request:

POST /model-swap/generate

Response:

{
    "status": "success",
    "generated_images": [
        {
            "url": "https://onmodel.s3.us-west-2.amazonaws.com/swap/jobs/540415/540415-1758a4.png"
        },
        ...
    ]
}

GET /model-swap/consistent-models-list

Returns a list of model IDs for the “Pick your model” feature

Response

Returns a JSON object with the list of models.

Example

Request:

GET /model-swap/consistent-models-list