action button

Hi everyone,

This isn’t very complicated, but I thought I share the code for an action button which takes a URL field and shortens it through’s API:

// this action button uses the API to shorten a URL

// Fibery API and HTTP services
const fibery = context.getService('fibery');
const http = context.getService('http');

for (const entity of args.currentEntities) {
    // get the URL field
    const linkURL = entity['{{YOUR-URL-FIELD-NAME}}'];
    // check to see if the field is empty
    if (linkURL) {
        // check to see if the link has already been shortened
        if ("") < 0) {
            // call bitly API to shorten the URL
            const strBitly = await http.postAsync('', {
                body: {
                    "domain": "",
                    "long_url": linkURL
                headers: {
                    'Content-type': 'application/json',
                    'Authorization': 'Bearer {{YOUR_BITLY_API_KEY_HERE}}'

            // parse the response string
            const objBitly = JSON.parse(strBitly)

            // extract the shortend URL
            const shortURL = objBitly["link"];

            // update the entity link field with the shortened URL
            await fibery.updateEntity(entity.type,, {
                '{{YOUR-URL-FIELD-NAME}}': shortURL

You will need to replace the following in the code:

{{YOUR-URL-FIELD-NAME}} : replace with field name for the URL field
{{YOUR_BITLY_API_KEY_HERE}}: replace with your API key

Hope this is helpful to someone else. If anyone has any improvements please let me know :slight_smile:

1 Like