File uploads

Upload files directly to storage through upload sessions, check that they passed scanning, and attach them to records with the AttachDocuments processings.
Note

File uploads are available only with a client-credentials token, used for service-to-service integrations. They are not available with a user token.

Files can be attached to records with the attachDocuments processings, by sending the file content base64 encoded in the fileBytes argument. That puts the whole file inside the GraphQL request, which is subject to the request size limit. Upload sessions avoid this: the file is uploaded directly to storage, and only a session identifier is passed to GraphQL.

Uploading a file works as follows:

  1. Request an upload session for each file with the requestFileUpload mutation. You get back a session identifier and an upload URL for each file.
  2. Upload the content of each file with an HTTP PUT request to its upload URL.
  3. Check with the fileUploadStatus query that each file has passed validation and malware scanning.
  4. Attach the files by passing their session identifiers in the uploadSessionId argument of an attachDocuments processing.

Requesting an upload session

The requestFileUpload field is available under both useCompany and useCustomer in the Mutation type. It takes a files argument with one entry per file. Each entry has the following fields:

FieldTypeDescription
fileNameString!The original file name, including the extension. This becomes the name of the file in the archive.
sizeLong!The exact size of the file in bytes. An upload of any other size is rejected.
fileTypeFileUploadTypeOptional. The type of the file, named by its extension. When given, it must match the extension of fileName. When missing, the type is taken from the extension.

At most 20 files can be requested in one call.

The following snippet shows a mutation that requests upload sessions for two files, in the context of a company.

Query
mutation request_upload($cid: Int!)
{
  useCompany(no: $cid)
  {
    requestFileUpload(files: [
      { fileName: "invoice.pdf", size: 48213 },
      { fileName: "delivery-note.png", size: 152870 }
    ])
    {
      fileName
      sessionId
      uploadUrl
      uploadUrlExpiresAt
      sessionExpiresAt
    }
  }
}
Result
{
  "data": {
    "useCompany": {
      "requestFileUpload": [
        {
          "fileName": "invoice.pdf",
          "sessionId": "5b7c2f0e-3d7a-4f4e-9a51-0c6c2a1d8e13",
          "uploadUrl": "https://...",
          "uploadUrlExpiresAt": "2026-11-23T10:15:00Z",
          "sessionExpiresAt": "2026-11-24T10:00:00Z"
        },
        {
          "fileName": "delivery-note.png",
          "sessionId": "c1e9a4d2-7b36-4b0f-8f2d-6a5e3b9c0f71",
          "uploadUrl": "https://...",
          "uploadUrlExpiresAt": "2026-11-23T10:15:00Z",
          "sessionExpiresAt": "2026-11-24T10:00:00Z"
        }
      ]
    }
  }
}

The result has one entry per requested file, in the order of the request. Each entry has the following fields:

FieldTypeDescription
fileNameString!The requested file name, so that you can match the sessions to your files without relying on their order.
sessionIdString!The identifier of the upload session. You pass it to the attachDocuments processing.
uploadUrlString!The URL where you upload the file content.
uploadUrlExpiresAtDateTime!The time when the upload URL stops working. After this, you must request a new session.
sessionExpiresAtDateTime!The time when the session expires, whether the file was uploaded or not.

The following file types are supported: BMP, CSV, DOCX, HTM, HTML, JPEG, JPG, ODS, ODT, PDF, PNG, TIF, TIFF, TXT, XLSX, XML, and ZIP. Extensions that name the same type, such as jpg and jpeg, are interchangeable.

Note

Requesting an upload session requires write access. A read-only context, such as one with a read-only token or with the AI permission set to read, can check the status of upload sessions but cannot request them.

Note

Each session counts towards the customer’s limit of pending uploads until it is used or it expires. Request sessions only for files you are going to upload.

Uploading the file

Upload the content of the file with an HTTP PUT request to the upload URL. The request must have the header x-ms-blob-type: BlockBlob. No authorization header is needed, because the URL itself grants access. The content does not pass through the Business NXT API.

curl -X PUT \
     -H "x-ms-blob-type: BlockBlob" \
     --data-binary @invoice.pdf \
     "<uploadUrl>"

Checking the upload status

After a file is uploaded, it is validated and scanned for malware. A file can be attached only after it has passed these checks. Use the fileUploadStatus field to find out. This field is available under both useCompany and useCustomer in the Query type. It takes a sessionIds argument with the identifiers of up to 20 sessions.

Query
query upload_status($cid: Int!, $ids: [String!]!)
{
  useCompany(no: $cid)
  {
    fileUploadStatus(sessionIds: $ids)
    {
      sessionId
      status
      code
    }
  }
}
Result
{
  "data": {
    "useCompany": {
      "fileUploadStatus": [
        {
          "sessionId": "5b7c2f0e-3d7a-4f4e-9a51-0c6c2a1d8e13",
          "status": "READY",
          "code": null
        },
        {
          "sessionId": "c1e9a4d2-7b36-4b0f-8f2d-6a5e3b9c0f71",
          "status": "PENDING",
          "code": null
        }
      ]
    }
  }
}

The status field has one of the following values:

NameDescription
READYThe file was scanned and accepted. The session can be passed to an attachDocuments processing.
PENDINGThe file was not uploaded yet, or it is still being scanned. Check again later.
REJECTEDThe file was refused by validation or scanning. It must be uploaded again in a new session.
UNKNOWNThe session does not exist, or it has expired. The file must be uploaded again in a new session.

The code field holds a reason code when one is available, for instance why a file was rejected.

Only sessions requested by the same client are reported. A session requested by another client is reported as UNKNOWN.

Attaching the file

Pass the session identifier in the uploadSessionId argument of the files of an attachDocuments processing, instead of fileBytes. The fileName argument is still required, because it gives the name and type of the attachment.

Query
mutation attach_documents($cid: Int!, $batchNo: Int!, $voucherNo: Int!)
{
  useCompany(no: $cid)
  {
    voucher_processings
    {
      attachDocuments(
        filter: {_and: [
          {batchNo: {_eq: $batchNo}},
          {voucherNo: {_eq: $voucherNo}}
        ]},
        args: {
          files: [
            {
              fileName: "invoice.pdf",
              uploadSessionId: "5b7c2f0e-3d7a-4f4e-9a51-0c6c2a1d8e13"
            },
            {
              fileName: "delivery-note.png",
              uploadSessionId: "c1e9a4d2-7b36-4b0f-8f2d-6a5e3b9c0f71"
            }
          ]
        })
      {
        succeeded
      }
    }
  }
}

The uploadSessionId argument is available on the attachDocuments processing of the following tables:

  • ApprovedReconciliation
  • CapitalAssetTransaction
  • CustomerTransaction
  • GeneralLedgerTransaction
  • IncomingAccountingDocument
  • OpenCustomerEntry
  • OpenSupplierEntry
  • Order
  • OrderAttachment
  • SupplierContract
  • SupplierTransaction
  • UpdatedVoucher
  • Voucher
Note

A file can be given either by uploadSessionId, by fileBytes, or by fileServicePath. Giving uploadSessionId together with one of the others is an error.

If a file is still being scanned when the processing runs, the processing waits a short while for the scan to complete. If a file is not ready by then, or it was rejected, the row fails and none of its files are attached. You can check the status with fileUploadStatus and run the processing again.

Errors

When a request is refused, the field returns null and the response has an error. The error code is in extensions.code. When the error is about one of the files or sessions, its position in the request (starting from 0) is in extensions.data.fileIndex or extensions.data.sessionIndex.

Result
{
  "errors": [
    {
      "message": "The file type is not supported.",
      "path": ["useCompany", "requestFileUpload"],
      "extensions": {
        "code": "invalidType",
        "data": {
          "fileIndex": 1
        }
      }
    }
  ],
  "data": {
    "useCompany": {
      "requestFileUpload": null
    }
  }
}

The following errors can be returned:

NameDescription
invalidRequestThe request is incomplete: no files or sessions were given, a file name or a session identifier is blank, or a file size is not greater than zero.
invalidTypeThe file type is not supported, or fileType does not match the extension of fileName.
tooManySlotsPerRequestMore than 20 files were requested in one call.
tooManySessionsPerRequestThe status of more than 20 sessions was asked for in one call.
ACCESS_DENIEDThe caller does not have access to the customer of the company or customer context.
customerUnresolvedThe customer could not be determined from the context.
serverErrorThe request could not be completed. Try again later.

Other codes may be returned when the file storage service refuses the request, for instance when the customer has too many pending uploads. These codes are passed on as they are.

Note

The requestFileUpload cannot be used inside an asyncQuery. It returns upload sessions that are meant to be used right away: you upload the file to the returned URL before the URL expires. An async request only gives you an operation ID and delivers its result later, by which time the upload URLs may have expired. To prevent this, a requestFileUpload inside an asyncQuery fails with an invalidRequest error and no sessions are opened. Call requestFileUpload in a regular, synchronous mutation, upload the file, and then use the session ID in your async request if neede

Last modified November 25, 2026