{"_id":"54995fc70195cc0b00dc32df","githubsync":"","project":"54995cb59da9390b00cffac6","__v":10,"user":"54995c979da9390b00cffac5","version":{"_id":"54995cb59da9390b00cffac9","__v":3,"project":"54995cb59da9390b00cffac6","createdAt":"2014-12-23T12:14:45.422Z","releaseDate":"2014-12-23T12:14:45.422Z","categories":["54995cb59da9390b00cffaca","54995e289da9390b00cffad0","5499610f0195cc0b00dc32e2"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"54995cb59da9390b00cffaca","pages":["54995cb69da9390b00cffacc","54995f2c9da9390b00cffad1","54995fc70195cc0b00dc32df","54a1580cce33cf1600c2334d"],"version":"54995cb59da9390b00cffac9","__v":4,"project":"54995cb59da9390b00cffac6","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-12-23T12:14:45.902Z","from_sync":false,"order":0,"slug":"documentation","title":"Documentation"},"metadata":{"title":"","description":"","image":[]},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2014-12-23T12:27:51.036Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"## Common types\n\nAll dates are expressed as [UNIX timestamps](http://en.wikipedia.org/wiki/Unix_time), with the exception of timetable times, which are shown in `H:MM` format (e.g. 4:32, 15:12. 24:06).\n\nLatitude and longitude will be expressed as floats, with the precision on both the request and response up to six decimal places.\n\n## CORS (Cross-domain resource sharing)\n\nThe TFE Open Data API supports CORS for communicating from Javascript. Please note that your API token is still considered sensitive and it is your responsibility to protect it.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var xhr = new XMLHttpRequest();\\nxhr.setRequestHeader(\\\"Authorization\\\", \\\"Token YOUR_SERVER_TOKEN\\\");\\nxhr.open('GET', 'https://tfe-opendata.com/api/v1/timetables/36235979');\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n## HTTP Status Codes\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Status code\",\n    \"h-1\": \"Description\",\n    \"0-0\": \"**200**\",\n    \"1-0\": \"**400**\",\n    \"2-0\": \"**401**\",\n    \"3-0\": \"**403**\",\n    \"4-0\": \"**404**\",\n    \"5-0\": \"**406**\",\n    \"6-0\": \"**422**\",\n    \"7-0\": \"**429**\",\n    \"8-0\": \"**500**\",\n    \"0-1\": \"OK. Everything worked as expected.\",\n    \"1-1\": \"Malformed request.\",\n    \"2-1\": \"Unauthorized the request requires user authentication (not logged in).\",\n    \"3-1\": \"Forbidden. Also used for unauthorized requests or permissions issues.\",\n    \"4-1\": \"Not found.\",\n    \"5-1\": \"Unacceptable content type. Client sent an accepts header for a content type which does not exist on the server. Body includes a list of acceptable content types, such as “Unacceptable content type. Request resource as: application/json\",\n    \"6-1\": \"Invalid request. The request body is parse-able however with invalid content.\",\n    \"7-1\": \"Too Many Requests. Rate limited.\",\n    \"8-1\": \"Internal Server Error.\"\n  },\n  \"cols\": 2,\n  \"rows\": 9\n}\n[/block]\n## Errors\n\nError responses will have a consistently formed JSON body. The keys may include:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Key\",\n    \"h-1\": \"Value\",\n    \"0-0\": \"`message`\",\n    \"1-0\": \"`code`\",\n    \"2-0\": \"`fields` (optional)\",\n    \"0-1\": \"Human readable message which corresponds to the client error.\",\n    \"1-1\": \"One-word error code\",\n    \"2-1\": \"A hash of field names that have validations. This has a value of an array with member strings that describe the specific validation error.\"\n  },\n  \"cols\": 2,\n  \"rows\": 3\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"message\\\": \\\"Invalid stop ID\\\",\\n  \\\"code\\\": \\\"invalid\\\",\\n  \\\"fields\\\": {\\n    \\\"stop_id\\\": [\\\"Required\\\"]\\n  }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"request-and-response","type":"basic","title":"Request and Response"}

Request and Response


## Common types All dates are expressed as [UNIX timestamps](http://en.wikipedia.org/wiki/Unix_time), with the exception of timetable times, which are shown in `H:MM` format (e.g. 4:32, 15:12. 24:06). Latitude and longitude will be expressed as floats, with the precision on both the request and response up to six decimal places. ## CORS (Cross-domain resource sharing) The TFE Open Data API supports CORS for communicating from Javascript. Please note that your API token is still considered sensitive and it is your responsibility to protect it. [block:code] { "codes": [ { "code": "var xhr = new XMLHttpRequest();\nxhr.setRequestHeader(\"Authorization\", \"Token YOUR_SERVER_TOKEN\");\nxhr.open('GET', 'https://tfe-opendata.com/api/v1/timetables/36235979');", "language": "javascript" } ] } [/block] ## HTTP Status Codes [block:parameters] { "data": { "h-0": "Status code", "h-1": "Description", "0-0": "**200**", "1-0": "**400**", "2-0": "**401**", "3-0": "**403**", "4-0": "**404**", "5-0": "**406**", "6-0": "**422**", "7-0": "**429**", "8-0": "**500**", "0-1": "OK. Everything worked as expected.", "1-1": "Malformed request.", "2-1": "Unauthorized the request requires user authentication (not logged in).", "3-1": "Forbidden. Also used for unauthorized requests or permissions issues.", "4-1": "Not found.", "5-1": "Unacceptable content type. Client sent an accepts header for a content type which does not exist on the server. Body includes a list of acceptable content types, such as “Unacceptable content type. Request resource as: application/json", "6-1": "Invalid request. The request body is parse-able however with invalid content.", "7-1": "Too Many Requests. Rate limited.", "8-1": "Internal Server Error." }, "cols": 2, "rows": 9 } [/block] ## Errors Error responses will have a consistently formed JSON body. The keys may include: [block:parameters] { "data": { "h-0": "Key", "h-1": "Value", "0-0": "`message`", "1-0": "`code`", "2-0": "`fields` (optional)", "0-1": "Human readable message which corresponds to the client error.", "1-1": "One-word error code", "2-1": "A hash of field names that have validations. This has a value of an array with member strings that describe the specific validation error." }, "cols": 2, "rows": 3 } [/block] [block:code] { "codes": [ { "code": "{\n \"message\": \"Invalid stop ID\",\n \"code\": \"invalid\",\n \"fields\": {\n \"stop_id\": [\"Required\"]\n }\n}", "language": "json" } ] } [/block]