GoCardless API using Classic ASP

463 views Asked by At

I'm creating the following request in vbscript and sending to the gocardless sandbox:

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

The response I always get despite any tweaks I do is:

{"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}}

Any help would be appreciated. Have successfully done similar for Stripe but now need to use GC.

1

There are 1 answers

1
user692942 On BEST ANSWER

If you read the response from the 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
  }
}

The error appears to be a HTTP status code (as is common with RESTful APIs) - 404 Not Foundlooking at the documentation link provided in the response;

404

Not Found. The requested resource was not found or the authenticated user cannot access the resource. The response body will explain which resource was not found.

So the issue could be;

  1. You have failed to authenticate using the token in the code provided.
  2. You authenticated but don't have permission to access the resource.
  3. The resource you are looking for does not exist.

In this particular instance, I would suggest it is because the resource doesn't exist as the code doesn't specify a resource, only the base URL of the API which won't constitute an API endpoint you can interact with.

Looking at the documentation it's clear you need to provide a valid endpoint in the URL, at the time of writing there are 15 core endpoints to interact with along with 2 helper endpoints.

For example, a create payment request/response would look like;

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"
    }
  }
}

Unfortunately, the code sample provided in the question doesn't really do anything so it's difficult to suggest what you are trying to do. In conclusion, I would suggest re-visiting the documentation for the API and look through the samples provided.