Migrating from the Drive API

This document outlines how to migrate code using the Drive API for permission management to the Looker Studio API. For common Drive API endpoints, it shows the corresponding Looker Studio API code.

Files

For the Drive API files endpoints, the Looker Studio API only has an equivalent endpoint for the Files: list endpoint.

List

API Method Endpoint
Drive POST /drive/v3/files
Looker Studio GET /v1/assets:search

Comparison:

Drive

const oAuthToken = '123' // This should be replaced with a valid OAuth token.
fetch(`https://www.googleapis.com/drive/v3/files`, {
  headers: {
    Authorization: `Bearer ${oAuthToken}`
  },
  method: "POST",
})

Looker Studio

const oAuthToken = '123' // This should be replaced with a valid OAuth token.
fetch(`https://datastudio.googleapis.com/v1/assets:search?assetTypes={ASSET_TYPE}`, {
  headers: {
    Authorization: `Bearer ${oAuthToken}`
  }
})

See search assets.

Permissions

Create, Delete, And Get

API Method Endpoint
Drive POST /drive/v3/files/fileId/permissions
Drive DELETE /drive/v3/files/fileId/permissions/permissionId
Drive GET /drive/v3/files/fileId/permissions/permissionId

There are no corresponding endpoints in the Looker Studio API for managing multiple Permissions objects. There is only one permissions object for a Looker Studio asset, and it always exists.

List

There isn't a 1-to-1 match between Drive and Looker Studio, but the endpoints serve similar goals. The main difference is that a Drive file can have many permissions objects, and Looker Studio has exactly one.

API Method Endpoint
Drive GET /drive/v3/files/fileId/permissions
Looker Studio GET /v1/assets/assetId/permissions

Comparison:

Drive

This following code lists all the permissions objects for the Drive API. Depending on your code, you may call this method multiple times using pagination tokens (as shown) to ensure you can see all of the permissions that are set for a file.

const fileId = '123'; // This should be replaced with a valid Drive ID.
const oAuthToken = '123'; // This should be replaced with a valid OAuth token.
let nextPageToken = undefined;
let permissions = [];
do {
  const permissionsData = await fetch(`https://www.googleapis.com/drive/v3/files/${fileId}/permissions`, {
    headers: {
      Authorization: `Bearer ${oAuthToken}`
    }
  });
  nextPageToken = permissionsData.nextPageToken;
  permissions = permissions.concat(permissionsData.permissions)
} while (nextPageToken !== undefined);

Looker Studio

Since there is only one permission object for a Looker Studio asset, you don't have to account for pagination.

const oAuthToken = '123' // This should be replaced with a valid OAuth token.
const assetId = '123' // This should be replaced with a valid asset ID.
fetch(`https://datastudio.googleapis.com/v1/assets/{ASSET_ID}/permissions`, {
  headers: {
    Authorization: `Bearer ${oAuthToken}`
  }
}

See get permissions.

Update

For updating permissions, the Looker Studio and Drive APIs have very similar functionality. The main difference is you cannot set an expirationTime on a Looker Studio permission.

API Method Endpoint
Drive PATCH /drive/v3/files/fileId/permissions/permissionId
Looker Studio PATCH /v1/assets/assetId/permissions

Comparison:

Drive

const fileId = '123'; // This should be replaced with a valid Drive ID.
const oAuthToken = '123'; // This should be replaced with a valid OAuth token.
const newPermissionsObject = {
  expirationTime: '...',
  role: 'owner', // Or any other option
}
fetch(`https://www.googleapis.com/drive/v3/files/${fileId}/permissions/permissionId`, {
  headers: {
    Authorization: `Bearer ${oAuthToken}`
  },
  method: "PATCH",
  body: JSON.stringify(newPermissionsObject)
})

Looker Studio

const oAuthToken = '123' // This should be replaced with a valid OAuth token.
const assetId = '123' // This should be replaced with a valid asset ID.
const newPermissionsObject = {
  permissions: {
    //...
  }
}

fetch(`https://datastudio.googleapis.com/v1/assets/${assetId}/permissions`, {
  headers: {
    Authorization: `Bearer ${oAuthToken}`
  },
  method: "PATCH",
  body: JSON.stringify({
    name: assetId,
    permissions: newPermissionsObject
  })
})

For use-case specific alternatives, see: