---
canonical: https://amplience.com/developers/docs/apis/asset-management/overview/examples/
title: Examples
description: Query and mutation examples for the Amplience GraphQL Management API, including getting assets by ID, listing repositories and folders, and more.
audience: Developer
date_published: 2023-09-19
date_modified: 2025-10-02
---
# Examples

## Query examples

### Getting an Asset by the ID

In the query below, we are querying for the `createdDate` and `label` of three specific assets using each of their ids.

```graphql
{
  assets(
    id: [
      "QXNzZXQ6MWMzYTUzNDUtM2I1Yi00ZjdmLThjNWItOTY0ZDBlYWE4ZDI1"
      "QXNzZXQ6OWU2YjM4ZjUtN2FjZC00MjJhLWIwZWEtMjE4MWRiNzU3MmI0"
      "QXNzZXQ6MzcxMWYyNGEtNzE5MS00ZjM2LWJmZjUtNTM4YzFkMjY5MDli"
    ]
  ) {
    edges {
      node {
        label
        createdDate
      }
    }
  }
}
```

This query gives us the following response:

```graphql
{
  "data": {
    "assets": {
      "edges": [
        {
          "node": {
            "label": "woman-in-blue-dress-on-beach.jpg",
            "createdDate": "2022-07-14T08:52:48.143Z"
          }
        },
        {
          "node": {
            "label": "woman-in-chair.jpg",
            "createdDate": "2021-10-06T11:17:25.208Z"
          }
        },
        {
          "node": {
            "label": "woman-in-winter-coat.jpg",
            "createdDate": "2022-07-14T08:52:48.143Z"
          }
        }
      ]
    }
  }
}
```

### Getting Asset Repositories

If you would like to access the asset repositories for the current user or API client, you would use the following query:

```graphql
{
  viewer {
    mediaHubs {
      edges {
        node {
          assetRepositories(first: 10) {
            pageInfo {
              hasNextPage
              endCursor
            }
            edges {
              node {
                id
                label
              }
            }
          }
        }
      }
    }
  }
}
```

### Getting Asset Folders

To get the asset repositories and asset folders for the current user or api client, you would use the following query:

```graphql
{
  viewer {
    mediaHubs {
      edges {
        node {
          assetRepositories(first: 10) {
            pageInfo {
              hasNextPage
              endCursor
            }
            edges {
              node {
                id
                label
                assetFolders(first: 20) {
                  pageInfo {
                    hasNextPage
                    endCursor
                  }
                  edges {
                    node {
                      id
                      label
                      children {
                        id
                        label
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
```

### Creating folders

Use the `createAssetFolder` mutation to create a folder. Specify the `assetRepositoryId`, `label`, and include `parentId` if you want to create the new folder within an existing folder. If `parentId` is not specified then the folder is created at the top level of the asset repository.

```graphql
mutation {
  createAssetFolder(
    input: {
      assetRepositoryId: "QXNzZXRSZXBvc2l0b3J5OmU3Mjc0ZTI0LWQ0MzEtNGY2Yi05YzFiLTQwMDZmYjUwOWIxOQ=="
      label: "My new folder"
      parentId: "QXNzZXRGb2xkZXI6OTdhZGRiZTktZWRmNi00ZWYyLTlmZTQtMzg1ZWNiYzUyZjU1"
    }
  ) {
    id
  }
}
```

### Getting the Media Hub ID

If you would like to obtain the `mediaHubId` that is needed for the `createTransformationTemplate mutation` you would use the following query:

```graphql
query {
  viewer {
    mediaHubs {
      edges {
        node {
          id
          __typename
        }
      }
    }
  }
}
```

### Getting the Organization id

To get the organization id that is needed for the `removeBackgroundFromImage ` mutation you can use the following query:

```graphql
query {
  viewer {
    organizations {
      edges {
        node {
          id
          name
        }
      }
    }
  }
}
```

## Creating, updating and deleting assets

### deleteAssets

The following mutation query example details how you would delete assets by ID:

```graphql
mutation {
  deleteAssets(
    input: {
      id: [
        "QXNzZXQ6NzA4MmFlMTItNzY3Ny00MDhjLTk1YzMtMmEwYzFlZGZhMzk1"
        "QXNzZXQ6ZmZmZjIwZTktOTljMC00NTM1LWEzZDItNjE1ZDBmZTU0YjVi"
        "QXNzZXQ6ZmZmZjIwZTktOTljMC00NTM1LWEzZDItNjE1ZDBmZTU0YjVi"
        "QXNzZXQ6ZmZmZjIwZTktOTljMC00NTM1LWEzZDItNjE1ZDBmZTU0YjVi"
      ]
    }
  )
}
```

### updateAssets

The following mutation query example details how you would update assets by specific id:

```graphql
mutation {
  updateAsset(
    input: {
      id: "QXNzZXQ6NjIxN2FjNGQtMzcxMi00YzI4LThlMDctOTFlYmM3ZmY5NDIw"
      assetFolderId: "QXNzZXRGb2xkZXI6OGI4N2Y2ODgtY2MwNy00NmM3LWE3OTItZGNjYThmNmRiMGE2"
    }
  ) {
    id
  }
}
```

### updateAssetMetadata

The following mutation query example details how you would update the metadata of your assets by a specific id.

```graphql
mutation {
  updateAssetMetadata(
    input: {
      id: "QXNzZXQ6Y2NmOTMxYjMtZmQ2NS00OWExLThlMTEtYjYzOTEyZDgzY2Nj"
      metadataSchemaName: "exif"
      metadata: { description: "my description", artist: "Olly" }
    }
  ) {
    id
  }
}
```

### createAsset - video

The following mutation query example details how you would create video assets. The src URL can be any valid video URL.

You can create the asset within a folder by specifying `assetFolderId`. If no folder is specified then the asset will be created at the top level of the repository.

See the [video transcoding examples](#video-transcoding) for details of how to add transcoding profiles to a video.

```graphql
mutation {
  createAsset(
    input: {
      name: "sunflower-video"
      type: VIDEO
      filename: "sunflower-video.mp4"
      src: "https://amp-product.s3.eu-west-1.amazonaws.com/examples/sunflower-video.mp4"
      assetRepositoryId: "QXNzZXRSZXBvc2l0b3J5OmU3Mjc0ZTI0LWQ0MzEtNGY2Yi05YzFiLTQwMDZmYjUwOWIxOQ=="
    }
  ) {
    id
  }
}
```

> **Note:** When using the createAsset mutation, if an asset with the specified name already exists in your account, then a new asset with a unique filename will be created (a number will be appended to the filename).

### createAsset - image

The following mutation query example details how you would create an image asset. The src URL can be any valid image URL.

```graphql
mutation {
  createAsset(
    input: {
      name: "sunflower"
      type: IMAGE
      filename: "sunflower.jpg"
      src: "https://amp-product.s3.eu-west-1.amazonaws.com/examples/sunflower.jpg"
      assetRepositoryId: "QXNzZXRSZXBvc2l0b3J5OmU3Mjc0ZTI0LWQ0MzEtNGY2Yi05YzFiLTQwMDZmYjUwOWIxOQ=="
    }
  ) {
    id
  }
}
```

### createOrUpdateAssetByName

The `createOrUpdateAssetByName` works in the same way as the `createAsset` mutation, except that if an asset with the specified name already exists, then it will be updated.

```graphql
mutation {
  createOrUpdateAssetByName(
    input: {
      assetRepositoryId: "QXNzZXRSZXBvc2l0b3J5OmU3Mjc0ZTI0LWQ0MzEtNGY2Yi05YzFiLTQwMDZmYjUwOWIxOQ=="
      assetFolderId: "QXNzZXRGb2xkZXI6OTdhZGRiZTktZWRmNi00ZWYyLTlmZTQtMzg1ZWNiYzUyZjU1"
      name: "field-of-sunflowers"
      label: "field-of-sunflowers.jpg"
      type: IMAGE
      src: "https://amp-product.s3.eu-west-1.amazonaws.com/examples/field-of-sunflowers.jpg"
      filename: "field-of-sunflowers.jpg"
    }
  ) {
    id
  }
}
```

### Creating a media set

To create a media set, use the `createOrUpdateAssetByName` or `createAsset` mutation. Set the `type` to `SET` and include the Id of each asset in the `contents` array.

The following example shows how to create a set named "test-media-set" with 3 images.

```graphql
mutation createOrUpdateSet {
  createOrUpdateAssetByName(
    input: {
      type: SET
      name: "test-media-set"
      filename: "test-media-set"
      assetRepositoryId: "QXNzZXRSZXBvc2l0b3J5OmU3Mjc0ZTI0LWQ0MzEtNGY2Yi05YzFiLTQwMDZmYjUwOWIxOQ=="
      label: "test-media-set"
      tags: ["example", "media-set"]
      thumbFile: "da607dd1-83dd-4995-989c-2180d787ed47"
      contents: [
        "QXNzZXQ6ZmVmY2M5OWMtNDFkZC00OTRlLWE2MzItNjc3YjdmMWUxMWI0"
        "QXNzZXQ6YmNiY2NkNTAtZjdhMi00ZWMwLWFkNWEtYTY3ZGI3MzZmNzU2"
        "QXNzZXQ6YjRhMjExNDgtNTdmYS00NzNmLTgyMzgtMTdkYTFmNmU5MzMy"
      ]
    }
  ) {
    id
  }
}
```

To include a thumbnail image for the set, you'll need to specify an asset `thumbFile`. The query shown below will return the `thumbFile` for the specified assets. We've included

```graphql
query assets {
  assets(
    id: [
      "QXNzZXQ6ZmVmY2M5OWMtNDFkZC00OTRlLWE2MzItNjc3YjdmMWUxMWI0"
      "QXNzZXQ6YmNiY2NkNTAtZjdhMi00ZWMwLWFkNWEtYTY3ZGI3MzZmNzU2"
    ]
  ) {
    edges {
      node {
        name
        thumbFile
      }
    }
  }
}
```

## Publishing an asset

The `publishAsset` mutation will publish an asset given its id. You can optionally specify an array of jobIds, for operations such as video transcoding jobs, that must complete before the asset is published.

```graphql
mutation {
  publishAsset(
    input: {
      id: "QXNzZXQ6MWMzYTUzNDUtM2I1Yi00ZjdmLThjNWItOTY0ZDBlYWE4ZDI1"
      jobId: ["transcode.1234", "transcode.5678"]
    }
  ) {
    publishJobId
  }
}
```

## Personal access token examples

[Personal access tokens](https://amplience.com/developers/docs/apis/authorization/personal-access-tokens) (PATs) can be used to authorize access to the GraphQL Management API and the Dynamic Content Management API. Access tokens are associated with users within an organization.

### Creating an access token

To create a PAT use the `createPersonalAccessToken` mutation and send the organizationId and a name as input.

```graphql
mutation {
  createPersonalAccessToken(
    input: {
      name: "My personal access token"
      organizationId: "T4JnYW5penF0aW9uOm9yZ18QVUI0OU51NDF4eU4zanZQ"
    }
  ) {
    id
    name
    token
    createdDate
    lastUsedDate
  }
}
```

### Listing your access tokens

This query will list all tokens assigned to the user.

```graphql
query {
  viewer {
    personalAccessTokens {
      id
      name
      token
      createdDate
      lastUsedDate
    }
  }
}
```

### Deleting an access token

Use the`deletePersonalAccessToken ` mutation to delete a token. The token will be revoked and can no longer be used for authentication.

```graphql
mutation {
  deletePersonalAccessToken(
    input: {
      id: "UGVyc29uYWxBY2Nlc3NUb2tlbjoyZjM4YTFhOS1jNzZkLTRmMzQtOTFmYS02NTJkMDliNmVlZGUvZWI4ZGJmMTgtMGY0Yi00OWFmLWI0YWUtZjZjOGUzZTNkNWNk"
    }
  )
}
```

## Video transcoding

### Listing transcoding profiles

You can use the following query to list all the available video transcoding profiles. This example includes all the supported fields in the response, although in most cases you will just need the id to add, reprocess and remove a profile from a video asset.

```graphql
{
  viewer {
    videoTranscodingProfiles {
      edges {
        node {
          id
          name
          container
          videoBitRate
          videoSizeWidth
          audioNumberOfChannels
          audioCopy
          captionsEnabled
          description
          videoAspectMode
          audioEnabled
          videoEnabled
          videoSizeHeight
          qualityLabel
          default
          audioBitRate
          videoCodec
          videoInterlace
          videoOnePass
          videoSpeed
          label
          audioCodec
          videoKeyFrameInterval
          captionsLanguage
          videoCopy
          status
          videoFramerate
          audioNormalise
        }
      }
    }
  }
}
```

### Adding transcoding profiles to an asset

The following mutation shows how to add one or more video transcoding profiles to a video asset. You need to specify the asset id and one or more profile ids. The profile will start processing when it is added to the asset.

```graphql
mutation {
  addVideoTranscodingProfiles(
    input: {
      id: "QXNzZXQ6MzM1OTFiNDUtN2E4Ni00OGUxLWIzNDYtOWMyODE4ZmZlNDBi"
      profileIds: [
        "VmlkZW9UcmFuc2NvZGluZ1Byb2ZpbGU6NTYzZWYyM2QtMDljOC00NzVkLWI2MzMtNmJmY2UxZDhlMzVi"
      ]
    }
  ) {
    transcodingJobId
  }
}
```

### Reprocessing transcoding profiles

You can reprocess an existing transcoding profile that has been added to a video asset by using the `reprocessVideoTranscodingProfiles` mutation.

```graphql
mutation {
  reprocessVideoTranscodingProfiles(
    input: {
      id: "QXNzZXQ6MzM1OTFiNDUtN2E4Ni00OGUxLWIzNDYtOWMyODE4ZmZlNDBi"
      profileIds: [
        "VmlkZW9UcmFuc2NvZGluZ1Byb2ZpbGU6NTYzZWYyM2QtMDljOC00NzVkLWI2MzMtNmJmY2UxZDhlMzVi"
      ]
    }
  ) {
    transcodingJobId
  }
}
```

### Removing transcoding profile

To remove a transcoding profile from a video asset use the `removeVideoTranscodingProfiles` mutation. Note that there are no fields returned in the response.

```graphql
mutation {
  removeVideoTranscodingProfiles(
    input: {
      id: "QXNzZXQ6MzM1OTFiNDUtN2E4Ni00OGUxLWIzNDYtOWMyODE4ZmZlNDBi"
      profileIds: [
        "VmlkZW9UcmFuc2NvZGluZ1Byb2ZpbGU6NTYzZWYyM2QtMDljOC00NzVkLWI2MzMtNmJmY2UxZDhlMzVi"
      ]
    }
  )
}
```
