I am trying the simple get at endpoint proto datastore for few days.
http://endpoints-proto-datastore.appspot.com/examples/simple_get.html
It works, but it always return not found.
Here is the get by id api.
https://pttbuying.appspot.com/_ah/api/pttbuying/v1/items/4504690549063680
Here is my model code.
class Item(EndpointsModel):
_message_fields_schema = ('id', 'item_title', 'item_link', 'item_price', 'item_description_strip', 'datetime')
item_title = ndb.StringProperty(indexed=False)
item_author_name = ndb.StringProperty(indexed=False)
item_link = ndb.StringProperty(indexed=True)
item_description_strip = ndb.StringProperty(indexed=False)
item_price = ndb.StringProperty(indexed=False)
datetime = ndb.DateTimeProperty(auto_now_add=True)
Here is my api code
@endpoints.api(name='pttbuying', version='v1',
allowed_client_ids=[WEB_CLIENT_ID, ANDROID_CLIENT_ID,
IOS_CLIENT_ID, endpoints.API_EXPLORER_CLIENT_ID],
audiences=[ANDROID_AUDIENCE],
scopes=[endpoints.EMAIL_SCOPE])
class PttBuyingApi(remote.Service):
"""PttBuying API v1."""
@Item.method(request_fields=('id',),
path='items/{id}', http_method='GET', name='item.MyModelGet')
def MyModelGet(self, my_item):
if not my_item.from_datastore:
raise endpoints.NotFoundException('Item not found.')
return my_item
@Item.query_method(query_fields=('limit', 'order', 'pageToken'), path='items', name='item.list')
def MyModelList(self, query):
return query
Am i missing something? Thanks for advice.
I did your example here and it works nicely with some changes:
I didn't change a thing regarding the model, just the api methods.
Just perform an item insertion, get the ID of the item that was just inserted and then perform the ItemGet with the ID provided.
For the get i prefer this way (not using the /{id}, but requiring the user to do a GET Query - i.e, ah/api/path?id=__ , which seems more correct for me). If you have any questions, ask bellow.