Create a thing via POST (API) and link it to the user

Hi,

I searched the internet for this but couldn’t find anything. Also tried to go through Bubble’s API docs but didn’t find anything either.

Here’s the thing: I am trying to create a thing via a POST request to my Bubble app. Everything’s ok up to this point, no problem creating the thing. The problem is that I would like to link that thing to a given user (by ID ?).
I tried to add a unique_id parameter to the request or a Created By but I get an error - statusCode 400 - when doing so: Unrecognized field: Created By.

Any ideas? Anyone successfully created a thing and linked it to a user, or to its parent thing?

Thanks!

You can’t manually set or modify the ‘Created By’ field, so if you’re creating things via the API and would like to link the thing to a User, you just nee to add an additional User field to the Datatype… then use the User’s unique ID…

The Bubble docs state regarding use of PUT call which replaces an entry that we can set the built in fields including the created by.

@adamhholmes have you used the PUT call before? I’ve had the issue since 2020 and now need it to actually work.

I’m currently waiting to hear back from support regarding the fact the PUT call doesn’t function properly as none of the built in fields are ‘recognized’ but they should be.

This post details a portion of the issue Fields created by logged in users shows "deleted thing" - #8 by boston85719

Yes, I have used the PUT call correctly, with no issues (including a quick test I just ran to confirm)…

That said, I can’t find anything in the docs about being able to modify the Created By or Created Date Fields (and if you try it, it won’t let you, as those are built in fields which you don’t have access to).

So I’m fairly sure it’s not possible to manually change those, and have never seen anything to suggest otherwise… (I also spoke to Bubble support fairly recently about this and they confirmed it’s not possible)…

Where have you seen the docs state you can do that?

1 Like

I’ll bet Boston is referring to this statement in this area of the documentation?

Note that any field not included in the PUT request will be deleted, included built in fields such as ‘Created Date’, so use with caution.

Am I right, Boston? If so, I don’t think it is stating you can actually set those fields (because as we know, you can’t set them, and Bubble support has confirmed that), but I do see how that statement could be interpreted in a couple of different ways.

1 Like

Hi and thank you all for your replies!

@adamhholmes, I did not think of that, thank you!. But before even testing it, a question comes to my mind: I have some privacy rules applied throughout the app to the current user. How would creating a specific property that links the created thing to a user would work with those?

Yeah, that just means that the Created Date field will be deleted…

1 Like

The Privacy Rules for Current User will work just the same, but you’ll have to change or add the additional User field as part of the rules…

@adamhholmes @mikeloc

Yes, I definitely read

Note that any field not included in the PUT request will be deleted, included built in fields such as ‘Created Date’, so use with caution

as saying that you need to make sure to include the built in fields otherwise they will be deleted.

And not seeing any specific language in either the modify or replace section indicating that the built in fields can not be modified or replaced, I naturally assumed they could be.

When I first tested this back in 2020 the only built in field not working was the created date, so my first attempt resulted in all fields filled in (modified and created by) but not the created date. I reached out to support back then to find out what was the proper syntax, either Created Date or Creation Date since Bubble uses both interchangeably in the system and never got an answer on that, nor was I informed it not possible or possible to make changes to the built in fields via the API.

Now when I am testing again with this setup below

I get this result in the database

The use of the query string checkbox makes it so the initialization doesn’t report any errors and shows the 204 success with empty body as per the documentation, but clearly the custom fields are empty, but the built in fields are not empty and the Modified Date is the current date and time. So the values sent are ignored, but still the entry is modified.

Then when I remove the query string parameter and the built in fields as below

I get the following result in the database.

The values I sent for custom fields are correct, however, the built in fields are not deleted as the documentation says they will be.

When I uncheck querystring from the first setup with the built in field parameters still present, I get the error of unrecognized field for all 3 built in fields.

So, clearly I’m very confused on what is what. Still waiting for support to respond to my request for more clarity on the subject.

@adamhholmes @mikeloc

Just wanted to circle back to this, as I have finally gotten a reply with some feedback from Bubble support on this after requesting support on December 12.

Below is the reply

Our engineers have informed me that the built-in fields Creator , Created Date , and Modified Date cannot be changed by the PUT request. This is a somewhat recent change that wasn’t adequately communicated, so we sincerely apologize for any confusion this has caused

I’m now struggling to understand, what exactly would be the difference between a PUT call and a PATCH call if the PUT call doesn’t actually replace an entry and is instead just modifying data fields.

Also really scratching my head as to why they would have removed this ability, if it was available previously.

Really hoping they may elect to put the ability back in as it would be great to have again.