Adding data from API and connect user role with workflow

Hi All
I am trying to achieve is as following:

I have an API which has got data of Guests and i want to add that data in my database via a work flow and add the user with role as guest.

What I have done so far

  1. connected my API as Data via bubble API Connector
    see below

    I am connected an initialized my call all working

    I created an endpoint AddAllGuest as a test with parameters pName, pPhone and PprimaryEmail as a text.
    Then I created an action to add as guest with fields Name=pName, Phone=pPhone & Primary Email=pPrimaryEmail

    Then I added front end schedule API workflow on a list to add guests with the data from API.

    All connected and i ma getting data as required from API and adding in Database , but its adding as Guest.
    which is showing good and i am happy to see that data is coming through.

But what i dont know how to make these guest as a user. if they come to application to check their bookings and other activity.

I also done is created guest data type and Role data type with different roles

and created a field guests (list of guests) & Roles (list of roles) in User data type

I need to know how do i connect the API data as a user in database and allocate as a guest.
may be i need to restructure my database correctly before going deep in my application.
i also will have other various roles of users in application aswell. This will help establishing how to go forward.

thx Sanjay

Hi @sanjay ,

If you need your guests to be able to login and use your application then you have to create them as users - in the Users data type of the database. Instead of, or in addition to adding them as Guest records, you should add them as User records. You can use the Create an account for someone else action for this. I hope this helps.

thx louis adekoya
can you please explain little bit more
I have guest data type and user data type
so, do i create a data type role ??

or create a field guest in user type
or create a filed user in guest type.
please explain

Hi @sanjay,

You should consider whether you need the guest data type at all, especially if every guest will be a user. If you don’t need it then use your api results to create user records instead (using the action I mentioned previously). Just add the fields you have in your guest data type to the user one instead.

Assuming you do need a Guest data type then create a guest record as you’re already doing then in the next step in the workflow, create a user record. You can have a guest field on the user data type to link the two data types and you can also have it the other way (user field on the Guest data type) or both ways. It just depends on how you want to search the data. There are lots of posts in the forum about optimising for search.

Thx Louisadekoya

I do need the guest data and also have other users as tenants, landlords etc and all will have different set of fields in their profile.
so, i think i will try to take approach as creating user after adding guest in workflow.

Thx sanjay

Hi @sanjay, just to add that even with just the user data type, you can create guests as users and just set their role to Guest. Usually a user will have just one role but I see from one of your screenshots that you have Role as a list, so perhaps in your use case, users can have multiple roles. I just thought I’d mention this in case it wasn’t obvious. Good luck.

Hi Louisadekoya
great. then how do i achieve with api workflow.
can you elaborate little bit, would be kind of you.

Which bit in particular is unclear to you @sanjay? You are already using an api workflow to create guests. I’m suggesting that in that workflow, you add a step to “Create an account for someone else”. It might look something like the following:

Hi Louisadekoya
great thx so, in the example above
step 1: I add guest
step 2: I create account for someone else (guest in this case) .
but how do i tell system that the account I created is a guest user or do i have to attach the guests role somewhere>???
thx sanjay

Hi @sanjay, in my screenshot, the last field is role and I set it to Guest. You should do something similar.

i missed that
thx for your kind help

hi Louiseadekoya
I dont see guest as role
I created all different users, cleaner, Landlord, Guest,Contractor & tenant as a filed in user Type as list of users .
then i created a data type called Role with field name (Landlord, Landlord, Guest, Contactor & tenant)
and created a field in user data type as Role

Then went back to do the step in my workflow but i don’t see role=Guest( its not there
am i missing any step??
see screen


Hi @sanjay, in that case, you need to do a search i. e Do a search for Role (constraint: name = Guest)'s first item.

A better way however, is to not create a data type called Role. Instead, create an option set called Role and add the different roles to it. You should then be able to do what I did in my screenshot. If you haven’t used them before, you can find information on option sets here in the forum.

Hi Louisadekoya
i havent used option set. but it seems easy and good. i will give it a go.

1 Like

hi Louisadekoya
Thanks for help. it was great.
now i mange to do what mentioned and manage to create guest and then make the user and user option set as role.
after doing that, now the email came from api for the guest is gone in the User type and all other data like name, phone etc have gone to guest data type.
Is that normal and how now if i want to create a list of guests shown in RG. do i make RG’s groups content as user or guest ? as email is in User and other data in guest tables??

This is why I suggested that you could do away with the guest data type altogether and put all the fields in the User data type. Only users with a role of Guest would need to use these fields. Without knowing the details of your application, I would say this is likely what I would do.

Still, even with your current approach, you can add a user field to your guest table and when you create the user, you add that user to the guest record. That way your repeating group can be of guests where user = Current user.

In general, I would suggest that you take a pause and take one of the several courses available, if you haven’t done so already, just so that you don’t go down a route that will hurt your application down the line. It’s easy to make changes in Bubble, so maybe it isn’t such a big deal but better to get your data structure right from the start if you can.