Skip to main content

Attachments API

The Attachments API provides operations for managing file attachments in CXTMS. Attachments can be associated with various entities such as orders, contacts, and equipment.

Types​

AttachmentGqlDto​

FieldTypeDescription
attachmentIdInt!Unique identifier
attachmentGuidUUIDGlobal unique identifier
attachmentTypeAttachmentType!Type of attachment (Picture, Avatar, OtherDocument, etc.)
createdDateTime!Creation timestamp
createdByString!User who created the attachment
descriptionStringOptional description
fileNameString!Original file name
fileUriString!Storage URI for the file
lastModifiedDateTime!Last modification timestamp
lastModifiedByString!User who last modified
organizationIdInt!Organization ID
parentIdStringID of the parent entity
parentTypeAttachmentParentType!Type of parent entity
previewUriStringURI for preview image (computed)
thumbnailUriStringURI for thumbnail image (computed)
presignedFileUriStringPre-signed download URL
presignedPreviewUriStringPre-signed preview URL
presignedThumbnailUriStringPre-signed thumbnail URL
isImageBooleanWhether the file is an image
isPdfBooleanWhether the file is a PDF
customValuesMapCustom field values

AttachmentType Enum​

ValueDescription
PictureImage file
AvatarProfile picture
OtherDocumentGeneral document

AttachmentParentType Enum​

ValueDescription
OrderOrder entity
ContactContact entity
EquipmentTypeEquipment type entity
CommodityCommodity entity

Queries​

getAttachment​

Retrieve a single attachment by ID.

query GetAttachment($organizationId: Int!, $attachmentId: Int!) {
getAttachment(organizationId: $organizationId, attachmentId: $attachmentId) {
attachmentId
fileName
fileUri
attachmentType
previewUri
thumbnailUri
created
createdBy
}
}

Parameters:

ParameterTypeRequiredDescription
organizationIdInt!YesOrganization ID
attachmentIdInt!YesAttachment ID

getAttachments​

Retrieve a paginated list of attachments.

query GetAttachments(
$organizationId: Int!
$filter: String
$search: String
$orderBy: String
$skip: Int
$take: Int
) {
getAttachments(
organizationId: $organizationId
filter: $filter
search: $search
orderBy: $orderBy
skip: $skip
take: $take
) {
items {
attachmentId
fileName
attachmentType
parentType
parentId
created
}
pageInfo {
hasNextPage
hasPreviousPage
}
totalCount
}
}

Parameters:

ParameterTypeRequiredDescription
organizationIdInt!YesOrganization ID
filterStringNoLucene filter query
searchStringNoFull-text search term
orderByStringNoSort expression (e.g., "created desc")
skipIntNoNumber of items to skip
takeIntNoNumber of items to return

Filter Examples:

# Filter by attachment type
filter: "attachmentType:Picture"

# Filter by parent type and ID
filter: "parentType:Order AND parentId:12345"

# Filter by file extension
filter: "fileName:*.pdf"

getAllOrderAttachments​

Retrieve all attachments related to an order, including order documents and workflow documents.

query GetAllOrderAttachments(
$organizationId: Int!
$orderId: Int!
$search: String
) {
getAllOrderAttachments(
organizationId: $organizationId
orderId: $orderId
search: $search
) {
items {
id
attachmentId
orderDocumentId
documentWorkflowId
fileName
fileUri
}
}
}

Field Resolvers​

getPresignedUri​

Generate a pre-signed URL for downloading attachments. Available on AttachmentGqlDto.

query GetAttachmentWithPresignedUrl($organizationId: Int!, $attachmentId: Int!) {
getAttachment(organizationId: $organizationId, attachmentId: $attachmentId) {
attachmentId
fileName
getPresignedUri(uriType: "file", expiresInDays: 1)
}
}

Parameters:

ParameterTypeRequiredDescription
uriTypeString!YesType of URI: "file", "preview", or "thumbnail"
expiresInDaysInt!YesNumber of days until URL expires
downloadBooleanNo, default falseuriType: "file" only. When true, the signed link is served as Content-Disposition: attachment; filename="<attachment fileName>", so the browser saves it under the attachment's real name instead of its storage name (which carries a GUID). preview and thumbnail links ignore it.

URI Types:

TypeDescription
fileOriginal file
previewLarge preview image (max 1024px width)
thumbnailSmall thumbnail (300x300 center crop)

Downloading under the real file name:

query DownloadAttachmentAsFile($organizationId: Int!, $attachmentId: Int!) {
getAttachment(organizationId: $organizationId, attachmentId: $attachmentId) {
attachmentId
fileName
getPresignedUri(uriType: "file", expiresInDays: 1, download: true)
}
}

Use this for a Download button: navigating to the returned URL (rather than opening it in a new tab) saves the file as fileName instead of the GUID-suffixed name it's stored under.

getParentOrder​

Retrieve the parent order for an attachment. Only available when parentType is Order.

query GetAttachmentWithOrder($organizationId: Int!, $attachmentId: Int!) {
getAttachment(organizationId: $organizationId, attachmentId: $attachmentId) {
attachmentId
fileName
getParentOrder {
orderId
orderNumber
orderStatus {
name
}
}
}
}

previewUri / thumbnailUri​

These fields return computed paths for preview and thumbnail images. They are automatically generated for supported file types:

  • Images: Picture, Avatar attachment types
  • PDFs: Any .pdf file

The paths follow a deterministic naming convention:

preview/{organizationId}/{parentType}/{sanitizedFileName}_{attachmentId}_large.jpeg
preview/{organizationId}/{parentType}/{sanitizedFileName}_{attachmentId}_small.jpeg
note

Preview and thumbnail images are generated asynchronously after upload. The URLs will return 404 until generation completes.

Examples​

Fetch Attachments for an Order​

query OrderAttachments($organizationId: Int!, $orderId: String!) {
getAttachments(
organizationId: $organizationId
filter: "parentType:Order AND parentId:$orderId"
orderBy: "created desc"
) {
items {
attachmentId
fileName
attachmentType
description
created
createdBy
previewUri
thumbnailUri
getPresignedUri(uriType: "thumbnail", expiresInDays: 1)
}
totalCount
}
}

Get Image Attachments with Previews​

query ImageAttachments($organizationId: Int!) {
getAttachments(
organizationId: $organizationId
filter: "attachmentType:Picture OR attachmentType:Avatar"
) {
items {
attachmentId
fileName
previewUri
thumbnailUri
getPresignedUri(uriType: "preview", expiresInDays: 7)
}
}
}

Download Original File​

query DownloadAttachment($organizationId: Int!, $attachmentId: Int!) {
getAttachment(organizationId: $organizationId, attachmentId: $attachmentId) {
attachmentId
fileName
getPresignedUri(uriType: "file", expiresInDays: 1)
}
}

The returned getPresignedUri value is a time-limited URL that can be used to download the file directly.