Calling endpoints with API JavaScript client library with promises

33 views
Skip to first unread message

Renaud Tarnec

unread,
May 28, 2016, 11:04:34 AM5/28/16
to Google API JavaScript Client
Hi,

I have a  web application which calls several AppEngine Endpoints with the Google API JavaScript client library.

I am currently changing this application from callback mode to promises mode, as recommended by Google (https://developers.google.com/api-client-library/javascript/features/promises#using-promises) and I am encountering a problem. Note that the app works well with the callback mode.

My problem with the promises mode is to find what is the correct path argument to use when calling the request method:

JavaScrit code:

var params = {'webSafeKeyParent’: ‘neN4fm15xW52b2ljZXMtb19saW5lmlYLEglBY1NFwpRpdHkYgICAgQj97AoM’};
gapi.client.request({
    'path': 'https://myappenginename.appspot.com/_ah/api/customerApi/v1/?????????',
    'params': params
    }).then(function(response) {
            // Handle response       
}, function(reason) {
            // Handle error
});


Endpoint definition in "customerApi":

@ApiMethod(
name = "listByParent",
path = "customerByParent/{webSafeKeyParent}",
httpMethod = ApiMethod.HttpMethod.GET,
scopes = {Constants.EMAIL_SCOPE},
clientIds = {Constants.WEB_CLIENT_ID, com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID},
audiences = {Constants.ANDROID_AUDIENCE})
public List<Customer> listByParent(final User user, @Named("webSafeKeyParent") final String webSafeKeyParent, @Nullable @Named("cursor") String cursor, @Nullable @Named("limit") Integer limit) throws UnauthorizedException {


For few of my endpoints it works by including in the path argument of the JavaScript request method, the values of "path" and "name" as declared in the @ApiMethod annotation.

i.e. for the above endpoint, the following path works:
https://myappenginename.appspot.com/_ah/api/customerApi/v1/customerByParent/listByParent

Strangely enough this does NOT work for some other endpoints of the same kind.

I've also tried with the paths displayed under "Request" when you query the endpoints with the APIs Explorer but without success....

Is there any detailed documentation for calling AppEngine endpoints with promises? I have not found any. Do you have some advice to share please?

Thanks in advance,
Renaud

PS: I've published the same post in the "Google App Engine" group

Renaud Tarnec

unread,
May 30, 2016, 4:39:57 PM5/30/16
to Google API JavaScript Client
Hi all,

Actually the request method works all the time with the "path" argument composed of the values of "path" and "name" as declared in the @ApiMethod annotation...

I don't know what I did wrong the last day.... but it works now.

Sorry if I wasted the time of the readers!
Reply all
Reply to author
Forward
0 new messages