Aleksis Andersonsd
 · Founder @ Bill

How to save a changing response structure from external API in database?

Answered

Hello!

I am trying to save a list of transactions from my bank account in my DB.

For example: here you can see that there is one incoming (account top up) and one outgoing transaction (paying a utility bill). One of them has a creditor name (utility provider) and another one has a debtor name (my own account from which I topped up).

This is how my function stack looks like. I am pulling the data from external API (which works fine and I can display results on screen), however, when I try to save it to DB, I run into a problem as in my loop I am expecting to have both, creditor account and debtor account saved as items.

How can I adjust my looping to allow to sometimes skip creditor account or debtor account if it is missing from the response structure and in other cases when it is provided save it in the database?

5 replies