In this example, we create a library, add a file, index the file, and poll until the library is ready for use.

This step creates a new file (SFDRIVE) library and returns a presigned upload URL.

The curl command calls the einstein/data-libraries resource. For more information, see ADL Resource Reference in the Connect REST API Developer Guide.

Expected Response: JSON with libraryId and groundingSource fields.

The library needs to provision Data 360 resources before files can be uploaded. This command polls for up to two minutes. If the resources aren’t ready after two minutes, you can run the script block again.

Expected Response: includes { "ready": true }

Request presigned URLs for your files. If you call file-upload-urls before the Data 360 resources are ready, a HTTP status of 400 is returned and you must wait for the upload-readiness call in the previous step to indicate readiness before you retry.

You can upload a maximum of 1000 files to a library.

Extract the presigned URL and headers from the creation response, and upload the PDF file.

The presigned URL includes headers. You must parse the header and send it (UPLOAD_HEADERS) to S3.

Expected Response: HTTP Status: 200

Index the uploaded file.

Expected Response: includes { "status": "IN_PROGRESS" }

This command loops every 10 seconds until the status is READY or FAILED.

Expected: After a few minutes, the status transitions to READY. This script exits when the status is READY, FAILED, or all stages report SUCCESS. The READY status requires chunking/embedding to complete for the SearchIndex. ALL_STAGES_SUCCESS means that the ADL pipeline is done even if SearchIndex processing is still pending.

After the library is READY or ALL_STAGES_SUCCESS is true, you can add more files to the library.

Update the path for NEW_FILE and run this command block.

Expected Response: HTTP Status: 200

Expected Response: includes { "filesAccepted": 1 }

Congratulations! You successfully added a second file to your library.