Working with the Amazon Connect Participant Service API - Amazon Connect Participant Service

Working with the Amazon Connect Participant Service API

This topic explains how to perform common tasks with the Amazon Connect Participant Service (ACPS) API.

Uploading attachments

There are three basic steps for uploading a file using the Amazon Connect Participant Service API.

  1. HTTP POST file metadata to StartAttachmentUpload API, which will provide a signed Amazon S3 URL and attachment ID for uploading the file directly to Amazon S3.

  2. HTTP PUT file data to the signed Amazon S3 URL.

  3. HTTP POST attachment ID to CompleteAttachmentUpload to finalize the upload to Amazon S3.

Below is a basic JavaScript implementation for reference purposes.

//Define the html element for file using input tag <input type="file" id="fileUpload"> <input type="button" id="btnUploadFile" onclick="uploadFile()" value="Upload file"> async function uploadFile() { //Initiate the file upload by calling StartAttachmentUpload, providing the name, size, and content type of the file you want to upload. //The response will include a pre-signed URL and headers to use when building the file upload request, as well as an AttachmentId. const files = document.getElementById('fileUpload').files; const file = files[0]; const startUploadRequest = { AttachmentName: file.name, AttachmentSizeInBytes: file.size, ContentType: file.type };idid const { AttachmentId, UploadMetadata } = await startAttachmentUpload(startUploadRequest); //Send the file data to the pre-signed S3 URL. //The file is stored in a temporary location in the S3 bucket. await uploadFileToS3(file, UploadMetadata.Url, UploadMetadata.HeadersToInclude); //Finalize the file upload by calling CompleteAttachmentUpload, providing the AttachmentId. //This moves the file to the final Attachments S3 path configured for the connect instance. const completeUploadRequest = { AttachmentIds: [ AttachmentId ] }; await completeAttachmentUpload(completeUploadRequest); } async function startAttachmentUpload(requestData){ const response = await fetch(StartAttachmentUploadEndpoint, { method: 'POST', headers: { 'Content-Type': 'application/json' 'X-Amz-Bearer': ConnectionToken, }, body: JSON.stringify(requestData) }); return response.data; } async function uploadFileToS3(file, signedUrl, headersToInclude) { return fetch(signedUrl, { method: 'PUT', headers: headersToInclude, body: file }); } async function completeAttachmentUpload(requestData){ return fetch(CompleteAttachmentUploadEndpoint, { method: 'POST', headers: { 'Content-Type': 'application/json' 'X-Amz-Bearer': ConnectionToken, }, body: JSON.stringify(requestData) }); }

For an example of a real world implementation, view the Amazon Connect ChatJS JavaScript client on GitHub.