API Workflow - "Created By"

I’ve set up an bubble endpoint and using API workflow to create / update a thing, based on a payload from an external app.

For “Things” created in bubble using the API workflow, the “Created By” field is empty.

Is there anyway to populate the standard fields - Created By,Created Date, Modified Date?

The users in my bubble app and my external app are the same and have the same email address.

The payload from the external app contains the email address of the bubble user. I want to match email and set the “Created By”.

1 Like

Yes, if you use the an API workflow to log the user in, and then use the token that is returned as the authentication token.

See this https://bubble.io/reference#API.authentication

Another option is to create another field that contains the ‘creator’, and save it there. Up to you.

Perfect! Many Thanks.

Will try it out.

For last option - I’ve already created data privacy rules, based on the Built-In “Creator” field that is available on all “Things”. So unless there is no other way, I want to avoid using a custom field for this.

It is not clear to me how to use API workflow to log the user in.

After reviewing the documentation, I used Postman to test what I understood from the documentation.

I used the API Token that I generated in the Settings Tab - API section for Authorization.

As you can see, it is not working :frowning:

Can you share a link? It’s probably an issue with how you set the API workflow.

Hi Emmanuel,

My API workflow is available on open app for forum questions here, the endpoint is called “flight”. The thing updated is also called “Flight” and contains three fields.

My use case is this: An external app has the same users as my bubble app (match based on email address). When the external app sends data to my bubble app (payload includes user’s email) , I want to create / update a thing in my bubble app as my user (using my user’s credentials).

I have:

  1. Enabled "This app exposes a GET/ Data API on thing “User”

  2. Generated an API Token

Thanks!

So first thing, you have errors in your workflows (see the red in the screenshot attached), so i CAN’T work. The first step to debug is to make sure you don’t have errors.

Second, what is the logic in your workflow? Why do you need to log the user is? If sounds like you just want to create a flight. If you want the created by to be the current user you’ll need the API token as I said earlier, but it’s a bit complex as you need people log in. I would just run the workflows with your admin private key.

Yes, you are correct. I have corrected the errors in the workflow.

Yes, you are correct. I do not need to log in the user. I only want to create a flight and the created by to be the current user.

It is not clear to me how I specify the current user if I use my admin private key. I called the endpoint and ran the workflow using postman. I set the Authorization in the header using the admin private key.

Right now, I’m able to create a flight but it is not populating the “Created By” field.

My API workflow is available on open app for forum questions here

If you run things with the private key, the creator is the app owner (admin), which is not a user of your app per se, so the field will look empty. If you want to save a user, you should put this in another field.

@emmanuel

Thanks!

If there no other option available, I’ll go with your suggestion. I’m reluctant to implement it this way - store in another field - since it is not very “clean”.

From your explanation of API token, it looks like it needs the user to really log in. I do not want to do this, because it does not make sense in my use case.

Is the following possible?

STEP 1: I use my admin private key to get the authentication key of a user (does this exist?).

This would be similar to how UBER and others enable external apps to use UBER features on behalf of UBER’s users. In the UBER like scenario, they use OAuth. In my scenario, I do not think I need to do this since I’m the admin/owner of the my bubble App.

STEP 2: I use the authentication key of the user to create a flight on their behalf.

All want to do is to create a flight and the created by to be the current user. The matching is based on the email address which is available in the payload.

Is there any way to do this without creating a new field?

No not currently.

Got it. So once the Bubble API returns the following:

“user_id”: “123212x1343141140”,
“token”: “34234234119x234234234234”,
“expires”: 31234000

How do we proceed with “logging into Bubble” via our webview in a native app? Do we pass the user_id and token in as headers of a new Authenticated API call along with the stored username and password?

What just worked for me is to put this into the header:

Authorization: Bearer ###

where ### is the token you got back from Bubble in the last request.

1 Like