Asset Library
Working with Assets
Swat.io offers the Library in each workspace, to better collaborate around assets. Check out the details here.
Fetch single asset
query asset {
asset(id: <asset ID>) {
id
filename
category
description
source_uploaded
source_uploaded_preview
source_uploaded_size
source_uploaded_width
source_uploaded_height
workspace {
id
name
}
workspaceLabels {
id
label
}
}
}
List
Fetch all assets in workspace library. The assetList query accepts several optional arguments in addition to the required workspace_id:
category- a list ofAssetCategoryEnumvalues (photo,video,document). Pass[photo]to get photos only.search_term- full-text search in the asset's filename.workspace_label_ids- list of label IDs to filter by.sort- sort field (defaults toupdated_at).order- sort direction (defaults todesc).after- pagination cursor.
query assets {
assetList(workspace_id: <WORKSPACE_ID>) {
assets {
id
filename
description
category
source_uploaded
source_uploaded_preview
source_uploaded_size
source_uploaded_width
source_uploaded_height
workspace {
id
name
}
workspaceLabels {
id
label
}
}
pagination {
after
}
}
}
Filtering assets
All optional filters can be combined. category accepts a list of photo, video, or document.
query assetsFiltered {
assetList(
workspace_id: <WORKSPACE_ID>
category: [photo]
search_term: "product launch"
workspace_label_ids: [<LABEL_ID_1>, <LABEL_ID_2>]
) {
assets {
id
filename
category
workspaceLabels {
id
label
}
}
pagination {
after
}
}
}
Paginating through assets
Use the pagination.after token from the previous response to fetch the next page. Pass the same filter arguments each time.
query assetsNextPage {
assetList(
workspace_id: <WORKSPACE_ID>
after: "<AFTER_TOKEN>"
) {
assets {
id
filename
}
pagination {
after
}
}
}
When pagination.after is null, you have reached the last page.
Create
mutation {
assetCreate(
description: "My asset description",
original_filename: "example.jpg",
source_uploaded: "https://assets-swatio-app.s3.eu-central-1.amazonaws.com/uploads/123.jpg",
source_alternate_uploaded: "https://assets-swatio-app.s3.eu-central-1.amazonaws.com/uploads/123-a.jpg",
workspace_id: <WORKSPACE_ID>,
workspace_label_ids: [1, 2, 3]
) {
id
}
}
File Upload Requirements
The source_uploaded and source_alternate_uploaded fields in assetCreate and assetUpdate mutations must reference files already uploaded to our S3 assets bucket. Users cannot use arbitrary external URLs. To register an upload use assetRegisterS3Upload mutation.
mutation {
assetRegisterS3Upload(
content_type: "image/jpeg",
size: 123456,
workspace_id: <WORKSPACE_ID>
) {
curl_command
parameters {
key
acl
policy
x_amz_algorithm
x_amz_credential
x_amz_date
x_amz_signature
content_type
content_disposition
cache_control
}
url_upload
url_final
}
}
This returns the following fields:
curl_command: Example command for uploading the file to S3.parameters: Required form fields for the upload (replace underscores_with dashes-).url_upload: The S3 endpoint to which the file should be uploaded.url_final: The URL that must be used forsource_uploadedorsource_alternate_uploadedinassetCreateorassetUpdate.
Workflow Summary
- Call
assetRegisterS3Uploadto get the credentials. - Upload the file to S3 using the returned parameters and
url_upload. - Use
url_finalas the value forsource_uploadedorsource_alternate_uploadedwhen creating/updating the asset.
See also Uploading assets for attachments to our S3 bucket.
Update
mutation {
assetUpdate(
id: <ASSET_ID>,
description: "Updated asset description",
custom_filename: "new_example.jpg",
original_filename: "example.jpg",
source_uploaded: "https://assets-swatio-app.s3.eu-central-1.amazonaws.com/uploads/123.jpg",
source_alternate_uploaded: "https://assets-swatio-app.s3.eu-central-1.amazonaws.com/uploads/123-a.jpg"
) {
id
}
}
Delete
mutation {
assetDelete(id: <ASSET_ID>)
}
Add label to an asset
mutation {
assetWorkspaceLabelAdd(
asset_id: <ASSET_ID>,
workspace_label_id: <LABEL_ID>
) {
id
}
}
Remove label from an asset
mutation {
assetWorkspaceLabelRemove(
asset_id: <ASSET_ID>,
workspace_label_id: <LABEL_ID>
) {
id
}
}
List labels
query {
workspaceLabels(workspace_id: <WORKSPACE_ID>) {
id
label
}
}
Create label
Each workspace label must have a unique name within its workspace.
mutation {
workspaceLabelCreate(
label: "New Label"
workspace_id: <WORKSPACE_ID>
) {
id
label
}
}
Delete label
Deleting a workspace label will remove it from all associated assets.
mutation {
workspaceLabelDelete(id: <LABEL_ID>)
}
Update label
mutation {
workspaceLabelUpdate(id: 123, label: "New Label Name") {
id
label
}
}
