How to create a thing if it is not in the DB - API Workflow

Hi people!!!

I have been struggling to make these, but unfortunately it is not happening.

I have searched all the forum before making this new tread.

Well, let´s go!

I have 2 tables, one is Client and the other is Pedidos:

Table: Client

Table: Pedidos

Client → one-to-many → Pedidos

I have setup my wokflow as below:


Searching for clients->fb_id = request data’s messenger user id
Only when Search for Client:count>0

On the second step:


Only when Result of step 1’ is not empty

Below is the return data in the API:

This setup creates the thing but with all the fields empty!!!

Even if I edit one thing and put fb_id correctly there it don´t update that thing as you can see below:

Look the return value from postman:

I have tried to everything for 5 days and nothing!!!

Waiting for yours help!!!

Thanks in advance!!!

Add a new field on the Client table called Pedidos. The field type will be “Pedidos”. Also check the checkbox for “this is a list of things.”

Now each Client record will be linked to a list of Pedidos since you already have a Client field on the Pedidos data type.

@Kfawcett, will try that ASAP!!

Thank you!!!

Hi @Kfawcett,

The workflow is not updating the Client table, it´s creating another thing.

Don’t know if the Only When Search for clients:count>0 is the proper way to do this.

I got what you said about a new field on Client table related to Pedidos but that´s not the problem now, I think.

Can you elaborate about the workflow not updating the Client?

The table Pedidos is ok because is just create a new thing.

Thank you again!!!

I would remove the second step. The “Make changes to thing” should be the only step you need, if the thing doesn’t exist then it will create a new one in the same action if you check the “Create if the thing doesn’t exist”.

image

@Kfawcett, I have looked at this, and I think it´s deprecated, not???

This option don´t show to me.

That’s odd. It should have the checkbox. I would open a ticket at https://bubble.io/bug_report

Look, from reference:

Warning: This option has been deprecated on Jul 18, 2017. Applications created after this date will not be able to access it (but it will still be applied in run mode). Instead, users can use a condition on the action and create the thing if it does not exist in an action prior to the Change Thing action. We recommend users using this optoin to follow the same pattern as they upgrade their apps.

I think the “Only when” should manage this, but can´t find how.

OK, I didn’t know they deprecated that functionality. It seems like the “makes changes to thing” should still be able to create a new thing, but I also do not understand how to get it to work based on the documentation (https://bubble.io/reference#Actions.ChangeThing).

Maybe someone from @bubble could help explain.

Actually, see Gaby’s post here: "Create if the thing doesn't exist"

2 Likes

@Kfawcett, this way it actually worked.

Will do a lot of test now and see…

Thank you for your help finding the answer and @romanmg providing it for the community!!!

1 Like