Skip to main content

Examples

Query examples
Link copied!

Getting an Asset by the ID
Link copied!

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

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

This query gives us the following response:

{
"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
Link copied!

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

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

Getting Asset Folders
Link copied!

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

{
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
Link copied!

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.

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

Getting the Media Hub ID
Link copied!

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

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

Getting the Organization id
Link copied!

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

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

Creating, updating and deleting assets
Link copied!

deleteAssets
Link copied!

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

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

updateAssets
Link copied!

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

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

updateAssetMetadata
Link copied!

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

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

createAsset - video
Link copied!

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 for details of how to add transcoding profiles to a video.

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
Link copied!

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

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
Link copied!

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.

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
}
}

Personal access token examples
Link copied!

Personal access tokens (PATs) can be used to authorize access to the account management features of the GraphQL Asset Management API and the Dynamic Content Management API. Access tokens are associated with users within an organization.

Creating an access token
Link copied!

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

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

Listing your access tokens
Link copied!

This query will list all tokens assigned to the user.

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

Deleting an access token
Link copied!

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

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

Video transcoding
Link copied!

Listing transcoding profiles
Link copied!

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.

{
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
Link copied!

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.

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

Reprocessing transcoding profiles
Link copied!

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

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

Removing transcoding profile
Link copied!

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

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