0

I am building an API and using Google App engine standard environment, Java 8 runtime.

The REST api itself is built over guice + google endpoints apis.

I have configured the API Key based security for the endpoint as well. The issue I am facing is that when I provide an incorrect key, the service responds 400 Bad request with an HTML error payload.

<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>400 API key not valid. Please pass a valid API key</title>
</head>

<body text=#000000 bgcolor=#ffffff>
    <h1>Error: API key not valid. Please pass a valid API key</h1>
</body>

</html>

Is there a way to make the endpoint send a JSON message instead? I'd rather not burden the clients to parse HTML in some one-off cases.

Thanks

OpenAPI.json (Generated using :mvn endpoints-framework:openApiDocs ) Edited to remove sensitive info.

{
 "swagger": "2.0",
 "info": {
  "version": "1.0.0",
  "title": "my-app.appspot.com"
 },
 "host": "my-app.appspot.com",
 "basePath": "/_ah/api",
 "schemes": [
  "https"
 ],
 "consumes": [
  "application/json"
 ],
 "produces": [
  "application/json"
 ],
 "paths": {
  "/operation/v1/query/{type}": {
   "get": {
    "operationId": "Lookup",
    "parameters": [
     {
      "name": "type",
      "in": "path",
      "required": true,
      "type": "string"
     }
    ],
    "responses": {
     "200": {
      "description": "A successful response",
      "schema": {
       "$ref": "#/definitions/Result"
      }
     }
    },
    "security": [
     {
      "api_key": [ ]
     }
    ]
   }
  }
 },
 "securityDefinitions": {
  "api_key": {
   "type": "apiKey",
   "name": "key",
   "in": "query"
  }
 },
 "definitions": {
  "Result": {
   "type": "object",
   "properties": {

    "field1": {
     "type": "string"
    },
    "field2": {
     "type": "string"
    }
   }
  },
 }
}
jayaram S
  • 580
  • 6
  • 13
  • Hi, GCP Endpoints does return a json response, for instance when following this [tutorial](https://cloud.google.com/endpoints/docs/openapi/get-started-compute-engine-docker) and passing a wrong api key using curl I do get a json response: { "code": 3, "message": "API key not valid. Please pass a valid API key.", "details": [ { "@type": "type.googleapis.com/google.rpc.DebugInfo", "stackEntries": [], "detail": "service_control" } ] } – Andres S Feb 03 '20 at 18:20
  • ok i wonder if there is a difference between the compute engine vs App engine standard deployments? – jayaram S Feb 04 '20 at 16:59
  • In the yaml file you define the format to be used, for instance in the app engine endpoints [tutorial yaml file](https://cloud.google.com/endpoints/docs/openapi/get-started-app-engine-standard#endpoints_configure) is set as: "produces: - application/json" for json format – Andres S Feb 04 '20 at 22:28
  • yeah I got that in my json file. "produces": [ "application/json" ], It is rather strange. – jayaram S Feb 05 '20 at 17:36
  • could you please share your endpoints openapi.yaml (remember removing sensitive data and url's) – Andres S Feb 19 '20 at 18:30
  • Just added the json. – jayaram S Feb 19 '20 at 20:14

0 Answers0