Example Get and Post requests. ============================== The redirect must be turned on in the ajax request. .. Caution:: If you get a CORS error while posting, set the ``Content-Type`` to ``text/plain``. Add --- .. tabs:: .. code-tab:: js GET fetch("https://script.google.com/.../exec?action=add&data=Hello,World") .then(res => res.json()) .then(res => console.log(res.status + ", id: " + res.id)); .. code-tab:: js POST fetch("https://script.google.com/.../exec?action=add", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ data: ["Hello", "World"] }) }) .then(res => res.json()) .then(res => console.log(res.status + ", id: " + res.id)); Delete ------ .. tabs:: .. code-tab:: js GET fetch("https://script.google.com/.../exec?action=delete&id=123456") .then(res => res.json()) .then(res => console.log(res.status)); .. code-tab:: js POST fetch("https://script.google.com/.../exec?action=delete", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ id: "123456" }) }) .then(res => res.json()) .then(res => console.log(res)); Read ---- .. tabs:: .. code-tab:: js GET fetch("https://script.google.com/.../exec?action=read&id=123456") .then(res => res.json()) .then(res => console.log(res)); // { status: true, data: ["Hello", "World"] } .. code-tab:: js POST fetch("https://script.google.com/.../exec?action=read", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ id: "123456" }) }) .then(res => res.json()) .then(res => console.log(res)); List ---- Lists all data if there is no limit parameter. .. tabs:: .. code-tab:: js GET fetch("https://script.google.com/.../exec?action=list&limit=3") .then(res => res.json()) .then(res => console.log(res)); // { status: true, data: [["Hello", "World"], [...], [...]] } .. code-tab:: js POST fetch("https://script.google.com/.../exec?action=list", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ limit: 3 }) }) .then(res => res.json()) .then(res => console.log(res)); Update ------ .. tabs:: .. code-tab:: js GET fetch("https://script.google.com/.../exec?action=update&id=123456&data=Hi,World") .then(res => res.json()) .then(res => console.log(res)); .. code-tab:: js POST fetch("https://script.google.com/.../exec?action=update", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ id: "123456", data: ["Hi", "World"] }) }) .then(res => res.json()) .then(res => console.log(res.message + ", id: " + res.id));