The Style Upload iFrame communicates with your parent window through postMessage events. Listen for these events to handle the result of the style creation process.
Handling Responses #
Listen for message events from the iFrame to handle success or error states.
window.addEventListener("message", event => {
if (event.data.type === "STYLE_CREATED") {
console.log("Style created with ID:", event.data.styleId);
console.log("Style data:", event.data.style);
} else if (event.data.type === "STYLE_CREATE_ERROR") {
console.error("Style creation failed:", event.data.error);
}
});
Response Events #
| Event Type | Description |
|---|
| STYLE_CREATED | Fired when the style is successfully created. |
| STYLE_CREATE_ERROR | Fired if an error occurs during the creation process. |
STYLE_CREATED Event Data #
| Property | Type | Description |
|---|
| type | string | `STYLE_CREATED` |
| styleId | integer | The ID of the newly created style. |
| style | object | The complete style object with all details. |
Style Object Structure:
{
"styleId": 12345,
"name": "Dri-FIT Polo",
"model": "123456-78",
"manufacturerId": 987,
"brandName": "Nike",
"views": [
{ "viewId": 501, "view": "Front" },
{ "viewId": 502, "view": "Back" },
{ "viewId": 503, "view": "Left" },
{ "viewId": 504, "view": "Right" }
]
}
STYLE_CREATE_ERROR Event Data #
| Property | Type | Description |
|---|
| type | string | `STYLE_CREATE_ERROR` |
| error | string | A description of the error that occurred. |
Common Errors #
| Error | Description |
|---|
| Brand name is required | The user did not enter a brand name. |
| Model name is required | The user did not enter a model name. |
| Category is required | No category was selected. |
| Front image is required | The user did not upload a front view image. |
| Valid PPCM value is required | The calibration step was not completed. |