Hello,
I’m hoping to create a widget that will display data about referenced records from a reference field.
I see a couple of examples of widgets here Swimlane Platform Custom Widgets that appear to lookup reference records and display data about them. For example, the Reference Records Table.
Looking at the code for that widget it looks like there are two ways that the widget is authenticating a request to the Swimlane API to retrieve the record data:
getReferencedApp() {
const appId = this.contextData.application.fields.find(f => f.key === referenceFieldKey).targetId;
return fetch(`${location.origin}/api/app/${appId}`, {
method: 'GET',
headers: {
**Authorization: `Bearer ${this.contextData.token}`,**
'Content-Type': 'application/json'
}
}).then(res => {
return res.json();
});
}
and
getReferences(fieldIds) {
if (this.referencedApp && !fieldIds.includes(this.referencedApp.trackingFieldId)) {
fieldIds = [...fieldIds, this.referencedApp.trackingFieldId];
}
const body = {
fieldIds: fieldIds,
recordIds: this.record[referenceFieldKey]
};
**const token = localStorage.getItem('jwt_token');**
return fetch(`${location.origin}/api/app/${this.contextData.application.id}/record/${this.record.id}/references`, {
headers: {
Authorization: `Bearer ${token}`,
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json;charset=UTF-8'
},
method: 'POST',
body: JSON.stringify(body)
}).then(res => {
return res.json();
});
}
I have tried both of these in my widget editor and neither are working. It appears that this.contextData.token
has been replaced with "<<deprecated>>"
and there isn’t a jwt
entry in local storage. It does appear that the jwt is stored in the cookies, but when trying to reference document.cookie
in the widget it is returning an empty string for me.
Does anyone know how to properly authenticate to the Swimlane REST API within a widget?
Thank you