,

API Series: Indentation for Humans

APIs are built for machines, and when it comes to working with data inputs and outputs, machines are very good at parsing and interpreting data very quickly. With all responses in the Znode API as JSON strings, it can sometimes be hard to read responses with the human eye, especially for large responses. While this doesn’t matter to machines, it can be useful at times to open an endpoint in a browser to see the results. For this, you can use the indent parameter for better readability.

Take for example the following endpoint to get the list of payment gateways:

GET /paymentgateways

If you open this endpoint in a browser, you’ll see something like this on screen:

{"PaymentGateways":[{"Name":"Authorize.Net","PaymentGatewayId":1,"Url":"http://www.authorize.net"},{"Name":"Verisign PayFlow Pro","PaymentGatewayId":2,"Url":"http://www.verisign.com"},{"Name":"Paymentech Orbital","PaymentGatewayId":3,"Url":"http://www.paymentech.com"},{"Name":"PayPal Direct Payment","PaymentGatewayId":4,"Url":"http://www.paypal.com"},{"Name":"WorldPay","PaymentGatewayId":5,"Url":"http://www.worldpay.com"},{"Name":"CyberSource","PaymentGatewayId":6,"Url":"http://www.cybersource.com"},{"Name":"Custom","PaymentGatewayId":7,"Url":"NA"}],"PageIndex":null,"PageSize":null,"TotalPages":null,"TotalResults":null,"ErrorCode":null,"ErrorMessage":null,"HasError":false}

Granted, it’s not a massive amount of data, but you can still make it easier for your own human eyes to comprehend that response by using the indent parameter and setting it to true, as such:

GET /paymentgateways?indent=true

Now when you open that endpoint in a browser, you get back the exact same response, but formatted for human readability:

{
  "PaymentGateways": [
    {
      "Name": "Authorize.Net",
      "PaymentGatewayId": 1,
      "Url": "http://www.authorize.net"
    },
    {
      "Name": "Verisign PayFlow Pro",
      "PaymentGatewayId": 2,
      "Url": "http://www.verisign.com"
    },
    {
      "Name": "Paymentech Orbital",
      "PaymentGatewayId": 3,
      "Url": "http://www.paymentech.com"
    },
    {
      "Name": "PayPal Direct Payment",
      "PaymentGatewayId": 4,
      "Url": "http://www.paypal.com"
    },
    {
      "Name": "WorldPay",
      "PaymentGatewayId": 5,
      "Url": "http://www.worldpay.com"
    },
    {
      "Name": "CyberSource",
      "PaymentGatewayId": 6,
      "Url": "http://www.cybersource.com"
    },
    {
      "Name": "Custom",
      "PaymentGatewayId": 7,
      "Url": "NA"
    }
  ],
  "PageIndex": null,
  "PageSize": null,
  "TotalPages": null,
  "TotalResults": null,
  "ErrorCode": null,
  "ErrorMessage": null,
  "HasError": false
}

So while not a mission critical piece of the Znode API, the indent parameter is very useful for those times when you just need to see an endpoint response in a browser.