Issue posting objects with generated id

Hi all,

I’m trying to create speckle objects from a web app and post them to the speckle database.
The issue I’m facing is that it tells me the resource can’t be found.
I’m testing in postman and when I don’t provide an id myself, there is no issue. The object can be retrieved fine.
When I do provide an id (generated by org.bson.types.ObjectId), I can not retrieve the object.
Post on

/api/objects/

{
    "_id": "5fa944b431e8b343e03e9428",
    "name": "postman_object",
    "type": "Number",
    "value": 789
}

Get response on

/api/objects/5fa944b431e8b343e03e9428

{
    "success": false,
    "message": "Error: Resource not found."
}

Hey @MdeLeur, I see you’re quite active for a post-surgery situation! Hope everything went well!

Speckle 1.0 ignores user-provided ids IIRC. The reason is that there’s a quite inelegantly implemented equivalence between an object id and hash in the mongo database, and generally developer laziness in cleaning that up.

The good news is in 2.0 this will be more clear. The bad news is in 1.0 you can’t really get away with it. You need to post objects to the server, and the response gives you back the ids (in order) of the objects you sent. Not sure if this is a limitation in what you’re doing!

Ie, in ArupCarbon, objects are also created on the fly; the responses with their ids are stored, and, after all of them are in place, I create a stream with a list of placeholder objects having those ids. Would this approach work for you?

2 Likes

Thanks for the quick response! My recovery is actually going very well, thanks for asking.

I was afraid this might be the case, your approach on Carbon seems to be the way to go for us then as well, or wait for 2.0 of course :wink:

We wanted to generate our own id’s so we could already use them in some parent-child relationships, but I guess generating them on the fly is the way to go then.

Thanks!

1 Like