DEV Community

Jian
Jian

Posted on

#008 | Backend Database: Build (Part 2)

Overview

I previously setup a Xano database - refer to #007 - to store data extracted from the Custodian Statement PDFs.

I have now built Application Programming Interface ("API") endpoints in Xano that:

  1. Authenticate an API client
  2. Accept a JSON input
  3. Apply basic data checks to skip invalid records
  4. Store valid records in the MVP's Xano database

summary endpoints

The workflow below recaps what I am currently building:

Workflow

These API endpoints can be consumed by any external client, such as my Flask Python backend, so long as they have a valid Auth Token.

Making a Xano API call

I called the /add_custodian_securities endpoint, which adds data to the custodian_securities table, with a JSON payload of hypothetical data extracted using my Flask Python backend. This table stores each client's month-end Securities holdings.

The JSON payload has three records, of which the second record is a duplicate of the first record. A duplicate record exists if there is more than one record with the same entity, account number and date combination.

{
  "new_records": [
    {
      "name": "AJI",
      "exchange": "KLSE",
      "quantity": "12800",
      "last_price": "15.40",
      "current_value": 197120,
      "account_number": "A0000000",
      "date": "20241130"
    },
    {
      "name": "AJI",
      "exchange": "KLSE",
      "quantity": "12800",
      "last_price": "15.40",
      "current_value": 197120,
      "account_number": "A0000000",
      "date": "20241130"
    },
    {
      "name": "HLIND",
      "exchange": "KLSE",
      "quantity": "39000",
      "last_price": "15.22",
      "current_value": 593580,
      "account_number": "B0000000",
      "date": "20241130"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Xano API Builder & custodian_securities table before the API Call

before

before

Xano API Builder & custodian_securities table after a successful API Call

after

after

The endpoint's authentication mechanism also works, as an error was returned when an expired Auth Token was entered.

auth token

Why add data checks?

The quality of the MVP's data output is directly impacted by the quality of the data being ingested.

It is therefore important to have basic data checks to skip over invalid records before data ingestion. The endpoint should also return variables that inform the user of the data processing results.

Next Steps

I now have the building blocks to extract data from a list of PDFs and make an API call to store valid records in their respective Xano tables.

But before I proceed further, I will run some tests to ensure the endpoints are working as expected.

--Ends

Top comments (0)