Forum Academy Marketplace Showcase Pricing Features

How to Set Up Login API

Hello Bubble-folk…

I want users of my app to access the data they have created in Bubble on their own web site, via JSON. Hence I want to expose various data types via the API, based on their own user login credentials that are embedded in the GET url.

Some things I have worked out:

In settings, I’ve enabled “This app exposes a data API”. I’ve selected the types to expose.
I’ve accessed the JSON for those types via the “…api/1.1/obj/type_name” path.

A good start.

Two questions remain.

1) Use of Endpoints
I believe I can access more qualified data by creating an API End Point within the API Workflows section.
I’ve tried that, (see setup below) and I am accessing it with the url:
…api/1.1/obj/endpoint_no_auth_no_privacy
But I’m getting a “type not found” message.
Should the URL be different when I’m accessing an endpoint rather than a type?

2) Login API
Since my site will have mulitple users, I need the API to perform a login process. The reference manual discusses this, but the words make no sense to me!
Can someone advise me the specific steps to take to set up the URL so that a user login is performed?

Many thanks in anticipation,

Antony.

================================
Reference Manual on Login Authorisation

Create Sign up/Login API workflows. This is useful for building an alternative front-end to the Bubble app, such as a native app that you developed. When an API workflow contains a sign up or login action, then a user ID, token, and expiration, expressed in seconds, are returned with the response of the call. Subsequent calls to the app’s API, with a header Authorization: Bearer API_TOKEN, runs all calls and workflows in the context of the user associated with the token. This user will be the ‘Current user,’ who you can access with actions. Privacy rules will apply to this user as they would if the user was logging in the Bubble app and using it in their own browser. This token should be kept safe.

image

3 Likes

Yep, you should use wf (for workflow) instead of obj (for a type of thing).
Also the name of the endpoint should be used not the workflow name.
So in your case the endpoint should be:

api/1.1/wf/test_endpoint and not api/1.1/obj/endpoint_no_auth_no_privacy

For your second question:

  1. Create a new workflow endpoint.
    Note that the name of the workflow (blue circle) is not the same as the endpoint name (red circle).
    In my case below i was using the same name but they can be different.
    You will use the Endpoint name in your api calls.

  2. After creating the Endpoint event, create a new login action as shown below.
    Note that the fields email, password are from those defined above.
    When you click on the dynamic field for both the Email and password the field will be available at the top for you to select.

3 Likes

Thanks for your rapid answer @seanhoots!

So yes, that makes sense… but when I change the url to be the endpoint name, then I get the message:

Wrong method. Should be a post

So with my basic knowledge of getting and posting, this implies it is looking for me to send data to Bubble rather than extract data from it.

Can I use endpoints in the API to expose JSON data from my Bubble app? If so, how do I do that?

Or am I restricted to exposing it from specific types using the api/1.1/obj/type form?

Thanks!
Antony.

1 Like

Thanks again @seanhoots for the second answer. I’ve set up the login as you describe.

However I’m totally unclear on how to activate the login. I am using:

api/1.1/wf/login?email=“[email protected]”&password=“banana”

and getting the same message about a post being expected.

How do I activate the login as a post?

Many thanks!

Antony.

Any progress with this @antony and any possible clarification @seanhoots ? I am stuck at the same step as @antony. My endpoint name is “login”. My browser shows the below print screen when I am at:
(1) https://myappnameishere.bubbleapps.io/version-test/api/1.1/wf/login?email=“[email protected]”&password=“1234” ***note: email and password are pre-existing log ins
(2) or https://myappnameishere.bubbleapps.io/version-test/api/1.1/wf/login

I was of the impression that we should be using the below address to utilize a bubble api, as per instructions on https://help.dropsource.com/docs/documentation/integrating-with-dropsource/api-tools/connect-your-app-to-bubble/.
https://myappnameishere.bubbleapps.io/version-test/api/1.1/meta/swagger.json

Looking forward to hearing on your progress

"12%20pm

1 Like

As the error message states you’re using the wrong method.
API workflows are POST not GET.
And you don’t just enter them as url. You have to call them as API requests from whatever application your calling you’re trying to login from.

1 Like

Hi there @sherman!

Good to hear from you. I didn’t get much further along the line with this one. I only managed to read the JSON data externally with a non password protected situation. My project is quite vast and so I decided to come back to it all another time, and that time doesn’t seem to have arrived yet. It’s not such an obvious topic if you do not have experience in this world of post, get, webhooks etc.

I think the documentation around this may have been updated in the Bubble Reference since I was working on it so I would recommend you reading that in some detail.

As @seanhoots says, you need the app which is receiving the data to be making the request, so I would recommend really digging into that documentation too.

It would be great if you can post anything you find out here!

Best wishes,
Antony.

1 Like

What if I am using a webview in dropsource. How do I log users in?

Hi @antony - I ran into the same problem as you did and solved it now by checking the “querystring” option which seems to be new:

Hope this helps,
Chris

1 Like

I know I am late to the party - this article details how to login to Bubble database from external apps (in this case a Dropsource app). It’s a shame Dropsource has not progressed their no code offering further.

how can i retrieve current user detail from api such as name? i only get current user email using obj/users/{uniqueID}

@antony @kenlaji

Did you guys managed to do this?