Google Cloud Endpoints API Encounter 404 Error

Scenario
Currently, my setup involves AppEngine Cloud Endpoints using a Bootstrap JavaScript UI along with a Google SQL Datastore.

Issue
The problem arises when the Javascript tries to call gapi.client.load and receives a 404 error. Surprisingly, the API Explorer functions correctly and the JavaScript works fine when tested locally... However, the failure occurs only when attempting to load the API via JavaScript.

This is the error message displayed in Chrome:

GET https://MyAppID.appspot.com/_ah/api/discovery/v1/apis/myAP…%2Cversion%2CrootUrl%2CservicePath%2Cresources%2Cparameters%2Cmethods&pp=0 404       ()
zu @ cb=gapi.loaded_0:83
n @ cb=gapi.loaded_0:83C
u @ cb=gapi.loaded_0:83
(anonymous function) @ cb=gapi.loaded_0:84
g @ cb=gapi.loaded_0:55
c @ cb=gapi.loaded_0:46

Additionally, it leads to another exception of "Cannot read property" due to the inability to locate the method within the unloaded API.

Code

The snippet from my index.html page:

        function init() 
        {

            apisToLoad = 2;

            var callback = function() 
            {
                if (--apisToLoad == 0) 
                {
                      signin(true, userAuthed);
                   }
            }

            gapi.client.load('oauth2', 'v2', callback);
            //LOCALCHANGE (SWITCH BETWEEN LOCAL AND NOT)
            gapi.client.load('myAPI', 'v1', callback, 'https://MyAppId.appspot.com/_ah/api');
            //gapi.client.load('myAPI', 'v1', callback, 'http://localhost:8080/_ah/api');

        }

To ensure all aspects are covered, I am including my appengine.xml as well:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>MyAppID</application>
<version>1</version>
<threadsafe>true</threadsafe>
<use-google-connector-j>true</use-google-connector-j>

<system-properties>
    <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
</appengine-web-app>

and my web.xml content:

<?xml version="1.0" encoding="utf-8" standalone="no"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
    <servlet-name>SystemServiceServlet</servlet-name>
    <servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
    <init-param>
        <param-name>services</param-name>
        <param-value>com.lthoi.myAPI</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>SystemServiceServlet</servlet-name>
    <url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>

If there are any other potential locations where the error might be hiding, feel free to suggest further examination or provide additional files for review.

Answer №1

I am experiencing the same issue as you. It appears that there is a bug in Google's webapp endpoints that has been causing this issue for quite some time now.

Here is a link to previous discussions on this topic: https://github.com/google/google-api-javascript-client/issues/147

(Apologies for posting this as an answer instead of a comment, I just recently created an account)

Answer №2

It turns out the issue at hand was simply a matter of incorrect capitalization. I had correctly entered the URL, but mistakenly tried to load 'myAPI' instead of 'MyAPI', as it was written in MyAPI.java. Remember, it's the value in the annotation that needs to match exactly, not necessarily the class name. Hopefully this helps anyone else who may have made the same silly mistake!

Answer №3

If you're looking to gather method information on an API, gapi.client.load can help by querying discovery (make sure to check the URL for proper integration as it may return a 404 error). It's worth noting that cloud endpoints do not currently support discovery functionalities.

In situations where discovery is unavailable, experimenting with direct API calls might be a viable alternative (though success isn't guaranteed). For example:

gapi.client.request({
  // Customize your service address, URI path, and query parameters accordingly.
  'root': 'https://your-domain.appspot.com',
  'path': '_ah/api/foo/bar', // adjust based on your service
  'params': {
    "foo": "bar"
  }
}).then(
  function(resp) {
    console.log(resp);
  },
  function(err) {
    console.log(err);
});

Hopefully, this solution proves helpful.

(Please be aware that using CORS feature mentioned in a previous revision of this response is experimental, undocumented, and unsupported. It was used solely for debugging purposes and has since been removed from the code.)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The most lightweight scraper for individual website pages

There is a certain website that constantly updates its data. Unfortunately, there is no API available to access this information programmatically in JavaScript, which presents a common challenge for me. To tackle this issue, I have created a simple JavaSc ...

There was an issue with locating the module: Error: Unable to find the specified module 'vue-axios' in the directory 'C:xampphtdocsvue-laravel-api esourcesjs'

I am currently working on a CRUD project using Laravel and Vue.js. I made sure to install all the necessary devDependencies, but when I try running NPM run watch, I encounter the following error: My app.js file includes all the required dependencies: ...

Unable to find any matches when conducting a search through Google Apps Script

After spending days analyzing the code, I am encountering an error that states "uncaught reference error: google is not defined." This issue seems to occur specifically in line 360. Curiously, when inspecting the original code editor, line 360 simply conta ...

A guide to updating property values in an array of objects in JavaScript while ensuring they remain in consecutive order

I am dealing with an array of objects called list. The parameters rid and rorder are provided for processing. -> 1. Whenever the value of rid matches the id in the list, the itemorder is updated with the value of rorder. -> 2. In the updated list p ...

Running "vue ui" with Node.js v17.2.0 - A step-by-step guide

After updating to Node.js v17.2.0, I am facing issues with running "vue ui" in my project. The error message I receive indicates a problem with node modules: at Object.readdirSync (node:fs:1390:3) at exports.readdir (/usr/local/lib/node_modules/@vu ...

Obtain the current user's Windows username without relying on the ActiveX object

Is there a way to retrieve a client's Windows username in ASP.NET when hosted on a remote server without using an ActiveX object? I tried the following code: Response.Write("HttpContext.Current.Request.LogonUserIdentity.Name " & HttpContext.Cur ...

Troubleshooting: 404 Error When Trying to Send Email with AJAX in Wordpress

In the process of creating a unique theme, I encountered an interesting challenge on my contact page. I wanted to implement an AJAX function that would allow me to send emails directly from the page itself. After conducting some research, I managed to find ...

Send a request for a multidimensional array to a PHP file using AJAX

I am in need of an array containing subarrays. Within my ProcessWire page, there are pages and subpages with various fields. I have organized this information into an array of arrays as shown below. <?php $allarticles = $pages->find("template=a ...

What are some methods for creating a Venn Diagram that includes data within each section using SVG, CSS, or Canvas?

I am attempting to replicate this visual representation using pure SVG, CSS, or Canvas drawing. So far, I have successfully created three circles that overlap and placed a label in the center of each one. However, I'm facing challenges when it comes t ...

Unable to execute ajax on dom ready in Internet Explorer 9

Here is some code that needs to be executed on DOM ready without any user interaction: if($.browser.msie){ console.log("Using getJSON"); $.getJSON(baseUrl,function(){ alert('hi'); }); }else{ setTimeou ...

React-NextJS encountered an error: TypeError, it cannot read the property 'taste' because it is undefined

Recently, I've been encountering an issue with NextJS that keeps throwing the error message: TypeError: Cannot read property 'taste' of undefined. It's quite frustrating as sometimes it displays the expected output but most of the time ...

The function fails to return a true value

Why is true never returned even when the given name exists in the array rows and the if(rows[i].userName == name) condition is met? function checkIfUserExists(name){ var isUserExists = false; OOTW.MYSQL.query('SELECT * FROM Time',functio ...

Utilize the csv-parser module to exclusively extract the headers from a file

Recently, I've been exploring the NPM package csv-parser which is designed to parse CSV files into JSON format. The example provided demonstrates how you can read a CSV file row by row using the following code snippet: fs.createReadStream('data.c ...

When the link_to element is clicked, use AJAX to replace the content of a specific

I was wondering about a modification to the link in view/users/show: <%= link_to "Photos (#{@user.photos.count})", user_path(@user), id: "photo_link", remote: true %> My goal is to dynamically change [1..6] to [1..-1] without having to rerender the ...

What is the technique for arranging the display of a component in React?

Is there a way to dynamically render a component in my react-app at a specific date and time, like 6.00PM on October 27, 2022? I want to release a form for signing up starting from that exact moment. The timestamp information will be stored in my database ...

Tips on utilizing ajax to load context without needing to refresh the entire page

As a beginner in AJAX, I have some understanding of it. However, I am facing an issue on how to refresh the page when a new order (order_id, order_date, and order_time) is placed. I came across some code on YouTube that I tried implementing, but I'm n ...

Viewing the JSON Data

Support: $scope.createTimeSlots = function(interval, field) { var startingTime = moment().hours(8).minutes(0); field.timeslots = []; for (var i = 0; i < interval; i++) { $scope.intervals = 60; field.timeslots.push(startingTi ...

What is the process for verifying a Bootstrap form?

I have created a form using Bootstrap (Form component in ReactJS), but when I attempt to click on the submit button without entering any input, the form is still submitted. How can I implement form validation so that it only submits when all input fields a ...

Encountering an error while trying to add text: SyntaxError - Unexpected token 'for

I'm trying to print out the elements of an array using JavaScript. let listToArray = ["a","b","c"]; $(".tooltip").append(for(let i = 0; i < listToArray.length; i++) {listToArray[i]}); But I keep getting an error that says Uncaught SyntaxError: U ...

Creating an inverted curve or border-radius for a div element is a design technique that can add

I've been tackling a project that requires me to style the border of a div in an inverted manner. To achieve this, I'm limited to using only CSS and JS without any plugins. I've searched through various online resources and similar questions ...