Apps 脚本 PUT API [英] Apps Script PUT API

查看:26
本文介绍了Apps 脚本 PUT API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是使用 Apps 脚本更新 API,但我不知道如何去做.为简单起见,这是我的代码:

My goal is to update an API using Apps Script but I cannot work out how to do it. For simplicity sake here is my code:

let APIkey = "...";
let url = "..."

newData = {"stock_status": "instock"}

//Update API

问题是我不知道如何进一步.我已阅读此 API 的相关文档,但无济于事,而且我在 Apps 脚本文档中找不到有关放置请求的任何信息.

The problem is I do not know how to get any further. I have read the relevant docs to this API but to no avail and I couldn't find anything about put requests in the Apps Script docs.

推荐答案

答案:

您需要使用 UrlFetchApp.

我不知道您的 API 如何接受身份验证,但假设它接受密钥作为 URL 参数,那么您可以执行以下操作:

I don't know how your API accepts authentication, but assuming it accepts the key as a URL parameter then you can do something like:

let APIkey = "..."
let url = "..."

const newData = {
  "stock_status": "instock"
}

var options = {
  'method' : 'PUT',
  'contentType': 'application/json',
  'payload' : JSON.stringify(newData)
}

UrlFetchApp.fetch(`${url}?key=${APIkey}`, options);

您可以阅读关于 fetch 的完整文档 这里

You can read the full documentation on fetch here

这篇关于Apps 脚本 PUT API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆