# Call Data Portability API methods

The Data Portability API consists of these methods:

- `portabilityArchive.initiate`
- `archiveJobs.getPortabilityArchiveState`
- `resetAuthorization`
- `archiveJobs.retryPortabilityArchive`
- `archiveJobs.cancelPortabilityArchive`
- `accessType.check`

## portabilityArchive.initiate

You call the [`portabilityArchive.initiate`](https://developers.google.com/data-portability/reference/rest/v1/portabilityArchive/initiate) method to start a new data
export job.

When you start an export job to create a data archive, you must request the
appropriate resource group and provide an OAuth token with the required
scopes for that resource group. The OAuth token is used to authorize the
request and to determine which user data is being exported.

For a list of all resource groups supported by a particular service, see the
[schema reference page](https://developers.google.com/data-portability/schema-reference) for that service.

For example, if you're exporting search activity data, you call
`InitiatePortabilityArchive(resources = ["myactivity.search"])`. The request
must have an OAuth token attached with the search OAuth scope:
`https://www.googleapis.com/auth/dataportability.myactivity.search`.

Though it is possible to include multiple resource groups in a single
`InitiatePortabilityArchive` call, this is not recommended. You can achieve
faster processing by making separate `InitiatePortabilityArchive` requests for
each resource group. Note that when you request multiple resource groups,
the attached OAuth token must have all the appropriate scopes attached.

For example, instead of calling
`InitiatePortabilityArchive(resources = ["myactivity.search","myactivity.youtube"])`
to create a data archive for both search and YouTube activity, make these
separate calls:
`InitiatePortabilityArchive(resources = ["myactivity.search"])`
and `InitiatePortabilityArchive(resources = ["myactivity.youtube"])`.

The `InitiatePortabilityArchive` request returns a `job_id`. This job ID is used
to retrieve the state of the data archive.

## archiveJobs.getPortabilityArchiveState

The [`archiveJobs.getPortabilityArchiveState`](https://developers.google.com/data-portability/reference/rest/v1/archiveJobs/getPortabilityArchiveState) method is called to retrieve
the current [state](https://developers.google.com/data-portability/reference/rest/v1/archiveJobs/getPortabilityArchiveState#State) of the data archive export job. When you call
`getPortabilityArchiveState`, you supply the `job_id`:
`GetPortabilityArchiveState(job_id)`. You must also supply an OAuth token with
scopes that match the resource groups used in the `initiate` request.

If the state is `COMPLETE`, signed Cloud Storage URLs are returned that you can
use to download the data. The signed URLs expire after six hours, and the data
is available for 14 days.

An archive request can take several minutes, several hours, or even several days
to complete depending on the volume of data. You can check the state of the
archive every five to 60 minutes.

> [!IMPORTANT]
> **Important:** You should initiate the portability archive within 24 hours of user authorization.

## resetAuthorization

The [`resetAuthorization`](https://developers.google.com/data-portability/reference/rest/v1/authorization/reset) method does the following:

- Revokes all user-granted OAuth scopes
- Allows your application to call `InitiatePortabilityArchive` for a resource group that you used previously
- Removes access to previous data archives

When you call `resetAuthorization`, you must supply an attached OAuth token for
the user whose authorization you're resetting.

> [!NOTE]
> **Note:** To automate archive cleanup, an internal `ResetAuthorization` endpoint is called 14 days after the first `InitiatePortabilityArchive` call.

## archiveJobs.retryPortabilityArchive

The [`archiveJobs.retryPortabilityArchive`](https://developers.google.com/data-portability/reference/rest/v1/archiveJobs/retry) method is called to retry
failed jobs where the [`archiveJobs.getPortabilityArchiveState`](https://developers.google.com/data-portability/reference/rest/v1/archiveJobs/getPortabilityArchiveState) method
already returned a [state](https://developers.google.com/data-portability/reference/rest/v1/archiveJobs/getPortabilityArchiveState#State) of `FAILED`. This may occur due to a transient
failure on the backend. In that case you can retry the export without obtaining
a *new* OAuth token from the user. When you call `retryPortabilityArchive` you
supply the `job_id` along with a valid OAuth token. The endpoint then tries to
create an export for the same [resource groups](https://developers.google.com/data-portability/schema-reference) requested in the initial
`initiatePortabilityArchive` request. If successful, this endpoint returns
a *new* `job_id` that you can use in calls to `getPortabilityArchiveState`. A
failed job can be retried up to three times.

For example:

1. You call `InitiatePortabilityArchive(resources = ["myactivity.search"])`,
   and you receive `job_id: 0`.

2. After calling `GetPortabilityArchiveState(0)`, you receive `JobSate: FAILED`.

3. You can then call `RetryPortabilityArchive(0)` to receive `job_id: 1` for
   `resources = ["myactivity.search"]`.

4. Then, you can continue to make calls to `GetPortabilityArchiveState(1)`.

## archiveJobs.cancelPortabilityArchive

The `archiveJobs.cancelPortabilityArchive` method is called to cancel an
individual job without revoking existing tokens when you have ongoing access
to user data. This is useful when a job or resource is no longer needed and you
want to reset your job quota. The job must be `IN_PROGRESS` and have been
created with time-based access to be canceled.

For example, you could cancel an in-progress, time-based job for
`myactivity.youtube` and `youtube.public_videos` then start a new job for just
`myactivity.youtube`.

## accessType.check

The `accessType.check` method lets you check whether an OAuth token authorizes
time-based or one-time access before starting a job. For example you might
intend to export a user's entire history if they grant one-time access, or just
the last day if they grant time-based access.

The response contains two fields: lists of one-time and time-based
dataportability resource group ids authorized by the OAuth token used in the
request. Users can't mix access types in a token grant, but you shouldn't
necessarily assume that behavior in the future.