appscript api 无效内容

发布于 2025-01-12 08:55:23 字数 1161 浏览 0 评论 0原文

我正在尝试使用来自 https://whapi.io/ 的 Whatsapp API

使用邮递员,它没有显示错误 使用邮递员成功的结果

但是当我尝试通过创建自定义函数在 googlesheet appscript 中使用时

function whatsappSend() {
  var myHeaders = {
      "contentType": "application/json"
    }

  var raw = JSON.stringify({
    "app": {
      "id": "601154119177", //sender@api_key
      "time": "1646716022", //sample_data
      "data": {
        "recipient": {
          "id": "60133102649" //recipient number with country code
        },
        "message": [
          {
            "time": "1646716022",
            "type": "text",
            "value": "Hello World!11"
          }
        ]
      }
    }
  });

  var requestOptions = {
    method: 'POST',
    headers: myHeaders,
    body: raw,
    redirect: 'follow'
  };

  var res = UrlFetchApp.fetch("https://whapi.io/api/send", requestOptions);
  console.log(res.toString())
  
}

它显示无效-content

{"msg":"invalid content","result":"error"}

那么如何创建工作 appscript 函数,以便使用此 api 发送? 谢谢

i'm trying to use whatsapp api from https://whapi.io/

using postman it show no error
result using postman success

but when I try to use in googlesheet appscript by creating custom function

function whatsappSend() {
  var myHeaders = {
      "contentType": "application/json"
    }

  var raw = JSON.stringify({
    "app": {
      "id": "601154119177", //sender@api_key
      "time": "1646716022", //sample_data
      "data": {
        "recipient": {
          "id": "60133102649" //recipient number with country code
        },
        "message": [
          {
            "time": "1646716022",
            "type": "text",
            "value": "Hello World!11"
          }
        ]
      }
    }
  });

  var requestOptions = {
    method: 'POST',
    headers: myHeaders,
    body: raw,
    redirect: 'follow'
  };

  var res = UrlFetchApp.fetch("https://whapi.io/api/send", requestOptions);
  console.log(res.toString())
  
}

it show invalid-content

{"msg":"invalid content","result":"error"}

So how to create working appscript function, for sending using this api?
thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨与橙与城 2025-01-19 08:55:23

这个文档来看,下面的修改如何?

修改后的脚本:

function whatsappSend() {
  var raw = JSON.stringify({
    "app": {
      "id": "601154119177", //sender@api_key
      "time": "1646716022", //sample_data
      "data": {
        "recipient": {
          "id": "60133102649" //recipient number with country code
        },
        "message": [
          {
            "time": "1646716022",
            "type": "text",
            "value": "Hello World!11"
          }
        ]
      }
    }
  });
  var requestOptions = {
    method: 'POST',
    contentType: "application/json",
    payload: raw,
  };
  var res = UrlFetchApp.fetch("https://whapi.io/api/send", requestOptions);
  console.log(res.getContentText())
}

注意:

  • 如果出现错误,请再次确认raw的值。

参考:

From this document, how about the following modification?

Modified script:

function whatsappSend() {
  var raw = JSON.stringify({
    "app": {
      "id": "601154119177", //sender@api_key
      "time": "1646716022", //sample_data
      "data": {
        "recipient": {
          "id": "60133102649" //recipient number with country code
        },
        "message": [
          {
            "time": "1646716022",
            "type": "text",
            "value": "Hello World!11"
          }
        ]
      }
    }
  });
  var requestOptions = {
    method: 'POST',
    contentType: "application/json",
    payload: raw,
  };
  var res = UrlFetchApp.fetch("https://whapi.io/api/send", requestOptions);
  console.log(res.getContentText())
}

Note:

  • If an error occurs, please confirm the values of raw again.

Reference:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文