[Resolved] Show user profile / filter api call


#1

Hi I would like to be able to view one record from a table returned from an API call.

In this case a table in bubble platform if that’s important to know.

In the back end table there’s a user table that has the name, email, profile picture, dob, etc.

I would like to view a profile data for current user only. I really have know qlue how to do this, have followed tutorial but didn’t see an explanation how to do that.

So I am trying to view users where unique id (user id) = current user after a user has logged in.

Below are what I found so far.

  1. There are two endpoints related to user table. Obj/user and obj/user(unique id) and I don’t know which one I should use.

  2. If I use obj/user, how do I enter parameter? I created page variables called myuser but I don’t know how to assign that myuser = current user. Then I also don’t know to filter obj/user’s unique id = page Variable.

  3. If I use obj/user (unique id), there’s api paremeters Under body - unique id. But how do you implement unique id = current user. And after that how do i apply that filter.

So, basically how to implement dynamic filter in Dropsource.

In addition, how do I display the result, do I still need to use dynamic table even though there’s only one record shown?

Thanks in advanced.


Display text and images from bubble to dropsource without dynamic list
Displaying user profile ? Not working
#2

By the way. My app is following the structure from the photo saver app tutorial, the only difference is that instead of showing list of pictures on collections page, I am trying to show current user profile.

However I want to save the user unique id after a user logged in (maybe as device variable since it will be used throughout tha app?), I just don’t know how to do that and how to apply the filter.


#3

To answer your questions in a simple way:
obj/type - returns a list of things of type
obj/type/{uniqueid} - returns a single object of type with uniqueid

In your specific case obj/user will return all things in your bubble Users table.
And obj/user/{uniqueid} will return a single user with the provided uniqueid

On the question of how to get the current user’s id. You can get that from the response to your login workflow api call.
Your login api call from Bubble should return both the token (which you will use for all other authenticated calls) and a user_id as shown below.

You can store the user_id in a Device variable just the same way you stored the token and use it anytime you want to get details of the current logged in user (using obj/user/user_id).


#4

thanks @seanhoots.That’s really helpful!

This is what I have done. I am documenting this so other users may benefit from this (please chime in if there’s a better way):

Under ws/login endpoint I added user id variable under the 200 event:

On the user profile page, on the obj/user/{unique id} end point:

Bind response to element which is a regular label, not dynamic cell. Perhaps I still need to use dynamic table even though there will be only one record shown?

Assigned unique id as parameter under path

Test and run the build and successfully showing the test user


#6

@seanhoots @rkresnadi

Does this work with all data types in Bubble, or just the one where the user data is stored?

I have one data type that is created when the user creates an account and another data type for storing some other information also associated with that user. However, I can only get the get/obj/{uniqueid} to work with the data type where bubble created the user initially and not any other data types. When i try another data type and the same method i get a 404 not found error.

What could cause this?


#7

Its hard to tell without seeing your swagger spec.
Make sure that you updated your swagger spec file in dropsource when you added the the data types.
Also check your privacy settings in your bubble database .


#8

Hi @seanhoots

Thanks for replying. I have checked both of those.

I found another issue when i was testing with POSTMAN and i really don’t know how to explain it. Basically, the “_id” and the “Created by” is changing from one data type to the other. I created a post here:


#9

Just took a look at that post on the bubble forum.
There is nothing wrong, that’s how it’s supposed to be.
You said the user in the first table created the row in the second table.
That’s why the Created By value in the second table is the same as the id in the first table.
Every new row will have a new unique id. That’s why the row in the second table has a different id.
So if you want to find the user that created the row in thr second table, you should be searching with the Created By not the id field.


#10

I see. I was under the impression that the “Created By” was equal to this response from the login?

image

I don’t see a Created By in the responses in Dropsource. Do i need to modify the swagger file to make that happen?


#11

The login request is to an API WORKFLOW endpoint in bubble so there is a predefined fields that it returns.
It’s not a DATA endpoint.
The GET obj/user/{uniqueID} is a data endpoint so will return all the fields of the user table which will include the Created By field


#12

Yes, i believe i understand the difference between workflow endpoints vs data endpoints. When i get the “_id” from the GET obj/user/{uniqueID} that is indeed the same as the “created by” in the GET obj/user_info/{uniqueID}. But when I use that in the GET obj/user_info/{uniqueID} request, and pass it as a device variable to the UniqueID parameter in the GET obj/user_info/{uniqueID} request it searches for the “_id” in the GET obj/user_info/{uniqueID} entry, not the “created by” column. And it appears to me that is why it isn’t working. So i think we are on the same page on that part. I don’t see a “created by” in the GET obj/user/{uniqueID} though. Only the “_id”:

To me it also makes sense it isn’t passing the “created by” in the GET obj/user/{uniqueid} because the bubble api workflow doesn’t seem to create one when you make a new user:

Am i making sense? Or am i completely off.


#13

Yes that is how bubble database is set up. The default User table doesn’t have a Created By field because it is the user who creates themselves. So if there was to be a Created By field then that value will be the same as the “_id”.
Aside this special User table, every table in bubble will have a Created By field. You can go to your bubble database and you will see there is no Created By field in the User table and hence the reason why you don’t see it in dropsource.


#14

Ok. So that part works fine then (and it does work for me when i run the GET obj/user/{uniqueid}, but it seems then, that the UniqueID parameter in GET obj/user_info/{uniqueid} is searching in the wrong field.


#15

@Asger so what exactly are you trying to acheive?
If you want to find the user that created the field on the user_info table you cannot just use GET obj/user/{uniqueid}.
You will have to do a filtered search.
You will have to do GET obj/user_info and have a constraint that the Created By field is equal to the uniqueid, where unique id is the user id


#16

Oh… Then my approach is wrong for sure.

I will have to look into how to do that.


#17

It is not. Its doing exactly what you stated.
If you say GET obj/user_info/123. You’re saying get me the row with _id 123.
But this is not what you want. You rather want the row whose Created By field is 123 and to do that you will have to do a search with a contraint. This is because you don’t know the id of that row, you only know the Created By value


#18

Take note that the _id field in your user_info table is not a user id, it is just a unique id for that row. Every table you create in bubble will have this id field and every row in a table will have a unique value for this field.


#19

I see, that makes sense.

So is it the search and filter in this guide i should be using instead?


#20

Yes that’s it. It takes some getting use to but once you get it its simple.


#21

Totally works. Took me 30 min to do it, haha. Did a few errors, but it was really pretty straight forward. Took me 3 days of hair pulling to look in the right place though…

Thanks a lot @seanhoots