HomeGuidesRecipesAPI EndpointsRelease NotesCommunity
Log In
Guides

Upload documents into Layar

Pre-Reqs

Before a document search can be done the API requests must be authenticated. Make sure you have already followed the instructions for importing dependencies and authentication from the Getting Started Guide.

👍

Check Your Imported Modules

Make sure you have imported the requests and json module before proceeding with this guide.

The following header can be used in your request.

header = {'Accept': 'application/json',
          'Content-Type': 'application/json',
          'Authorization': f"Bearer {token}",
          'X-Vyasa-Client': 'layar',
          'X-Vyasa-Data-Providers' : 'sandbox.certara.ai',
	  'X-Vyasa-Data-Fabric' : 'YOUR_FABRIC_ID'
  	 }

Uploading a document

To upload a document, we'll be using the Source Document API to add a document to the Layar data fabric.

The first step is to upload the document to the Layar API

curl 'https://YOUR_SERVER_HERE/layar/sourceDocument' \
-X POST \
-H 'Authorization: Bearer YOUR_TOKEN_HERE' \
-F 'name=filename.pdf' \
-F 'file=@path/to/local/file/filename.pdf'
uploadDocsUri = f'{envUrl}/layar/sourceDocument'

header = {
        'Authorization': f"Bearer {token}",
        'X-Vyasa-Client': 'layar',
        'X-Vyasa-Data-Providers' : 'sandbox.certara.ai'
        }

body = {'name': 'Test_doc.docx'}

files=[
  ('file',('Test_doc.docx',open('C:/Users/dschindl/Documents/Test_doc.docx','rb')))
]


response = requests.post(uploadDocsUri,
                         headers = header,
                         data = body,
                         files = files,
                         )

documentId = response.json().get('id')
print(documentId) #optional

The response of the document upload will contain an ID that you can use to reference the document in the future. In the example below, the ID is AYXGsE6FbZ95yV31x8iZ

{
    "cortexDocumentType": "DOCUMENT",
    "createdByUser": 25001,
    "id": "AYXGsE6FbZ95yV31x8iZ",
    "metadata": {},
    "mimeType": "application/pdf",
    "name": "filename.pdf"
}

Processing of documents after upload is an asynchronous process. You can monitor the status of the uploaded document by calling the Source Document Status API using the ID returned above (e.g. in this instance it's AYXGsE6FbZ95yV31x8iZ)

curl -X GET 'https://YOUR_SERVER_HERE/layar/sourceDocument/AYXGsE6FbZ95yV31x8iZ/status'
-H 'Accept: application/json' 
-H 'Authorization: Bearer YOUR_TOKEN_HERE'
docStatusUri = f'{encUrl}/layar/sourceDocument/{documentId}/status'

response = requests.get(docStatusUri,
                        headers = header
                       )

print(response.text)

As the document is processed, the API will return with a status of Processing

{
  "percent":75,
  "message":"Processing..."
}

Once the document is uploaded and ready for querying and use in the data fabric, the status will change to 100% and the message will read Complete

{
  "percent":100,
  "message":"Complete!"
}

Up Next

Now that we have a subset of documents to work with, we can add those documents to a set.