OpenEnergyPlatform / oeplatform

Repository for the code of the Open Energy Platform (OEP) website. The OEP provides an interface to the Open Energy Family
http://openenergyplatform.org/
GNU Affero General Public License v3.0
61 stars 20 forks source link

Id not returned after successfull insert #633

Open henhuy opened 3 years ago

henhuy commented 3 years ago

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]]
jh-RLI commented 6 months ago

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?

henhuy commented 6 months ago

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.

jh-RLI commented 5 months ago

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.

wingechr commented 5 months ago
jh-RLI commented 5 months ago

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