400 状态码Parse.Cloud.httpRequest

400 Status Code when making Parse.Cloud.httpRequest

我返回了 400 错误,这可能意味着由于语法错误导致请求格式错误。但是,我看不到它,所以也许其他人可以发现它。这是代码:

Parse.Cloud.define("sendWelcome", function(req, res)
{
    var userId = req.params.userId;
    var welcomeBody =
    {
       'recipients': [ userId ],
       'sender': { 'name': 'RealSheek' },
       'parts':
       [{
        'body': 'Welcome to RealSheek!\n\nThanks for becoming a member. We hope you have fun with RealSheek - finding fun stuff, sharing it with your friends as you chat with them about it, and making collections.\n\nBe sure to invite your friends, and let us know how we can help ("Contact Us" from the app menu).\n\nCheers,\n\nThe RealSheek Team',
        'mime_type': 'text/plain'
        }],
       'notification': { 'text': 'Welcome to RealSheek!', 'sound': 'chime.aiff' }
    };
    var welcomeBodyJSON = JSON.stringify(welcomeBody);

                   console.log("\n\n\n"+welcomeBodyJSON);

    Parse.Cloud.httpRequest(
    {
      method: 'POST',
      url: "https:api.layer.com/apps/" + layerProviderID + "/announcements",
      headers: 
      {
        'Accept'            : 'application/vnd.layer+json; version=1.0',
        'Authorization'     : 'Bearer n4YeGaeJDmsC0kMdem28fsVjNuUOqhO86aqCUYoBNBYzjRP9',
        'Content-Type'      : 'application/json'
      },
      body: welcomeBodyJSON
    }).then(function(httpResponse) 
    {
        res.success();
    }, 
    function(httpResponse) 
    {
        res.error('Request failed with response code ' + httpResponse.status);
    });
});

变量userIdlayerProviderID是正确的字符串并且是有效的ID。 URL 是正确的,授权令牌也是如此。

仅供参考,它使用名为 Layer 的消息传递平台向新注册的用户发送欢迎消息。 Layer 有一个平台 API,它允许各种功能,例如向用户发送消息或发送公告(这就是我在这里所做的)。

我已经根据 API 的要求检查了 body;这是 Layer 的示例:

{
    "recipients": [ "1234" ],
    "sender": {
        "name": "The System"
    },
    "parts": [
        {
            "body": "Hello, World!",
            "mime_type": "text/plain"
        }
    ],
    "notification": {
        "text": "This is the alert text to include with the Push Notification.",
        "sound": "chime.aiff"
    }
}

所以,正如我所说,我被困住了。感激地接受任何帮助。

提前致谢!

是否有助于将您的 url 从 https:api.layer.com/apps/ 更改为 https://api.layer.com/apps/