You can create and manage data segments using the
[Curation Partners API](https://developers.google.com/authorized-buyers/curation/apis/curationpartners/reference/rest),
which exposes a
[`curators.dataSegments`](https://developers.google.com/authorized-buyers/curation/apis/curationpartners/reference/rest/v1/curators.dataSegments)
resource. This is a REST API with [generated client
libraries](https://developers.google.com/api-client-library) that you can use for
your integration.

> [!TIP]
> **Tip:** To learn how to make API calls using the generated client libraries, reference existing [Curation Partners API samples](https://github.com/googleads/curation-partners-api-samples).

## Set up authentication

Google APIs use the [OAuth 2.0
protocol](https://developers.google.com/identity/protocols/oauth2) for authentication
and authorization. Here's how to set up a [Service
Account](https://developers.google.com/identity/protocols/oauth2/service-account) to
access the Curation Partners API.

1. If you have not done so already, [create a Google Cloud
   Project](https://cloud.google.com/resource-manager/docs/creating-managing-projects)
   that hosts your credentials used to access the API.

   > [!IMPORTANT]
   > **Important:** We recommend that multiple members of your organization are granted access to this project. This process avoids interruptions to your integration from lost access to the project.

2. Go to the [Google Cloud Console Enabled APIs
   page](https://console.cloud.google.com/apis/enabled?project=_). Select the
   project you created earlier.

3. Review the list of enabled APIs and services. To access the Curation
   Partners API, you must enable it. If the Curation Partners API isn't
   enabled, click **+Enable APIs and services** and step through the following
   instructions:

   1. Search for **Curation Partners API** using the search box.
   2. Select **Curation Partners API** in the results page.
   3. Click **Enable**.

   It is a known issue that you might not be able to find the Curation
   Partners API with the Google Cloud Console search box. As an alternative,
   you can use [Google Cloud CLI](https://docs.cloud.google.com/sdk/docs/install-sdk)
   to enable the API instead. After you install gcloud CLI, you can enable the
   Curation Partners API with the following command:

       gcloud services enable curationpartners.googleapis.com --project=CLOUD_PROJECT_ID

4. On the navigation menu, select **Credentials**.

5. Click **+Create credentials** , and in the resulting drop-down menu select
   **Service account**.

6. Enter a **Name** for the service account. The **Service account ID** is
   created automatically upon creation -- note this value because it will be
   needed later in step 14. Optionally enter a description. Click **Create and
   continue**.

7. Optionally configure permissions for the service account and click
   **Continue**.

8. Optionally configure users or groups that can perform actions as the service
   account and click **Done**.

9. Your new service account is listed under **Service Accounts**. Find and
   click the service account ID you just created.

10. Click the **Keys** tab.

11. In the **Add key** drop-down menu, select **Create new key**.

12. Select **JSON** as the **Key type** , and click **Create**.

13. Download the key to your working directory. For more information about
    storing your key securely, see [Managing service account
    keys](https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys).
    The key is used by your application to make API calls.

14. Share the service account ID with your Technical Account Manager to link the
    service account with your account.

### API scopes

When stepping through the OAuth 2.0 flow to receive an access token used to make
an API call, you must specify the APIs that can be accessed using that token.
For the Curation Partners API, that scope is
`https://www.googleapis.com/auth/curation-partners`.

## How to identify data segments in the API versus Real-time Curation

In the Curation Partners API, data segments are identified with an API-specific
resource [name](https://developers.google.com/authorized-buyers/curation/apis/curationpartners/reference/rest/v1/curators.dataSegments#DataSegment.FIELDS.name)
such as:

    "curators/ACCOUNT_ID/dataSegments/DATA_SEGMENT_ID".

When [identifying the data segments relevant for an ad opportunity in Real-time
Curation](https://developers.google.com/authorized-buyers/curation/realtime-curation/build-response),
specify the value for the `DATA_SEGMENT_ID` resource ID rather than the full
resource name provided by the API in the `name` field.

## Next Steps

- Learn how to [create and manage data
  segments](https://developers.google.com/authorized-buyers/curation/apis/guides/curationpartners/datasegments/create-modify) with the Curation Partners API.
- Learn how to [activate and deactivate data
  segments](https://developers.google.com/authorized-buyers/curation/apis/guides/curationpartners/datasegments/activate-deactivate) with the Curation Partners API.
- Learn how to [view your data
  segments](https://developers.google.com/authorized-buyers/curation/apis/guides/curationpartners/datasegments/view) with the Curation Partners API.