Block reference
Last updated: Dec-20-2022
As explained in Learn about blocks, flows are composed of a set of blocks that you connect together, creating step-by-step actions to execute. Each block performs a specific function. Blocks are grouped into different categories to make them more accessible:
Triggers
Triggers are special blocks that are used to start the flow execution. For example, use the Catch Webhook block to trigger the flow every time a webhook is sent to a specific URL or use the Scheduler block to trigger the flow on a predefined schedule.
Catch Webhook
Webhooks are a simple way for applications to send messages to one another.
This is how, for example, your Shopify store can send a message to Slack to notify you of a new order.
Use this block to trigger a flow from any application.
The block generates a unique URL. The URL is the address that the flow is listening to. Any message sent to this address will trigger your flow.
Specific information can be sent to this address, which can then be used by the flow.
In the example below, Cloudinary is connected to SendGrid. Once an asset is uploaded to Cloudinary, Cloudinary can send a message to any address. Once the flow catches this message, it sends an email to a predefined email address.
To configure your Cloudinary product environment to trigger a flow:
- Double-click the Catch Webhook block to open its settings page:
- Use the Copy button to copy the webhook URL to your clipboard.
- Navigate to the Upload Settings page in your Cloudinary Console.
- Paste the copied URL in the Notification URL field and click the Save button at the bottom of the page.
Scheduler
Use this block for recurring flows. Trigger an action every day of the month, every day of the week or every single day. This is similar to a crontab, cronjob or cron.
See crontab.guru to easily create a cron schedule expression.
DAM App
Use this block in flows that you want to trigger from your Cloudinary Media Library. This works in conjunction with the MediaFlows Media Library app.
Double click the DAM App block to configure its appearance in the Media Library app.
You can modify the title, the description, and its cover image.
To run the flow, you need to enable the MediaFlows Media Library app in your Cloudinary product environment. Contact support if you don't see the MediaFlows app listed in your App Marketplace.
Once the app is enabled, select the media you want to send to the flow and select Run MediaFlows from the kebab menu:
Choose the flow that you want to run from the list of flows in your account that have DAM App as a trigger.
Flow Logic
These blocks can be used by any flow to implement logical flow functionality.
Filter
Use this block to determine how to proceed based on a condition.
This is the only block that has two happy paths (two blue dots).
- The block connected to the upper happy path is executed if the condition is met (returns true).
- The block connected to the lower happy path is executed if the condition is not met (returns false).
For example, the filter could test if the asset is an image, and if it is, process the image, otherwise send an email:
Using Fan Out
Use this block to run the next connected block for each object in an array.
Cloudinary APIs
These blocks interact with Cloudinary APIs.
Account Usage
Use the block to get information about your account usage. This block calls the usage method of the Admin API.
For example, you could schedule a weekly email to be sent about your usage:
Rename Asset
Use this block to rename an asset in Cloudinary. This block calls the rename method of the Upload API.
Upload Media
Use this block to upload content from an FTP, HTTP, or HTTPS URL into your Cloudinary product environment.
You can include optional upload parameters in the Optional Parameters (Advanced) section using JSON format.
Once an asset is uploaded, you'll receive many fields you can use in subsequent blocks such as the ones shown in this sample response.
For example, you could upload media to Cloudinary, then send an email about its format and dimensions:
Update Asset Metadata
Use this block to update the Structured Metadata of an asset. This block calls the metadata_fields method of the Metadata API.
Process Media
Use this block to apply actions on assets in Cloudinary. For example, to convert a video to multiple formats up front, so the different formats of the video will not need to be generated on the fly when first accessed by users. This block calls the explicit method of the Upload API.
Read the documentation on the explicit method to get ideas on what you can achieve with this block. You can include optional parameters in the Optional Parameters (Advanced) section using JSON format.
For example, you could test if an asset is a video, and if it is, apply video moderation, otherwise apply image moderation:
Create Slideshow
Use this block to generate a slideshow from a set of images.
Preview Video for Emails
Use this block to generate a preview of a video in a GIF format, to use in emails.
Cloudinary add-ons
In order to use a block that’s associated with a Cloudinary add-on, you need to register for the add-on first.
Google Automatic Video Tagging
Use this block to add tags to videos based on automatically identified scenes in the video.
Use these auto-generated tags to manage, sort, and search your media.
This block uses the Google Automatic Video Tagging add-on.
Perform Image Moderation
Use this block to scan an asset and identify categories such as violence or gambling that you want to moderate in your media.
This block uses the Amazon Rekognition AI Moderation add-on.
Remove Image Background
Use this block to automatically and accurately remove the background of an image.
This block uses the Cloudinary AI Background Removal add-on.
Integrations
Akeneo - Get Token
Use this block to generate a token to be used to communicate with Akeneo’s REST API. This block requires the credentials of your Akeneo Connector.
Akeneo - Create Asset
Use this block to create an asset in Akeneo's Asset Manager.
Use Akeneo’s Product Link Rule to automatically link the created Akeneo asset to a product.
Akeneo - Delete Asset
Use this block to delete an asset in Akeneo's Asset Manager.
Image Colorization API
Use this block to automatically colorize an image or a video.
This block uses the DeepAI API.
Notifications
Send Message with Twilio
Use this block to send messages using your Twilio account.
Send Email Using SendGrid
Use this block to send emails using your SendGrid account.
Developer Tools
MediaFlows Function
Use this block to add custom logic to your flows. You can use this block to transform media, compute data, or even perform simple operations within flows that you might otherwise need to write server-side code for.
MediaFlows functions support Javascript (ES7).
Add your custom code inside the MediaFlows function.
Function parameters
Parameter | Description |
---|---|
event | Contains flow instance IDs, and all the data from blocks. |
cloudinary | A ready-to-use Cloudinary object, which contains the OAuth token. |
callback | To return the output or an error. |
The event object
The event
object contains all the data from the current flow run instance and data from all previous blocks.
This is an example of an event object structure and data:
{ "mf":{ // useful IDs of current flow run instance "previous_node_id":"mf_AR...Ke", "flow_id":"f7...bd", "project_id":"3a...aa", "request_id":"80...gf", "account_id":"ad...c9", "current_node_id":"mf_AN...tx", "callback_webhook":"https://hooks.mediaflows.cloudinary.com/prod/v1/rk...X9" }, "data":{ // data from all previous blocks "mf_oa7EiIiBCoEdWNVDJLGe":{ // block id "public_id":"black_shoe_front" // block output }, "mf_ARtNC6LYijozfwHaoYKe":{ // block id "requires_approval":true, // block output "requires_tagging":false }, "trigger_data":{ "Public_id":"black_shoe_front" // trigger output }, "current_payload":{ // input of current block "requires_approval":true, // block input "requires_tagging":false } } }
The cloudinary object
The cloudinary
object is an instance of Cloudinary’s Node SDK.
Use it to perform any API request to the Cloudinary APIs. See the Node SDK documentation.
Here is an example of a function that calls the explicit method of the Upload API:
module.exports = function (event, cloudinary, callback) { ... cloudinary.v2.uploader.explicit(asset_public_id, { type : asset_type, resource_type :asset_resource_type }) ... }
The callback object
Any data that is returned with the callback from this function can then be accessed by the next blocks in the flow.
Here is an example of a function that uses the callback function to pass the response of an API call to the next block:
module.exports = function (event, cloudinary, callback) { ... cloudinary.v2.uploader.explicit(asset_public_id, {...}) .then((result) => { callback(null,JSON.stringify(result)) }) .catch((error) => { callback(JSON.stringify(error)) }) }
Using dynamic parameters
As with any other block, MediaFlows dynamic parameters can be accessed from the {}
button in the bottom left corner of the block. See Block parameters to learn more.
Here's an example of a function that gets a parameter from the previous block:
module.exports = function (event, cloudinary, callback) { const user_id = {{event.data[event.mf.previous_node_id]}}.user_id ... }
Wrapping it all together
Here's an example of a MediaFlows function that accesses parameters from the previous block, calls the explicit method of the Upload API, and passes the result to the next block:
module.exports = function (event, cloudinary, callback) { const asset_public_id = {{event.data[event.mf.previous_node_id]}}.item_key const asset_resource_type = {{event.data[event.mf.previous_node_id]}}.resource_type const asset_type = {{event.data[event.mf.previous_node_id]}}.type cloudinary.v2.uploader.explicit(asset_public_id, { type : asset_type, resource_type :asset_resource_type }) .then((result) => { callback(null,JSON.stringify(result)) }) .catch((error) => { callback(JSON.stringify(error)) }) }
Send HTTP Request
Use this block to communicate with other services and APIs. For example, send the media output to a marketing automation system.
Log to Rollbar
Use this block to send logs to your Rollbar account.
Search and Replace
Use this block to search for a pattern in a string and replace it with a different string.
Join Strings
Use this block to join two strings with an optional separator.