400 from GAE Cloud Endpoints

I am trying to make the following api call for my GAE cloud endpoint:

gapi.client.myapp.foo.update({
  "value": "foobar",
  "key": "keyvaluefromlistoperation"
}).execute(function(resp) {
  console.log(resp);
});

Answers the following:

[
 {
  "error": {
   "code": 400,
   "message": "Bad Request",
   "data": [
    {
     "domain": "usageLimits",
     "reason": "keyInvalid",
     "message": "Bad Request"
    }
   ]
  },
  "id": "gapiRpc"
 }
]

Note. Before this call, I authenticated, inserted several foo objects, and then called a list to return them to the client. The api explorer update utility works fine and works under the reduction of the jQuery snippet below. Any suggestions? Or am I just in an experimental country of errors.

var token = gapi.auth.getToken();
$.ajax({
  type:"POST",
  beforeSend: function (request) {
    request.setRequestHeader("Content-Type","application/json");
    request.setRequestHeader("Authorization", token.token_type+" "+token.access_token);
  },
  url: "https://myappid.appspot.com/_ah/api/myapp/v1/foo/update",
  data:JSON.stringify({
     "value": "foobar",
     "key": "keyvaluefromlistoperation"
  }),
  processData: false,
  dataType: "json",
  success: function(msg) {
    console.log(msg);
  },
  failure: function(msg) {
     console.log(msg);
  }
});

Here is the Java code:

@Api(
    name = "myapp",
    description = "This is the myapp rest interface",
    scopes = {"https://www.googleapis.com/auth/userinfo.email"},
    version = "v1",
    clientIds = {Ids.WEB_CLIENT_ID}
)
public class FooV1 {

    private static PersistenceManager getPersistenceManager() {
        return PMF.get().getPersistenceManager();
    }

    @ApiMethod(
            name = "foo.update", 
            httpMethod = HttpMethod.POST
    )
    public Foo update(Foo foo, User user) throws OAuthRequestException, IOException, UnauthorizedUpdateException {
        PersistenceManager pm = PMF.get().getPersistenceManager();

        if (user != null) {
            try {
                Foo f = pm.getObjectById(Foo.class, foo.getId());
                if ( Security.isUpdateAuthorized(f, user) ) {
                    if( foo.getValue() != null ) f.setValue(foo.getValue());
                } else {
                    throw new UnauthorizedUpdateException("");
                }
            } finally {
                pm.close();
            }
        } else {
            throw new OAuthRequestException("Invalid user.");
        }

        return foo;
    }
}
+5
source share
1 answer

I had the same problem. Apparently, you cannot use the “key” as a field after deployment in GAE. Locally, it worked fine.

+8
source

All Articles