## Sync Media from Brandfolder To sync media/content that resides in Brandfolder to an external system, the most effective way to do this is to make use of the Brandfolder webhooks service. At the current time, webhooks are at the Brandfolder level for actions taken on assets. Ultimately this means that, when you create a webhook in a Brandfolder you will get a webhook for any asset action taken in that Brandfolder (depending on the specific subscription). Available subscriptions: - `asset.create` → when a new asset is added to a Brandfolder - `asset.update` → certain update actions on an asset (such as name changes, moving between sections, etc) - `asset.delete` → when an asset is deleted in a Brandfolder Each type of subscription can be subscribed to individually. When you are creating your application, you can create an endpoint to receive Brandfolder webhooks. From there you can make a request to the Brandfolder API to get data about the asset beyond the `asset_key` and webhook type. As we will go into, this can be data like which section or collection the asset belongs to. ### Use Case: Syncing a specific section with an external system In this use case, we want to add an asset from only one specific section to our external system. So for this we will subscribe to `asset.create` events in the brandfolder. Upon receipt of a webhook, we parse the payload for `key` and make a call to the Brandfolder API for more data on the asset and we will add `section` to the `include` parameter. `GET https://brandfolder.com/api/v4/assets/?include=section` To validate, you will need to either store the name of the section or the id of the section you wish to sync in your system. Grab the payload provided as a response to your `GET` request and parse the `”included”` values and match against what you have stored. If your validation returns `True` we can sync the asset with your external system. To do this, you will need to fetch the attachments associated with the asset, as these are the actual files. For each asset returned you will grab the corresponding file url and send that to your external system based on their API. Our recommendation is to always use the `cdn_url` since it provides much more flexibility. Advanced users can even manipulate the `cdn_url` before sending the file along to resize or change the file type. To get the attachments: `GET https://brandfolder.com/api/v4/assets//attachments?fields=cdn_url` *If you do not have the CDN included in your plan, you can omit `?fields=cdn_url` from your request.* From here, parse the JSON response to grab the appropriate url. ### Use Case: Syncing a specific collection with an external system In this use case, we want to add an asset from only one specific section to our external system. So for this we will subscribe to `asset.create` events in the brandfolder. Upon receipt of a webhook, we parse the payload for `key` and make a call to the Brandfolder API for more data on the asset and we will add `section` to the `include` parameter. `GET https://brandfolder.com/api/v4/assets/?include=collections` To validate, you will need to either store the name of the collection or the id of the collection you wish to sync in your system. Grab the payload provided as a response to your `GET` request and parse the `”included”` key for the id or name and match against what you have stored. If your validation returns `True` we can sync the asset with your external system. To do this, you will need to fetch the attachments associated with the asset, as these are the actual files. For each asset returned you will grab the corresponding file url and send that to your external system based on their API. Our recommendation is to always use the `cdn_url` since it provides much more flexibility. Advanced users can even manipulate the `cdn_url` before sending the file along to resize or change the file type. To get the attachments: `GET https://brandfolder.com/api/v4/assets//attachments?fields=cdn_url` *If you do not have the CDN included in your plan, you can omit `?fields=cdn_url` from your request.* From here, parse the JSON response to grab the appropriate url.