I have an endpoint/webhook that gets data in the form of a string inside a json object. I can receive the chunk of data from the object and place it in one field of some data type when the webhook fires.
The data is comma separated an should go in to individual fields of a data type.
How can I achieve this?
Not the most elegant solution but here’s a suggestion.
Use Regular Expression to extract out all the csv data. Use “Extract with Regex” with
If you then choose Item# you can obtain each individual item. For example, if you choose Item #3, then you will get the 3rd item in the csv list.
You can use backend workflow to recursively go through the thing based on the extract method above and then put it into the fields that you choose. You can detect the number of elements in the field by doing a count after “Extract with Regex” is applied to the field.
Thanks this was helpful!, managed to extract the first item.
How do I run/make the flow recursive?
Make it schedule itself on current date/time and place an extinguishable conditional to make it stop
How to Run a Loop in Bubble.io
In your ENDPOINT that detects the new message, you would firstly create the thing. For example say you have a new MESSAGE thing. This may be your Step 1. This Message thing would now have all the data received (including the comma separated value in a field).
In Step 2, run another Backend Workflow (say Workflow 2) which takes Step 1 Message Thing as the input.
In Workflow 2, setup 2 fields that accepts the Count of the CSV elements and reference to the Message Thing. You need to provide this data in Step 2 of Workflow 1.
As Workflow 2 runs, it should decrement the count by 1 for every iteration. At the end of each iteration, it calls Workflow 2 again, now giving the Revised Count (that is less by 1). In Workflow 2, have a condition that once count detected is 0 to Terminates Workflow 2 .
Of course, in each Workflow 2 run, you will need to setup the condition for extraction using Regular Expression so that you can get your elements to populate the fields using “Make changes to existing thing”.
Hope this helps.
Thanks @cmarchan and @kaventan1 this solved my problem!
I had a new problem, the data comes in like this: “name1,type1,name2,type2”
So I need to take care of two words in each iteration and store them in different fields. When using :extract with Regex:item#iteration I couldn’t add +1 to #iteration.
Solved it by making a new API workflow and posting iteration+1 and then save the second word. is there a nicer way or regex syntax to achieve this?
Noticed that it was possible to do this :extract with Regex:count/2 when I posted MaxIterations to the first API workflow.
I’m not sure if you mean the following but I would do it the way shown below.
I would consign all iteration to run on 1 workflow. For example, there are 100 values inside the 1 css list. In 1 iteration run, I would have 2 action.
I would pass the following variables to the recursive workflow:
- “total” : Count of the CSV AND
- “iteration” : in this case it is always 1 (as we are starting the iteration)
In the first iteration, value of 1 is passed to the backend workflow.
This is what happens in my wf:
Iteration WF Run number 1
a) Action 1, extract with Regex item 1 (initially passed value of 1)
b) Action 2, extract with Regex item 2 (initially passed value of 1 add 1)
Call wf again with “iteration” value 3 being passed on (derived from original iteration value of 1+2 added on) and “count” value of 100.
Iteration WF Run number 2
a) Action 1, extract with Regex item 3 (3 - passed from Run 1)
b) Action 2, extract with Regex item 4 (3 passed from Run 1 + 1)
Call wf again with “iteration” value 5 being passed on (derived from original iteration value of 3+2 added on) and “count” value 100
This goes on until your wf terminates when it detects that iteration = total.