Images in a Smartform
An image is sent as a base64 string in values, under the property name of the image field in the Smartform, like any other value. The example picks one of two images with your own logic and returns the URL of the Smartform that was created. For how values works, see Create a Smartform.
const axios = require('axios').default;
async function main(args) {
var client_id = 'ex_ezY5QjM4MDZELTdERkUtNDdGNCxxxxxxxxxxxxxx';
var client_secret = 'ezYxQkMxNTA2LUI0RTAtNDFGQy04Mxxxxxxxxxxxxxx';
var idDialogId = '64aea6aad36xxxxxxxxxxxx';
var scope = 'api.external';
var authHeader = 'Basic ' + Buffer.from(client_id + ':' + client_secret).toString('base64');
const options =
{
method: 'POST',
url: 'https://identity-v2.metaforce.net/connect/token',
headers: { 'content-type': 'application/x-www-form-urlencoded', 'Authorization': authHeader },
data: 'grant_type=client_credentials&scope=' + scope
};
var response = await axios.request(options);
axios.defaults.headers.common['Authorization'] = `Bearer ${response.data.access_token}`;
var inp_insured = 'Johan Ohlsson';
var inp_claimnumber = 'LP27394829';
const logo1 = "iVBORw0KGgoAAAANSUhEUgAAASwAAAEoCAMAAADVMjxRAAAB/lBMVEUAAAAAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjtUAjt";
const logo2 = "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
var bitmap = logo1;
const request =
{
method: 'POST',
url: 'https://api.smartforms.metaforce.net/Integrations/dialog/json',
headers: { 'content-type': 'application/json' },
data:
{
dialogDefinitionId: idDialogId,
values:
{
'Insured' : inp_insured,
'claimnumber' : inp_claimnumber,
'bmpLogo' : bitmap
}
}
};
const res = await axios(request);
var url = 'https://smartforms.metaforce.net/dialog/' + res.data.dialogDefinitionId + '/form/' + res.data.id
return { body: url }
}
module.exports.main = main;