Step 1: Create dynamic dataslots on dashboard

You can go to the configure portal to create a dynamic dataslots field type. See the example below

Here you can a sample object format being created:

{
    map_fields_object: {
        dynamic: {
        // replace 'dynamic' with your object name set on the dashboard
            fields: [{
                name: string;
                value: string;
            }];
        };
    };
};

Step 2: Pass the labels in .config() function

For end customers, you can ask them to map your SaaS fields with the dynamic fields of the app as shown below:

Pass label in configuration

While calling the .config() function you need to pass the labels object in the third parameter as shown below. You can add any number of label fields in the object in the given format.

cobalt.config('mailerlite','configid',{
    map_fields_object: {
        dynamic: {
            fields: [{
                name: "My Name";
                value: "my_name";
            },
            {
                name: "Family Name";
                value: "family_name";
            }];
        };
    };
};);

Step 3: Map the labels and dynamic options using .updateConfig()

Once you have passed the labels in .config() you will get a response with labels and options added in the config, as shown below:

{
    "application_data_slots": [
        {
            "required": true,
            "id": "645df2f8e77af6ed8d02f32f",
            "name": "Map Mailerlite Fields",
            "has_dynamic_map_fields": false,
            "field_type": "map",
            "options": [
                {
                    "name": "Direct Access Link",
                    "value": "direct_access_link"
                },
                {
                    "name": "Last Name",
                    "value": "last_name"
                },
                {
                    "name": "First Name",
                    "value": "first_name"
                }
            ],
            "dynamic_slot_identifier": "dynamic:mailerlite:1",
            "labels": [
                {
                    name: "My Name";
                    value: "my_name";
                },
                {
                    name: "Family Name";
                    value: "family_name";
                }
            ]
        }
    ],
    "workflows": [],
    "config_id": "1234"
}

Once the user has mapped the labels and objects, you need to call the .updateConfig() function to

cobalt.updateConfig('mailerlite','1234', {
    "config_id": "1234",
    "application_data_slots": {
        "645df2f8e77af6ed8d02f32f": {
            "my_name": "first_name",
            "family_name": "last_name"
            /*[response.application_data_slots[0].id] : {
            [response.application_data_slots[0].labels[0].value]: response.application_data_slots[0].options[2].value
            [response.application_data_slots[0].labels[1].value]: response.application_data_slots[0].options[1].value
            */
        }
    },
    "workflows": []
});

Step 4: Send the dynamic fields from an event

Now that you have mapped your labels with the dynamic object of an application, you can pass the value of your fields via an event. The custom fields must be passed inside an object. See example below:

{
  "event": "send data to mailerlite",
  "payload": {
    "email": "john@loremipsum.com",
    //you can rename the "custom_fields" object
    "custom_fields": {
      "my_name": "John",
      "family_name": "doe"
    }
  }
}

Step 5: Map the event object with config dataslot

Awesome, you are almost at the end. Now the last thing is to map the event object with the dynamic dataslot created in the workflow. Look at the example below: