I'm getting 404 error when I post request to google execution api from chrome extension.
I'm sure my client id is correct and scopes are correct. Also, my script id and function name to call are correct as well.
I also published the script as api executable to everyone.
Here is my sample chrome extension files.
Please give me a help!
I've been stuck with this problem for a long time.
manifest.json
{
"name": "Execution Api Test",
"version": "0.1",
"manifest_version": 2,
"description": "Execution Api Test",
"permissions": [
"identity",
"tabs",
"http://*/*",
"https://*/*"
],
"background": {
"scripts": ["background.js"]
},
"oauth2": {
"client_id": "816912884742-icjd8pjj58m4rvrh211f1rrg97bkepho.apps.googleusercontent.com",
"scopes": [
"https://www.googleapis.com/auth/spreadsheets"
]
},
"page_action": {
"default_icon": "icon.png",
"default_title": "test"
}
}
background.js
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
chrome.pageAction.show(tabId);
});
chrome.pageAction.onClicked.addListener(function () {
chrome.identity.getAuthToken(
{'interactive': true},
function(token) {
//I get access token successfully.
console.log(token);
var scriptID = "MR4ao03vpkqX-hTekNkflNDxdZGPvncRS";
var apiURL = "https://script.googleapis.com/v1/scripts/" + scriptID + ":run";
var requestBody = {
"function": "myFunction",
"devMode": true
};
var xhr = new XMLHttpRequest();
xhr.open('POST', apiURL, true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
xhr.send(JSON.stringify(requestBody));
});
});