OnModel is an application that enables clothing stores to:
Company and App links: OnModel Shopify App OnModel Web Application Trendage, Inc.
<aside> ➡️ The following iframe integration is designed for partners with Web Apps.
</aside>
An iframe integration demo is linked. It contains a log section on the right side of the page to view events as they occur.
To integrate the OnModel iframe inside your web app, please follow the instructions below.
<iframe id="onmodel-iframe" sandbox="allow-top-navigation allow-scripts allow-forms allow-popups-to-escape-sandbox"></iframe>
<button id="btn-change-model">Change Model</button>
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>
{
"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"
]
}
<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.
<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>
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.
To integrate the OnModel iframe inside your web app, please follow the instructions below.
<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>
<button id="btn-change-model">Change Model</button>
<script src="[https://shpint.onmodel.ai/onmodel_iframe.js](https://shpint.onmodel.ai/onmodel_iframe.js)"></script>
<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>
{"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.
{
"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.
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
/model-swap/generateGenerates new model images
Parameters
image-base64: Base64 of the input imageethnicity: One of the following values - [asian, black, southasian, middleeastern, pacificislander, latino, white]age: One of the following values - [18, 25, 35, 45, 55, 65]gender: One of the following values - [man, neutral, woman]expression: (optional) Default initial. One of the following values - [smile, neutral, initial]consistent-model-id: (optional) Default disabled. For model IDs to send see the /model-swap/consistent-model-list endpointbackground-scene: (optional) Default photo_studio.
One of the following values -
[beach, living_room, photo_studio, library, flower_garden, mountain_peak, industrial_warehouse, vineyard, amusement_park, city_skyline, sailboat, subway, graffiti, hotel, urban_street, parking_lot]hair-color: (optional) Default black.
One of the following values -
[black, blonde, blonde_dirty, blonde_platinum, brown, brown_red, red, white, gray, purple, pink, bald]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"
},
...
]
}
/model-swap/consistent-models-listReturns 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