HomeGuidesRecipesAPI EndpointsRelease NotesCommunity
Log In
Guides

Upload Documents into Layar

Pre-Reqs

We will need to use a different header. We will still need to authenticate the header using the token.

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

👍

Check Your Imported Modules

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

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'

body = {'name': 'Filename.extension'}

files=[
  ('file',('filename.extension',open('C:/users/danschindler/filename.extension','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.