JSON API response from openAI: iterate through json and save things - search database etc

Hello guys I know this topic has been asked about a million times but I still have trouble to wrap my head around this since bubble does not natively support this (although they should).

Inside the openAI reponse content-item if have something similar to:

{
  "clusters": [
    {
      "keywords": ["keyword1", "keyword2"],
      "clusterName": "lorem ipsum cluster",
      "clusterDescription": "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."
    },
    {
      "keywords": ["keyword2", "keyword3"],
      "clusterName": "consetetur sadipscing cluster",
      "clusterDescription": "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."
    }
  ]
}

The keywords are already inside the database in Keyword DT. What I want to do is:

  • save each clusterName and clusterDescription into a new Cluster DT
  • edit each Keywort DT with a new field cluster: Cluster DT

What I have tried:

  • each and every JSON and JSON parser Plugin on the market.
  • make another call to myself within the API Connector plugin with just passing in the content and tried to connect the types but I ran into problems when searching through the database for every single keyword to add the current cluster. This ended up to be very frickly and needs high maintance imho.

My question:
How can I access the contents of this response without counting or anything related to find&replace? Needs to work in backend workflows.

Thanks for any helping hand!

Once you have called the openAI API and get the content, send it to backend WF using API Connector and let Bubble detect the content. Schedule on a list (type Clusters). This WF will create cluster DT and update a list of keywords DT Be sure to put an interval because you need to update a list of keywords DT and without interval, you will run into a racing issue
OR change the Cluster DT to have a reference to keywords DT instead (And from my point of view, this should be a better DB settings because you may reach limit of relationship field to Cluster DB if a keyword have a lot of related Cluster item. I don’t think it will be a problem from Cluster DT to keywords DT). It will also help to search Cluster DT with keywords. This will also save WU and you will run the Schedule on a list faster and without interval

1 Like

Hi @Jici, thanks for answering. I like the idea of referencing a listOfKeywords from each cluster.

I tried this method but I got stuck when searching through the possible ListOfKeywords. I try to show the following pictures in the order of operation:

The api call to myself comes in and triggers this “Schedule API Workflow on a list”:

The problem here (but I think this has been always like this): I cannot reference any of the fields directly to a datatype:

The triggered workflow on a list looks like this:


And here is also the problem. How can I search through the list of Keywords that is inside the Report DT and when it matches add this list of keywords to this cluster?


Just to show it: Before I tried to connect one cluster to one keyword and this is what I tried inside workflow 04 but it’s also not working since I cannot iterate through the listOfkeywords and if a match is found add data:

use, in your do a search for keywords with “keyword” is in “keywords” (from Backend WF settings field that is a list of text)