1

我在 vbscript 中创建以下请求并发送到 gocardless 沙箱:

url="https://api-sandbox.gocardless.com/"
typ="GET"
Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
xml.Open typ, url, False
xml.setRequestHeader "Authorization", "Bearer " & GCAccessToken
xml.SetRequestHeader "GoCardless-Version", "2015-07-06"
xml.SetRequestHeader "Accept","application/json"
xml.SetRequestHeader "Content-Type", "application/json"
xml.Send
GetGC = xml.responseText
Set xml = Nothing

尽管我做了任何调整,但我总是得到的回应是:

{"error":{"message":"not found","errors":[{"reason":"not_found","message":"not found"}],"documentation_url":"https://developer.gocardless.com/api-reference#not_found","type":"invalid_api_usage","request_id":"0AA4000DECCD_AC121CEB1F90_5BE18701_19AD0009","code":404}}

任何帮助,将不胜感激。已经成功地为 Stripe 做了类似的事情,但现在需要使用 GC。

4

1 回答 1

2

如果您阅读 API 的响应

{
  "error": {
    "message": "not found",
    "errors": [{
        "reason": "not_found",
        "message": "not found"
      }
    ],
    "documentation_url": "https://developer.gocardless.com/api-reference#not_found",
    "type": "invalid_api_usage",
    "request_id": "0AA4000DECCD_AC121CEB1F90_5BE18701_19AD0009",
    "code": 404
  }
}

该错误似乎是一个 HTTP 状态代码(这在 RESTful API 中很常见) ——404 Not Found查看响应中提供的文档链接;

404

未找到。未找到请求的资源或经过身份验证的用户无法访问该资源。响应正文将解释未找到哪个资源。

所以问题可能是;

  1. 您未能使用提供的代码中的令牌进行身份验证。
  2. 您已通过身份验证,但无权访问该资源。
  3. 您要查找的资源不存在。

在这个特定的例子中,我建议这是因为资源不存在,因为代码没有指定资源,只有 API 的基本 URL 不会构成您可以与之交互的 API 端点。

查看文档很明显,您需要在 URL 中提供一个有效的端点,在撰写本文时,有 15 个核心端点与 2 个辅助端点进行交互。

例如,创建付款请求/响应如下所示;

POST https://api.gocardless.com/payments HTTP/1.1
{
  "payments": {
    "amount": 100,
    "currency": "GBP",
    "charge_date": "2014-05-19",
    "reference": "WINEBOX001",
    "metadata": {
      "order_dispatch_date": "2014-05-22"
    },
    "links": {
      "mandate": "MD123"
    }
  }
}

HTTP/1.1 201 (Created)
Location: /payments/PM123
{
  "payments": {
    "id": "PM123",
    "created_at": "2014-05-08T17:01:06.000Z",
    "charge_date": "2014-05-21",
    "amount": 100,
    "description": null,
    "currency": "GBP",
    "status": "pending_submission",
    "reference": "WINEBOX001",
    "metadata": {
      "order_dispatch_date": "2014-05-22"
    },
    "amount_refunded": 0,
    "links": {
      "mandate": "MD123",
      "creditor": "CR123"
    }
  }
}

不幸的是,问题中提供的代码示例并没有真正做任何事情,因此很难建议您尝试做什么。总之,我建议重新访问API 的文档并查看提供的示例。

于 2018-11-07T08:44:25.033 回答