{"id":3225,"date":"2012-08-07T10:00:47","date_gmt":"2012-08-07T10:00:47","guid":{"rendered":"https:\/\/www.gosquared.com\/blog\/?p=3225"},"modified":"2019-11-28T12:40:33","modified_gmt":"2019-11-28T12:40:33","slug":"all-new-api-v2","status":"publish","type":"post","link":"https:\/\/www.gosquared.com\/blog\/all-new-api-v2","title":{"rendered":"All new: API v2"},"content":{"rendered":"<p><img decoding=\"async\" src=\"\/\/static.gosquared.com\/images\/liquidicity\/12_08_06_api_01.jpg\" alt=\"Introducing the all new GoSquared API - real-time analytics data for your apps\"\/><\/p>\n<p>Today we&#8217;re delighted to announce the public launch of <a href=\"https:\/\/www.gosquared.com\/developer\/\" target=\"_blank\" rel=\"noopener noreferrer\">API v2<\/a> beta. We&#8217;ve rebuilt the whole API from the ground up, taking into account all of the experience, experimentation and feedback we gained from the first version. The result is a high quality API which is even more powerful than its predecessor.<\/p>\n<h2>Fresh documentation<\/h2>\n<p>We believe the most important part of an API is its documentation. We&#8217;ve created a shiny new <a href=\"https:\/\/www.gosquared.com\/developer\/\" target=\"_blank\" rel=\"noopener noreferrer\">documentation site<\/a> for both the <a href=\"https:\/\/www.gosquared.com\/developer\/latest\/\" target=\"_blank\" rel=\"noopener noreferrer\">latest<\/a> beta version and the original <a href=\"https:\/\/www.gosquared.com\/developer\/v1\/\" target=\"_blank\" rel=\"noopener noreferrer\">API v1<\/a>. One of the best things about this new documentation is the live examples, where you can enter your API key, select one of your sites, and play around with all of the API functions and parameters using real data for your site. Besides this, the documentation is generally much cleaner and more descriptive.<\/p>\n<h2>Fully RESTful<\/h2>\n<p>API v2 follows <a href=\"http:\/\/en.wikipedia.org\/wiki\/Representational_state_transfer\" target=\"_blank\" rel=\"noopener noreferrer\">REST<\/a>ful design principles, offering a rich HTTP query model supporting HTTP POST\/GET\/PUT\/DELETE methods invoking CREATE\/READ\/UPDATE\/DELETE resource operations.<\/p>\n<h2>Response formats<\/h2>\n<p>The default response format is JSON. The API can also respond with JSONP if given the &#8216;callback&#8217; query string parameter, and CSV for supported functions (e.g. <a href=\"https:\/\/www.gosquared.com\/developer\/latest\/timeSeries\" target=\"_blank\" rel=\"noopener noreferrer\">timeSeries<\/a>).<\/p>\n<h2>Logical response data<\/h2>\n<p>We&#8217;ve changed the default response structure of JSON data to be more representative of its actual content. For examples, when you request the <a href=\"https:\/\/www.gosquared.com\/developer\/latest\/pages\/\" target=\"_blank\" rel=\"noopener noreferrer\">pages<\/a> function to obtain a list of currently active content, you get back an array of objects, one for each page. Additionally, in contrast to API v1, the response data is no longer nested in a property.<\/p>\n<h2>Presenters<\/h2>\n<p>Occasionally you might want the response data to be structured differently for convenience in your app. Some functions have presenters which can adapt the structure of the response data. For example, a plain GET request to the <a href=\"https:\/\/www.gosquared.com\/developer\/latest\/referrers\/\" target=\"_blank\" rel=\"noopener noreferrer\">referrers<\/a> function will send back an array list of unique referring URLs, but if you also supply the &#038;presenter=groupByDomain query string parameter, the function will respond with a list of objects that in turn contain a list of referring URLs from a common domain. <\/p>\n<p>If you desire a particular response structure but the API function doesn&#8217;t yet support it, <a href=\"https:\/\/www.gosquared.com\/contact\/\" target=\"_blank\" rel=\"noopener noreferrer\">get in touch<\/a> with your idea and we can implement it.<\/p>\n<h2>Combining functions<\/h2>\n<p>Multiple functions can be <a href=\"https:\/\/www.gosquared.com\/developer\/latest\/combining-functions\/\" target=\"_blank\" rel=\"noopener noreferrer\">combined<\/a> into a single HTTP request, so that the response contains data from each function grouped into a single response. Each function&#8217;s data is keyed by the function name. <\/p>\n<p>Grouping the response data in this way helps cut down on the number of HTTP requests your app needs to perform, saving on bandwidth and cumulative load time, which is particularly important on mobile devices.<\/p>\n<h2>Error handling for humans<\/h2>\n<p>API v1 was a little hostile when it came to errors. It got embarrassed when it encountered an issue and didn&#8217;t offer you much insight into what happened or how to rectify the problem.<\/p>\n<p>The new API is much more approachable in an error situation. If something goes wrong, you&#8217;ll get a non-200 HTTP response status code. The code will give you an idea of whose fault the problem was. You&#8217;ll get a 4xx error if you did something wrong, or a 5xx error if the API is to blame. <\/p>\n<p>Further to this, the data in the body of an error response will contain an additional error code, along with a message. You can look up the code using the <a href=\"https:\/\/www.gosquared.com\/developer\/latest\/error-codes\/\" target=\"_blank\" rel=\"noopener noreferrer\">error code reference<\/a>, or there may be more information about the error code on the function&#8217;s documentation page. For a 4xx error, the error message tries to be as descriptive as possible to help you identify where you went wrong when making the request.<\/p>\n<p>If any component function of a combination request encounters an error, its response data will contain information about the error, without affecting any of the other functions.<\/p>\n<h2>Stability and versioning<\/h2>\n<p>For the duration of an API version being in an alpha or beta stage, it will be labelled with the version &#8216;latest&#8217;. At time of writing, API v2 is in beta, and is therefore the current &#8216;latest&#8217; version. When the latest version reaches a mature state, it will be locked down to patches only and released with a v&lt;number&gt; label.<\/p>\n<p>Individual functions also have their own stability status. This allows us to release cutting-edge functionality to developers as soon as we craft it.<\/p>\n<p>We will be maintaining API v1 for some time longer, but it will eventually be deprecated. We will endeavour to give plenty of notice before this happens. Nonetheless, we strongly encourage developers to build on API v2 and above.<\/p>\n<h2>The API is for you<\/h2>\n<p>We&#8217;ve lovingly put all of this together for you. Therefore, what you think is of huge importance to us. Having problems? Something you love? Something you hate? You have to <a href=\"https:\/\/www.gosquared.com\/contact\/\" target=\"_blank\" rel=\"noopener noreferrer\">let us know<\/a>. You&#8217;ll be helping make the experience as great as possible for all, and we always take your feedback into account.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we&#8217;re delighted to announce the public launch of API v2 beta. We&#8217;ve rebuilt the whole API from the ground&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1452],"tags":[96,101,254,561,771,844],"class_list":["post-3225","post","type-post","status-publish","format-standard","hentry","category-engineering","tag-analytics","tag-api","tag-data","tag-live","tag-rest","tag-stats"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v18.6 (Yoast SEO v19.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>All new: API v2 - GoSquared Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.gosquared.com\/blog\/all-new-api-v2\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"All new: API v2\" \/>\n<meta property=\"og:description\" content=\"Today we&#8217;re delighted to announce the public launch of API v2 beta. We&#8217;ve rebuilt the whole API from the ground...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.gosquared.com\/blog\/all-new-api-v2\" \/>\n<meta property=\"og:site_name\" content=\"GoSquared Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GoSquared\" \/>\n<meta property=\"article:published_time\" content=\"2012-08-07T10:00:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-11-28T12:40:33+00:00\" \/>\n<meta property=\"og:image\" content=\"\/\/static.gosquared.com\/images\/liquidicity\/12_08_06_api_01.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@TheDeveloper\" \/>\n<meta name=\"twitter:site\" content=\"@GoSquared\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Geoff Wagstaff\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/#organization\",\"name\":\"GoSquared\",\"url\":\"https:\/\/www.gosquared.com\/blog\/\",\"sameAs\":[\"https:\/\/instagram.com\/gosquaredteam\",\"https:\/\/www.linkedin.com\/company\/go-squared-ltd.\",\"https:\/\/www.facebook.com\/GoSquared\",\"https:\/\/twitter.com\/GoSquared\"],\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.gosquared.com\/blog\/wp-content\/uploads\/2015\/07\/gosquared.png\",\"contentUrl\":\"https:\/\/www.gosquared.com\/blog\/wp-content\/uploads\/2015\/07\/gosquared.png\",\"width\":1270,\"height\":250,\"caption\":\"GoSquared\"},\"image\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/#website\",\"url\":\"https:\/\/www.gosquared.com\/blog\/\",\"name\":\"GoSquared Blog\",\"description\":\"Turn visitors into customers.\",\"publisher\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.gosquared.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/all-new-api-v2#webpage\",\"url\":\"https:\/\/www.gosquared.com\/blog\/all-new-api-v2\",\"name\":\"All new: API v2 - GoSquared Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/#website\"},\"datePublished\":\"2012-08-07T10:00:47+00:00\",\"dateModified\":\"2019-11-28T12:40:33+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/all-new-api-v2#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.gosquared.com\/blog\/all-new-api-v2\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/all-new-api-v2#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.gosquared.com\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"All new: API v2\"}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/all-new-api-v2#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/all-new-api-v2#webpage\"},\"author\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/56a3341790c8a0603f96066fb8d42448\"},\"headline\":\"All new: API v2\",\"datePublished\":\"2012-08-07T10:00:47+00:00\",\"dateModified\":\"2019-11-28T12:40:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/all-new-api-v2#webpage\"},\"wordCount\":822,\"publisher\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/#organization\"},\"keywords\":[\"Analytics\",\"API\",\"Data\",\"Live\",\"REST\",\"Stats\"],\"articleSection\":[\"Engineering\"],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/56a3341790c8a0603f96066fb8d42448\",\"name\":\"Geoff Wagstaff\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/66792d2e4d04406697b9a5f322664691590a386bc15b7146d143bbca07aa8889?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/66792d2e4d04406697b9a5f322664691590a386bc15b7146d143bbca07aa8889?s=96&d=mm&r=g\",\"caption\":\"Geoff Wagstaff\"},\"sameAs\":[\"https:\/\/twitter.com\/TheDeveloper\"],\"url\":\"https:\/\/www.gosquared.com\/blog\/author\/echo\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"All new: API v2 - GoSquared Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.gosquared.com\/blog\/all-new-api-v2","og_locale":"en_US","og_type":"article","og_title":"All new: API v2","og_description":"Today we&#8217;re delighted to announce the public launch of API v2 beta. We&#8217;ve rebuilt the whole API from the ground...","og_url":"https:\/\/www.gosquared.com\/blog\/all-new-api-v2","og_site_name":"GoSquared Blog","article_publisher":"https:\/\/www.facebook.com\/GoSquared","article_published_time":"2012-08-07T10:00:47+00:00","article_modified_time":"2019-11-28T12:40:33+00:00","og_image":[{"url":"\/\/static.gosquared.com\/images\/liquidicity\/12_08_06_api_01.jpg"}],"twitter_card":"summary_large_image","twitter_creator":"@TheDeveloper","twitter_site":"@GoSquared","twitter_misc":{"Written by":"Geoff Wagstaff","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/www.gosquared.com\/blog\/#organization","name":"GoSquared","url":"https:\/\/www.gosquared.com\/blog\/","sameAs":["https:\/\/instagram.com\/gosquaredteam","https:\/\/www.linkedin.com\/company\/go-squared-ltd.","https:\/\/www.facebook.com\/GoSquared","https:\/\/twitter.com\/GoSquared"],"logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.gosquared.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.gosquared.com\/blog\/wp-content\/uploads\/2015\/07\/gosquared.png","contentUrl":"https:\/\/www.gosquared.com\/blog\/wp-content\/uploads\/2015\/07\/gosquared.png","width":1270,"height":250,"caption":"GoSquared"},"image":{"@id":"https:\/\/www.gosquared.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"WebSite","@id":"https:\/\/www.gosquared.com\/blog\/#website","url":"https:\/\/www.gosquared.com\/blog\/","name":"GoSquared Blog","description":"Turn visitors into customers.","publisher":{"@id":"https:\/\/www.gosquared.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.gosquared.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.gosquared.com\/blog\/all-new-api-v2#webpage","url":"https:\/\/www.gosquared.com\/blog\/all-new-api-v2","name":"All new: API v2 - GoSquared Blog","isPartOf":{"@id":"https:\/\/www.gosquared.com\/blog\/#website"},"datePublished":"2012-08-07T10:00:47+00:00","dateModified":"2019-11-28T12:40:33+00:00","breadcrumb":{"@id":"https:\/\/www.gosquared.com\/blog\/all-new-api-v2#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.gosquared.com\/blog\/all-new-api-v2"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.gosquared.com\/blog\/all-new-api-v2#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.gosquared.com\/blog"},{"@type":"ListItem","position":2,"name":"All new: API v2"}]},{"@type":"Article","@id":"https:\/\/www.gosquared.com\/blog\/all-new-api-v2#article","isPartOf":{"@id":"https:\/\/www.gosquared.com\/blog\/all-new-api-v2#webpage"},"author":{"@id":"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/56a3341790c8a0603f96066fb8d42448"},"headline":"All new: API v2","datePublished":"2012-08-07T10:00:47+00:00","dateModified":"2019-11-28T12:40:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.gosquared.com\/blog\/all-new-api-v2#webpage"},"wordCount":822,"publisher":{"@id":"https:\/\/www.gosquared.com\/blog\/#organization"},"keywords":["Analytics","API","Data","Live","REST","Stats"],"articleSection":["Engineering"],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/56a3341790c8a0603f96066fb8d42448","name":"Geoff Wagstaff","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/66792d2e4d04406697b9a5f322664691590a386bc15b7146d143bbca07aa8889?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/66792d2e4d04406697b9a5f322664691590a386bc15b7146d143bbca07aa8889?s=96&d=mm&r=g","caption":"Geoff Wagstaff"},"sameAs":["https:\/\/twitter.com\/TheDeveloper"],"url":"https:\/\/www.gosquared.com\/blog\/author\/echo"}]}},"wps_subtitle":"","_links":{"self":[{"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/posts\/3225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/comments?post=3225"}],"version-history":[{"count":0,"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/posts\/3225\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/media?parent=3225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/categories?post=3225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/tags?post=3225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}