Id not returned after successfull insert
When running insert command from here:
https://oep-data-interface.readthedocs.io/en/latest/api/how_to.html#insert-data
data gets inserted and I get Response Code 201
But I cannot find resulting ID in response?
results.json() returns {'description': [['id', 20, None, 8, None, None, None]], 'rowcount': 1}
but no key data, as shown in example:
>>> import requests
>>> data = {"query": {"name": "John Doe"}}
>>> result = requests.post(oep_url+'/api/v0/schema/sandbox/tables/example_table/rows/new', json=data, headers={'Authorization': 'Token %s'%your_token} )
>>> result.status_code
201
>>> json_result = result.json()
>>> json_result['data'] # Show the id of the new row
[[1]]
Just saw this issue.
This is where the response is built up, and yes, the ID is not part of it:
https://github.com/OpenEnergyPlatform/oeplatform/blob/45f31b1ed495026be7a9242307214a956a7174c2/api/actions.py#L1401-L1414
I think this would be good to have? But I'm a bit afraid that this is a big change to the API? What do you think about this?
In the example, there is a key data which is not present yet in the response.
IMO adding an entry data holding the resulting ID, would only add value and cannot break anything.
Right, I wonder where that key came from :D It probably got kicked out accidentally (or on purpose - without documentation of course). I will discuss this in the next OEP-DEV round. I vote for implementing it.
- I don't even know why the returned description is for the id column. it's not intuitive at all and maybe should be removed completely.
- as for returning the row id: I think it's a good idea. It just gets a little more complicated. the api also allows to insert multiple values at once. should the return value then be an array of the ids?
Good point. I think at some point we shoud create a v1 of the API and streamline things like this.
I would assume that in this case an array with all new IDs is returned. But I'm not as familiar with how other apis do this either. Maybe I can find a "best practice", otherwise we can decide here what we want and then just document that decision.
BTW: I added this not "yet very helpful" open api documentation to our oeplatform docs. So we could just start updating the documentation and show it there. Currently, to show changes in the documentation, you have to manually generate the open api schema.
https://openenergyplatform.github.io/oeplatform/install-and-documentation/oeplatform-code/web-api/oedb-rest-api/#open-api