I have a database type with 3 fields: TaskID, Input, and Rephrase.
The TaskID and Input are added to the database record at one time, and then after a delay (a custom API processing), the Rephrase is returned through a backend API post request. If I add the API response to the database as a new record, it works fine, and I can see the Rephrase in my database. However, I want to update the existing record that contains the TaskID and Input. Attached is my configuration, what am I doing wrong? The current configuration does nothing.
What is the name of the data-type which you say has three fields? Is that âRephraseâ?
What are the parameters to the API workflow receive-response?
Hi Ivan.
It looks like youâre passing task_id to the API call and then searching for the Task based on that. As a first step to improve this, Iâd suggest passing the new Task itself to the API, then you donât have to search for it in your âMake changesâŚâ step.
Presumably on your page youâve got something like:
Step 1 - Create a new Task
Step 2 - Schedule API call
The API call should pass the parameter Task = results of Step 1.
Doing it this way is good practice anyway as it ensures your API call doesnât run before the task exists (which could potentially be the problem youâre describing).
James
AppEDGE
Hi James,
Take a look at the screenshot.
The bottom record exists in the database prior to the backend workflow firing/the API response returning to bubble. What I would like to happen, is that when the API response is returned, it searches the database for the matching taskID (which is included in the API response), and if it finds a match, updates that record to fill in the Response field (also included in the API response.
Youâll see in the top record in the screenshot, that when I try to âCreate a new thingâ instead of âMake changes to a thingâ it correctly adds the API response to the database. This tells me the API response is working correctly, but for whatever reason, bubble isnât able to update the preexisting record based on the taskID. My goal is to have all three fields in the same record.
Thanks for your help!
Data type: Rephrase
- Field: taskID
- Field: Input
- Field: Response
The API returns a âresultâ which is the âresponseâ in the database, and the taskID.
Prior to the API response, there is a record in the database that includes the same taskID and the Input. I want to update the pre-existing record that has the matching taskID to fill in the Response data field returned from the API. The attached screenshot shows the preexisting record on the bottom and the result of creating a new record from the API response on the top. I want only one record.
Hi Ivan,
I assume the âCreate a new Rephraseâ is just there for you investigating the issue?
My main question at this stage would be why are you using taskID? You may have a really good reason for doing so, but it doesnât make sense based on what youâve shared so far.
It would be helpful to see some details of the workflow thatâs calling this backend workflow - is it something youâre doing on a page, just after the task has been created?
In many scenarios, on the page you already know what Task youâre dealing with so you itâs better to pass the Task object (as opposed to the text taskID) as the parameter to the backend workflow.
But like I said, I might be missing something in what youâre doing to call this.
My gut feeling is that you are triggering your backend workflow before the task you want to update has been created - this can happen unintentionally, even though it seems odd and out of sequence.
James
AppEDGE
Thanks again James,
Yes, the Create new Rephrase is just to investigate the issue.
The taskID is necessary for the API. The initial workflow is: User types in inputâ>POST request to API with inputâ>API immediately responds back with taskIDâ>Input and taskID stored in databaseâ> API processes input (There is significant delay in processing the input, which is why I use a taskID through celery in my API)â> when API is finished processing, send POST request using backend workflow to bubble with the taskID and output.
There are scenarios where the app could be handling multiple tasks at once, so the taskID (I think) is necessary to keep the inputs and outputs in sync.
I would like to investigate further if I am triggering my backend workflow before the task, but Iâm not sure thatâs possible. To my knowledge, the backend workflow only triggers when the POST request comes in from my API. Given that there is a delay of at least a couple seconds that it takes my API to process, I donât see how thats possible. The API doesnât send the POST request until processing is finished. Also, when i troubleshoot using the Create a new thing, I can see the initial task get created, and then after a few seconds, the new thing appear in the database.
Thanks so much again for your help!
Okay, looks like you have set up a webhook or a public API and not just an API workflow that is invoked internally within Bubble application. (Youâre sure it is needed to be done that way?)
One silly question, but since I have made such silly mistakes in past myself, just checking: When you did the testing, hope you did remove the object that got created because of your âcreate new thingâŚâ? Otherwise it is possible that âsearchâŚâ in update action is returning the object that you created in your previous test.
Hey Ivan,
Thanks for the detailed explanation. Iâd assumed you were calling it from within Bubble, so your approach makes more sense now.
If the thing definitely does exist, perhaps itâs not being returned by your search. Which made me wonderâŚ
Your receive-response API workflow is set to run without authentication, but isnât set to ignore privacy rules. Are there any privacy rules set for your Rephrase data type? If not âeveryoneâ can see all Rephrases, those settings could explain why your workflow canât search for and find the Rephrase itâs meant to update, but it can create a new one.
Itâs a shot in the dark, but worth checking.
James
AppEDGE
1 Like
Thatâs exactly what was wrong. The privacy rules were preventing the backend workflow from reading the taskID in the database. Checking the âIgnore privacy rules when running this workflowâ worked. This is my first bubble app, so Iâll have to read up on the privacy rules to figure out the best way of implementing this.
Thanks again for your help!
1 Like
Great news and really glad I could help.
All the best with your project.
James
AppEDGE