# Facebook

## Create a Facebook app and set up authentication on Mindflow

1. Go to: [https://developers.facebook.com/apps/](https://developers.facebook.com/apps/)
2. Click the `Create an app` button and fill in the required fields.
3. Once the app is created, retrieve the `App ID` and the `App Secret` from `*App Settings` > `Basic`\*.

   <div class="docs-screenshot-compact">

   ![Design sans titre.png](./assets/design-sans-titre.png)

   </div>

4. Go to your app's `Dashboard` and add the `Facebook Login` product.
5. Click the `Vault` tab, then the `+ Add Credentials` button, and search for Facebook Lead Ads API.
6. Choose **`OAuth 2.0 Authorization Code`** for the `Credential type` and fill in the fields as follows:
   1. `Client_id*` = Your `App ID`
   2. `Client_secret*` = Your `App Secret`
   3. `Authorization URL*` = [_https://www.facebook.com/v12.0/dialog/oauth_](https://www.facebook.com/v12.0/dialog/oauth)
   4. `Access token URL*` = [_https://graph.facebook.com/v12.0/oauth/access_token_](https://graph.facebook.com/v12.0/oauth/access_token)
   5. `Scope(s)*`(Advanced) = The scopes relevant to the actions you want to perform
      - _e.g., (catalog_management,ads_management,business_management leads_retrieval,pages_show_list,pages_manage_metadata,pages_read_engagement,pages_read_user_content,pages_manage_ads) for the Facebook Marketing API_
7. Copy the `Callback URL`, return to Facebook, go to `Facebook Login` > `Settings`, and add the `Callback URL` in the `Valid OAuth Redirect URIs`. Click `Save changes`.
8. Return to Mindflow and click `Authorize and create`. A Facebook window will open, click the button to validate the connection.
9. Congratulations, you have configured OAuth 2.0 authentication for your Facebook app. You can now use it by selecting this credential in your steps to authenticate Facebook integrations.

:::note
Test webhook with test lead generator: [Generator](https://developers.facebook.com/tools/lead-ads-testing/)
:::

## Create the webhook

1. Go to the Dashboard of your Facebook app [https://developers.facebook.com/apps/your_app_id/dashboard/](https://developers.facebook.com/apps/your_app_id/dashboard/)
2. Add the `Webhooks` product by clicking the `Set up` button.
3. Click the `Webhook` page that appears on your sidebar.
4. Select the desired topic (e.g., `Pages`) and click the `Subscribe to this object` button.
5. Go to your playbook on Mindflow and click the `⚙️` icon.
6. Click the `Triggers` section, check the `Webhook` box, and copy the `WEBHOOK (SYNCHRONOUS)`.
7. Return to your Facebook app and fill in the required fields:
   1. `Callback URL` = The value previously copied from Mindflow.
   2. `Verify Token` = Any value (e.g., my_verify_token).
8. Click the `Verify and save` button.
9. Return to Mindflow and create a `webhook response` step.
10. Configure it by adding a new `Body` of type `Text` and insert the `hub.challenge` value received from the Facebook webhook.
11. Return to the Facebook app and click `Verify and save` again.
12. You can now subscribe to events for the topic by clicking the `Subscribe` button and test your webhook with test data using the `Test` button.
13. You can now delete the `webhook response` step from your playbook; your trigger is operational.
