Hi Everyone,
I am new to coding so this may be easy but trying to figure out the best way to do this.
I am using a button click script to trigger a query using query.trigger() and this will create an event in the endpoint. The trigger returns an ID, which I need to use in a second call to poll and wait until the process is complete (this is a document parsing API btw).
The response from the first query looks like this -
{
"message": "667b325291d3f49feae94b55"
}
The response from the second query looks like this when the file isn't done parsing:
{
"_id": "667b331d91d3f49feae94e85",
"name": "lock confirmation 30.pdf",
"content_type": "application/pdf",
"status": "parsing",
"created_at": "2024-06-25T21:14:05.440Z",
"processed_at": null,
"filename": "lock confirmation 30.pdf",
"credits": 0,
"json":
}
If you wait about 4-5 seconds and run the call again, the response changes to display the information:
"_id": "667b331d91d3f49feae94e85",
"name": "lock confirmation 30.pdf",
"content_type": "application/pdf",
"status": "parsed",
"created_at": "2024-06-25T21:14:05.440Z",
"processed_at": "2024-06-25T21:14:24.884Z",
"filename": "lock confirmation 30.pdf",
"credits": 3,
"json": {
"adjustments": "0.814",
"advanced_features": "--",
"agency_case_assignment_date": "--",
"amortization_term": "360",
"appraised_value": "435,000.00",
"arm_initial_fixed_term_months": "--",
"aus_recommendation": "Approve Eligible",
"aus_type": "DU",
"base_loan_amount": "300,000.00",
"base_price": "101.112",
-- cutting it here to show example.
My goal is to run the script and then trigger the first API call, get the ID from the response, then trigger the second call and poll until the parse is complete.
In the UI, I want to show a pop-up loading message with the spinning loading logo until the parsing is complete.
What's the best way to go about this?
Thanks in advance!