> ## Documentation Index
> Fetch the complete documentation index at: https://docs.refold.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Setup

> Connect to your Facebook Ads app for OAuth.

To setup your Facebook Ads app in Refold for OAuth, you will need the following credentials from your [Facebook Developer App Settings](https://developers.facebook.com/apps/):

* Client ID
* Client Secret
* Scopes

### Pre-requisites

1. Facebook Developer Portal. You can create one [here](https://www.facebook.com/r.php?next=https%3A%2F%2Fdevelopers.facebook.com%2Fapps%2F\&locale=en_GB\&display=page).

### Required Settings

* **Mandatory Scopes**

1. Ads\_management
2. email
3. pages\_show\_list
4. pages\_manage\_ads
5. pages\_manage\_metadata
6. leads\_retrieval

<Info>If you haven't already created an app in Facebook, you'd need to create one.</Info>

### Creating an app in Facebook

To create a Facebook Ads app and acquire the above mentioned credentials, please follow the steps mentioned below:

1. Log in to your [Facebook Developer Portal](https://developers.facebook.com/apps/).
2. Select the `Apps` tab in the top nav bar and click on the `Create App` button.

<img height="200" src="https://mintcdn.com/cobalt-55/PicQQg0XJq1JrBVB/images/fb_ads/fb_navigation.png?fit=max&auto=format&n=PicQQg0XJq1JrBVB&q=85&s=28dbcc909dce0914faf3205f3602b4d5" alt="Navigation for App setup" data-path="images/fb_ads/fb_navigation.png" />

3. Select `Other` for **use-case** > Click `Next` > Select `Business` as **App-type** and click on `Next`.
   <Warning> App Type cannot be changed after the app has been created.</Warning>
4. Enter the **App Name** for your application and click on `Create App`.
5. Go to your [`Apps catalog`](https://app.gocobalt.io/apps) in **Refold** > Search for `Facebook Ads` > `Settings` > `Use your credentials` > `Callback Url` > Copy it.
6. Click on `Add Product` in the left menu > Click on `Set Up` under **Facebook Login for Business** > Paste the Callback Url under **Valid OAuth Redirect URIs** and click on `Save changes`.

<img height="200" src="https://mintcdn.com/cobalt-55/PicQQg0XJq1JrBVB/images/fb_ads/fb_config.png?fit=max&auto=format&n=PicQQg0XJq1JrBVB&q=85&s=72f2b31e395f7a6fa468ef5f31f0016d" alt="Setting up Facebook Ads Developer app" data-path="images/fb_ads/fb_config.png" />

7. Go to `Basic` under the **App Settings** section in the left menu and copy the **App ID**(Client ID) and **App Secret**(Client Secret).

<img height="200" src="https://mintcdn.com/cobalt-55/PicQQg0XJq1JrBVB/images/fb_ads/fb_credentials.png?fit=max&auto=format&n=PicQQg0XJq1JrBVB&q=85&s=e202ea19bdc3c1dd7991fcd2ae90d5bf" alt="Getting Credentials" data-path="images/fb_ads/fb_credentials.png" />

#### Configuring credentials in Refold

App settings page lets you configure the authentication settings for an `OAuth 2.0` based application. For your customers to provide you authorization to access their data,
they would first need to install your application. This page lets you set up your application credentials.

<img height="200" src="https://mintcdn.com/cobalt-55/PicQQg0XJq1JrBVB/images/fb_ads/fb_cobalt.png?fit=max&auto=format&n=PicQQg0XJq1JrBVB&q=85&s=c7e36dbb1fe31a02cc82b43558c03a84" alt="Setting up application client credentials" data-path="images/fb_ads/fb_cobalt.png" />

Provide the acquired Client ID and Client Secret under Settings of the app and save it.

#### Facebook Ads Single Webhook URL

If you wish to create an orchestration where a workflow is being triggered when some operation occurs in Facebook Ads, you'd need to subscribe to Facebook Ads' Webhook. Refold provides
a single webhook URL to manage such event triggers for all your customers.

**To setup Facebook Ads webhook subscription:**

1. Select **Facebook Ads** from the application list in **Refold**, and select `Settings`.
2. Copy the `Single Webhook Url`.
3. Go to OAuth app of Facebook Ads > Click on `Add Product` in the left menu > Click on `Set Up` under **Webhooks**.
4. Select **Page** object from drop-down and click `Subscribe to this object`. Paste the **Single Webhook URL** under `Callback URL` and the **Verify token** as `cobalt_verify_token`. Click on `Verify and save`.

<Note>
  Ensure that the verify token entered is `cobalt_verify_token`. No other value will be able to verify the Webhook.
</Note>

5. Subscribe to the `Leadgen` event if not already subscribed.

<img height="200" src="https://mintcdn.com/cobalt-55/rCTCKBbhiwGPdeWb/images/fb_ads/fb_webhook.png?fit=max&auto=format&n=rCTCKBbhiwGPdeWb&q=85&s=393f3166eecb6cabb77ca8f5afeacd00" alt="Setting up Facebook Ads Webhook URL" data-path="images/fb_ads/fb_webhook.png" />

**Test the Webhooks**

<Info>
  Webhooks can be only tested while the App Mode is `Live`.
</Info>

* Toggle on the **App Mode** from `Development` to `Live`. You can test the Lead Ads Webhook at the Facebook Ads testing tool [here](https://developers.facebook.com/tools/lead-ads-testing/).

#### App Review for Facebook Ads

If the app will only be used by app users who have a role on the app itself, **App Review** is not required but if the app will be used by anyone without a [**Role on the app**](https://developers.facebook.com/docs/development#roles) or a [**role in a Business**](https://www.facebook.com/business/help/442345745885606?id=180505742745347) that has claimed the app, it must first undergo App Review by Meta.

<Tip>
  Follow the detailed steps for an App Review submission given in the guide [here](https://developers.facebook.com/docs/resp-plat-initiatives/app-review/submission-guide).
</Tip>

Once approved, you can change the **Mode** of the app to `Live` by using the Toggle given in top Nav bar of the OAuth app.

#### Actions and triggers

Once the above setup is completed, you can create orchestrations of your use-cases using Facebook Ads actions and triggers. Following are the set of Facebook Ads actions and triggers
supported by Refold.

<Tabs>
  <Tab title="Actions">
    <AccordionGroup>
      <Accordion title="Ad Creative">
        1. **Create Ad Creative** - Create an Ad Creative in Facebook Ads.
        2. **Update Ad Creative** - Update an Ad Creative in Facebook Ads.
      </Accordion>

      <Accordion title="Ad">
        3. **Create Ad** - Create an lead in Facebook Ads.
        4. **Get Ad** - Get an Ad in Facebook Ads.
      </Accordion>

      <Accordion title="Ad Set">
        5. **Get all Ad Sets** - Get all Ad Sets in Facebook Ads.
        6. **Create Ad Set** - Create an Ad Set in Facebook Ads.
        7. **Get Ad Set** - Get an Ad Set in Facebook Ads.
        8. **Update Ad Set** - Update an Ad Set in Facebook Ads.
      </Accordion>

      <Accordion title="Campaigns">
        9. **Get All Campaigns** - Get all Campaigns in Facebook Ads.
        10. **Create Campaign** - Create a Campaign in Facebook Ads.
        11. **Update Campaign** - Update a Campaign in Facebook Ads.
      </Accordion>

      <Accordion title="Leadgen Forms">
        12. **Get Leadgen forms** - Get all Leadgen forms in Facebook Ads.
        13. **Create Leadgen form** - Create a Leadgen form in Facebook Ads.
      </Accordion>

      <Accordion title="Others">
        14. **HTTP Request** - Make HTTP API calls to any Facebook Ads documented REST APIs.
        15. **Get Profile** - Get a profile in Facebook Ads.
      </Accordion>
    </AccordionGroup>
  </Tab>

  <Tab title="Triggers">
    1. **Leadgen Updated** - Triggers when a leadgen form is updated on Facebook Ads.
  </Tab>
</Tabs>
