{"__v":16,"_id":"576d7bb179f35917002dc046","category":{"__v":6,"_id":"563a4fcaa19edf0d00972321","pages":["563a50051846790d0089535e","564ba1cf5cc43717009bcfe9","565a60d433140c0d0033930c","5673222e47f7010d005bfd7c","56afd2f5d21e9c0d00b62962","56be2bff6cae110d00190c05"],"project":"55773a5ba042551900b002cb","version":"55773a5ba042551900b002ce","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-11-04T18:34:50.832Z","from_sync":false,"order":1,"slug":"guides","title":"Guides"},"parentDoc":null,"project":"55773a5ba042551900b002cb","user":"546d17e2eb9cfd1400dd4529","version":{"__v":17,"_id":"55773a5ba042551900b002ce","project":"55773a5ba042551900b002cb","createdAt":"2015-06-09T19:11:23.764Z","releaseDate":"2015-06-09T19:11:23.764Z","categories":["55773a5ca042551900b002cf","55773a6ce6063e0d00481380","55773ab007e7110d001043ec","55773abaa042551900b002d5","55773ac207e7110d001043ed","55773acb07e7110d001043ee","55773ad3a042551900b002d6","55773adce6063e0d00481383","55773ae4a042551900b002d7","55773af307e7110d001043ef","55773af907e7110d001043f0","55773b0407e7110d001043f1","563a4f7ad25e8919005f3f39","563a4fcaa19edf0d00972321","564a70dc4cd0521700523edf","564b797bcc472d0d00da9435","564b855b766d4923004e1fd1"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Motherboard","version_clean":"1.0.0","version":"1"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-06-24T18:28:01.762Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":7,"body":"The [Search API ](https://developers.triathlon.org/docs/search-api-overview) is the fastest and simplest way to access resources on the Triathlon.org API platform. The Search API is best suited for front-end applications where users are, for example, searching for events or athlete names as typos will be factored in when returning search results and custom ranking criteria are used to determine the most relevant results.\n\nLet's say for example we want to find any athletes named `Brownlee`. Using the Search API and the `athletes` collection we can conduct the following request:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl --header \\\"apikey: YOUR_APP_KEY\\\" \\\"https://api.triathlon.org/v1/search/athletes?query=brownlee\\\"\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nWhich will return an array of basic athlete objects. Results are ordered via custom ranking criteria but more weight will be placed on elite athletes.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n    \\\"code\\\": 200,\\n    \\\"status\\\": \\\"success\\\",\\n    \\\"total\\\": 16,\\n    \\\"per_page\\\": 10,\\n    \\\"current_page\\\": 1,\\n    \\\"last_page\\\": 2,\\n    \\\"next_page_url\\\": \\\"https://api.triathlon.org/v1/search?query=brownlee&collection=athletes&page=2\\\",\\n    \\\"prev_page_url\\\": null,\\n    \\\"from\\\": 1,\\n    \\\"to\\\": 10,\\n    \\\"data\\\": [\\n        {\\n            \\\"athlete_id\\\": 7788,\\n            \\\"athlete_title\\\": \\\"Alistair Brownlee\\\",\\n            \\\"athlete_slug\\\": \\\"alistair_brownlee\\\",\\n            \\\"athlete_first\\\": \\\"Alistair\\\",\\n            \\\"athlete_last\\\": \\\"Brownlee\\\",\\n            \\\"athlete_country_id\\\": 292,\\n            \\\"athlete_gender\\\": \\\"male\\\",\\n            \\\"athlete_yob\\\": \\\"1988\\\",\\n            \\\"validated\\\": false,\\n            \\\"athlete_profile_image\\\": \\\"http://www.triathlon.org/images/athlete_thumbs/Brownlee.png\\\",\\n            \\\"athlete_noc\\\": \\\"GBR\\\",\\n            \\\"athlete_country_name\\\": \\\"Great Britain\\\",\\n            \\\"athlete_country_isoa2\\\": \\\"GB\\\",\\n            \\\"athlete_listing\\\": \\\"http://www.triathlon.org/athletes/profile/7788/alistair_brownlee\\\",\\n            \\\"athlete_flag\\\": \\\"https://f9ca11ef49c28681fc01-0acbf57e00c47a50e70a1acb89e86c89.ssl.cf1.rackcdn.com/images/icons/gb.png\\\",\\n            \\\"athlete_api_listing\\\": \\\"https://api.triathlon.org/v1/v1/athletes/7788\\\",\\n            \\\"athlete_categories\\\": [\\n                42\\n            ]\\n        }\\n    ]\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nThe resulting list of 16 athletes that were returned contain both age-group athletes (defined as those without a points list ranking) as well as potential matches considering misspellings such as `Jody Brownley` though naturally they would be ranked lower in search results. \n\nThe Search API also allows for [additional filters](https://developers.triathlon.org/docs/search-api-overview#filters) to further restrict results, which for athletes are `athlete_country_name` and `athlete_gender`. So restricting to male Brownlees in Great Britain the following request would be made:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl --header \\\"apikey: YOUR_APP_KEY\\\" \\\"https://api.triathlon.org/v1/search/athletes?query=brownlee&filters=athlete_gender,male|athlete_country_name,Great Britain\\\"\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nOther collections i.e. videos or events have different filterable options with events for example in addition allowing filtering on dates and even [geolocation](https://developers.triathlon.org/docs/search-api-overview#geo-searching) to find nearest event etc... So the following request would return events within 250km of London,UK during 2015\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl --header \\\"apikey: YOUR_APP_KEY\\\" \\\"https://api.triathlon.org/v1/search/events?location=51.500152,-0.126236&distance=250&filters=year,2015\\\"\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"using-the-search-api","type":"basic","title":"Using the Search API"}

Using the Search API


The [Search API ](https://developers.triathlon.org/docs/search-api-overview) is the fastest and simplest way to access resources on the Triathlon.org API platform. The Search API is best suited for front-end applications where users are, for example, searching for events or athlete names as typos will be factored in when returning search results and custom ranking criteria are used to determine the most relevant results. Let's say for example we want to find any athletes named `Brownlee`. Using the Search API and the `athletes` collection we can conduct the following request: [block:code] { "codes": [ { "code": "curl --header \"apikey: YOUR_APP_KEY\" \"https://api.triathlon.org/v1/search/athletes?query=brownlee\"", "language": "curl" } ] } [/block] Which will return an array of basic athlete objects. Results are ordered via custom ranking criteria but more weight will be placed on elite athletes. [block:code] { "codes": [ { "code": "{\n \"code\": 200,\n \"status\": \"success\",\n \"total\": 16,\n \"per_page\": 10,\n \"current_page\": 1,\n \"last_page\": 2,\n \"next_page_url\": \"https://api.triathlon.org/v1/search?query=brownlee&collection=athletes&page=2\",\n \"prev_page_url\": null,\n \"from\": 1,\n \"to\": 10,\n \"data\": [\n {\n \"athlete_id\": 7788,\n \"athlete_title\": \"Alistair Brownlee\",\n \"athlete_slug\": \"alistair_brownlee\",\n \"athlete_first\": \"Alistair\",\n \"athlete_last\": \"Brownlee\",\n \"athlete_country_id\": 292,\n \"athlete_gender\": \"male\",\n \"athlete_yob\": \"1988\",\n \"validated\": false,\n \"athlete_profile_image\": \"http://www.triathlon.org/images/athlete_thumbs/Brownlee.png\",\n \"athlete_noc\": \"GBR\",\n \"athlete_country_name\": \"Great Britain\",\n \"athlete_country_isoa2\": \"GB\",\n \"athlete_listing\": \"http://www.triathlon.org/athletes/profile/7788/alistair_brownlee\",\n \"athlete_flag\": \"https://f9ca11ef49c28681fc01-0acbf57e00c47a50e70a1acb89e86c89.ssl.cf1.rackcdn.com/images/icons/gb.png\",\n \"athlete_api_listing\": \"https://api.triathlon.org/v1/v1/athletes/7788\",\n \"athlete_categories\": [\n 42\n ]\n }\n ]\n}", "language": "json" } ] } [/block] The resulting list of 16 athletes that were returned contain both age-group athletes (defined as those without a points list ranking) as well as potential matches considering misspellings such as `Jody Brownley` though naturally they would be ranked lower in search results. The Search API also allows for [additional filters](https://developers.triathlon.org/docs/search-api-overview#filters) to further restrict results, which for athletes are `athlete_country_name` and `athlete_gender`. So restricting to male Brownlees in Great Britain the following request would be made: [block:code] { "codes": [ { "code": "curl --header \"apikey: YOUR_APP_KEY\" \"https://api.triathlon.org/v1/search/athletes?query=brownlee&filters=athlete_gender,male|athlete_country_name,Great Britain\"", "language": "curl" } ] } [/block] Other collections i.e. videos or events have different filterable options with events for example in addition allowing filtering on dates and even [geolocation](https://developers.triathlon.org/docs/search-api-overview#geo-searching) to find nearest event etc... So the following request would return events within 250km of London,UK during 2015 [block:code] { "codes": [ { "code": "curl --header \"apikey: YOUR_APP_KEY\" \"https://api.triathlon.org/v1/search/events?location=51.500152,-0.126236&distance=250&filters=year,2015\"", "language": "curl" } ] } [/block]