Available since version 11.0 (Paper Plane)
The Unity Messaging API allows the external application front-end to interact with Pricefx Unity front-end. Via the API you can ask Unity to create a new quote, update or fetch quote inputs, etc.
To enable the Messaging API, set up the Feature Flag feIntegration.active
to value true
. In case you are using this Feature Flag for the first time, please add the following to your CRM config file:
{ ...other feature flags, "feIntegration": { "active": true } }
You can find more details about Feature flags here: /wiki/spaces/UDEV/pages/2235236632.
To call Unity, use the window.postMessage() method from JavaScript in the browser.
Example, when Unity is embedded inside of external application:
const iframe = document.getElementById('pfx-iframe'); const messageHandler = (event) => console.log(event.data); window.addEventListener(messageHandler); iframe.contentWindow.postMessage({ "source": "pfxParentMessage", "type": "getUserData" }, *);
In this case, you will attach a handler that logs the message it receives from Unity, and also will message Unity requesting the logged in user data.
Example, when external application is embedded in Unity:
const messageHandler = (event) => console.log(event.data); window.addEventListener(messageHandler); window.parent.postMessage({ "source": "pfxParentMessage", "type": "getUserData" }, *);
The messages must have 2 fields: source and type. For most messages, there will be also a payload field which will contain additional data for the sent message.
Source refers to the origin of the message, which can be either pfxParentMessage
or pfxChildMessage
.
Type is which kind of message is being sent, and can be any of the following described in the tables below.
Some kinds of messages will also return data, which will be also sent through postMessage.
Please note that the messages described in the table below (except for getUserData
and addClicLineItems
) have the same signature as in Interceptor CLIC API.
The following messages are available for both cases (where Unity is either the parent or a child page):
Message type | Payload | Description | Example | Response |
---|---|---|---|---|
| none | Returns the logged user data. | { "source": "pfxParentMessage", "type": "getUserData" } | { "source": "pricefx", "type": "GET_USER_DATA", "payload": { "locale": "en-gb", "email": "your@email.com", "loginName": "login.name", "roleNames": [...] } } |
|
| Gets some header field’s value from the CLIC i.e. quote displayed. This is only enabled when a detail page is open. | { "source": "pfxChildMessage", "type": "getClicHeaderValue", "payload": { "fieldName": "externalRef" } } | { "source": "pricefx", "type": "HEADER_VALUE", "payload": { "fieldName": "externalRef", "fieldValue": "externalReference" } } |
|
| Updates some header field’s value. This is only enabled when a detail page is open. | { "source": "pfxParentMessage", "type": "updateClicHeaderValue", "payload": { "fieldName": "externalRef", "fieldValue": "new externalRef" } } | none |
| none | Recalculates the CLIC displayed. This is only enabled when a detail page is open. | { "source": "pfxChildMessage", "type": "recalculate" } | none |
|
| Returns the line items matching the given queryData criteria. This is only enabled when a detail page is open. | { "source": "pfxParentMessage", "type": "getClicLineItems", "payload": { "queryData": "AK_0001" } } | { "source": "pricefx", "type": "LINE_ITEMS", "payload": { "queryData": "AK_0001", "lineItems": [] } } |
|
| Add a list of SKUs to the current CLIC displayed, with the option of filling some of its inputs. This is only enabled when a detail page is open. | { "source": "pfxParentMessage", "type": "addClicLineItems", "payload": { "lineItems": [ { sku: "AK_0001', inputs: { Quantity: 3 } } ] } } | none |
There are also messages which are exclusive to the case where Unity is embedded inside external application, since they manipulate window location:
Message type | Payload | Description | Example | Response |
---|---|---|---|---|
|
| Creates a new quote/RBA/contract/compensation plan. Values of this new CLIC can be passed through targetPageState, which reuses context linking and has the exact same API. | { "source": "pfxParentMessage", "type": "newQuote", "payload": { "targetPageState": { "targetPageFields": { "externalRef": "created by message" } } } } | none |
|
| Navigates Unity to the given target page. | { "source": "pfxParentMessage", "type": "navigate", "payload": { "targetPage": "priceShopPage", "id": "123" } } | none |
There are also events in Unity that will trigger a message. When submitting or recalculating a CLIC, a message will be sent containing all CLIC data, like below:
{ "source": "pricefx", "type": "QUOTE_RECALCULATED", "payload": { "version": 7, "typedId": "2147493723.Q", "uniqueName": "P-2147493723", "label": "New Quote", "targetDate": "2023-05-29", "workflowStatus": "DRAFT", ... } }