Detect new records from a rest api and send it

Hi any chance i can use workflow for this use case?

I got a inventory management with rest api i need to detect when a new product is created and then pass is and save it to a retool db and show that info in a table for internal use and then also send that to another rest api is that possible?

Hi @agaitan026,

Yes, great idea! Use Retool Workflow to detect new records from a REST API and send them to another REST API. Here is a basic workflow:

  1. Add a Call API block to your workflow and configure it to call the REST API that returns the inventory data.
  2. Add a Filter block after the Call API block and configure it to filter the data to only include new records.
  3. Add a Save to Database block after the Filter block and configure it to save the new records to the Retool database.
  4. Add a Call API block after the Save to Database block and configure it to call the REST API that you want to send the new records to.

You can use the following steps to configure the Filter block to filter the data to only include new records:

  1. In the Filter block, click the Add condition button.
  2. In the Condition field, select the Date field that contains the creation date of the inventory records.
  3. In the Operator field, select the Greater than or equal to operator.
  4. In the Value field, enter the current date.

This will filter the data to only include inventory records that were created on or after the current date.

You can also use the Filter block to filter the data by other criteria, such as the product category or the supplier.

Here is an example of a Retool Workflow that detects new inventory records from a REST API, saves them to the Retool database, and sends them to another REST API:

# Call the API to retrieve the inventory data.
response = workflow.call_api("https://my-api.com/inventory")

# Filter the data to only include new records.
new_records = filter(lambda record: record["created_at"] >= datetime.datetime.today(), response.json())

# Save the new records to the Retool database.
workflow.save_to_database("inventory", new_records)

# Call the API to send the new records to another REST API.
workflow.call_api("https://my-other-api.com/inventory", method="POST", body=json.dumps(new_records))

This is just a basic example, but it should get you started.

Happy Retool'ing!

:grinning:

Patrick

3 Likes

awesome thank you so much

2 Likes