Google Apps脚本中的PayPal REST API错误400 [英] PayPal REST API Error 400 in Google Apps Script

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

问题描述

我正在尝试使用PayPal API为我的OnlyFans应用创建订阅。
我使用的正文与我使用邮差时的正文完全相同。
不知何故,我可以使用邮递员获得响应,但尝试通过应用程序脚本执行此操作时遇到此错误。
我已经检查了三重四重是否有任何尾随逗号等。
似乎在格式中找不到任何错误。

为什么我收到错误代码400?
"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect...


function restCall (){
  
  var restEndpoint = "https://api-m.sandbox.paypal.com/v1/billing/subscriptions"
  
  var head = {
    "Authorization":"Bearer "+ TokenProperties.getAccessToken(),
    "Content-Type": "application/json",
    "PayPal-Request-Id": "1111-1111-1111-1111"
  }

  var postPayload = 
  {
    "plan_id": "P-09E19660L3543673CMETTBBA",
    "subscriber": {
      "name": {
        "given_name": "John",
        "surname": "Doe"
      },
      "email_address": "sb-y9erz7310462@personal.example.com"
    },
    "application_context": {
      "brand_name": "Test",
      "user_action": "SUBSCRIBE_NOW",
      "payment_method": {
        "payer_selected": "PAYPAL",
        "payee_preferred": "IMMEDIATE_PAYMENT_REQUIRED"
      },
      "return_url": "https://example.com/returnUrl",
      "cancel_url": "https://example.com/cancelUrl"
    }
  }

  var params = {
    headers:  head,
    method: "POST",
    payload : postPayload
  }

  var response = UrlFetchApp.fetch(restEndpoint, params); 
}

推荐答案

尝试

  var options = {
    "contentType": "application/json",
    "method": "post",
    "headers": head,
    "payload": JSON.stringify(postPayload)
  };

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

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