Formatting spreadsheets is accomplished by creating a set of request commands in the form of JSON payloads, and sending them to the API. Here is a sample JavaScript Object made up of an array of requests (only one this time) to bold the first row of the default Sheet automatically created for you (whose ID is 0):
{"requests": [ {"repeatCell": { "range": { "sheetId": 0, "startRowIndex": 0, "endRowIndex": 1 }, "cell": { "userEnteredFormat": { "textFormat": { "bold": true } } }, "fields": "userEnteredFormat.textFormat.bold" }} ]}
SHEETS.spreadsheets().batchUpdate(spreadsheetId=SHEET_ID, body=requests).execute()
For more details on the code in the video, check out the deepdive blog post. As you can probably guess, the key challenge is in constructing the JSON payload to send to API calls—the common operations samples can really help you with this. You can also check out our JavaScript codelab where we guide you through writing a Node.js app that manages customer orders for a toy company, featuring the toy orders data we looked at today but in a relational database. While the resulting equivalent Sheet is featured prominently in today's video, we will revisit it again in an upcoming episode showing you how to generate slides with spreadsheet data using the new Google Slides API, so stay tuned for that!
We hope all these resources help developers enhance their next app using G Suite APIs! Please subscribe to our channel and tell us what topics you would like to see in other episodes of the G Suite Dev Show!
Posted by Wesley Chun (@wescpy), Developer Advocate, Google Apps
At Google I/O 2016, we launched a new Google Sheets API—click here to watch the entire announcement. The updated API includes many new features that weren’t available in previous versions, including access to functionality found in the Sheets desktop and mobile user interfaces. My latest DevByte video shows developers how to get data into and out of a Google Sheet programmatically, walking through a simple script that reads rows out of a relational database and transferring the data to a brand new Google Sheet.
Let’s take a sneak peek of the code covered in the video. Assuming that SHEETS has been established as the API service endpoint, SHEET_ID is the ID of the Sheet to write to, and data is an array with all the database rows, this is the only call developers need to make to write that raw data into the Sheet:
SHEETS
SHEET_ID
data
SHEETS.spreadsheets().values().update(spreadsheetId=SHEET_ID, range='A1', body=data, valueInputOption='RAW').execute()
rows = SHEETS.spreadsheets().values().get(spreadsheetId=SHEET_ID, range='Sheet1').execute().get('values', []) for row in rows: print(row)
If you’re ready to get started, take a look at the Python or other quickstarts in a variety of languages before checking out the DevByte. If you want a deeper dive into the code covered in the video, check out the post at my Python blog. Once you get going with the API, one of the challenges developers face is in constructing the JSON payload to send in API calls—the common operations samples can really help you with this. Finally, if you’re ready to get going with a meatier example, check out our JavaScript codelab where you’ll write a sample Node.js app that manages customer orders for a toy company, the database of which is used in this DevByte, preparing you for the codelab.
We hope all these resources help developers create amazing applications and awesome tools with the new Google Sheets API! Please subscribe to our channel, give us your feedback below, and tell us what topics you would like to see in future episodes!
Posted by Israel Shalom, Product Manager
Every day, hundreds of thousands of developers send millions of requests to Google APIs, from Maps to YouTube. Thousands of developers visit the console for credentials, quota, and more -- and we want to give them a better and more streamlined experience.
Starting today, we’ll gradually roll out the API Console at console.developers.google.com focusing entirely on your Google API experience. There, you’ll find a significantly cleaner, simpler interface: instead of 20+ sections in the navigation bar, you’ll see API Manager, Billing and Permissions only:
console.cloud.google.com will remain unchanged. It’ll point to Cloud console, which includes the entire suite of Google Cloud Platform services, just like before. And while the two are different destinations, your underlying resources remain the same: projects created on Cloud Console will still be accessible on API Console, and vice versa.
The purpose of the new API Console is to let you complete common API-related tasks quickly. For instance, we know that once you enable an API in a new project, the next step is usually to create credentials. That’s why we’ve built the credentials wizard: a quick and convenient way for you to figure out what kind of credentials you need, and add them right after enabling an API:
Over time, we will continue to tailor the API Console experience for the many developers out there who use Google’s APIs. So if you’re one of these users, we encourage you to try out API Console and use the feedback button to let us know what you think!
Originally posted to the Google Apps Developer blog
Posted by Edward Jones, Software Engineer, Google Apps Script and Wesley Chun, Developer Advocate, Google Apps
Have you ever wanted a server API that modifies cells in a Google Sheet, to execute a Google Apps Script app from outside of Google Apps, or a way to use Apps Script as an API platform? Today, we’re excited to announce you can do all that and more with the Google Apps Script Execution API.
The Execution API allows developers to execute scripts from any client (browser, server, mobile, or any device). You provide the authorization, and the Execution API will run your script. If you’re new to Apps Script, it’s simply JavaScript code hosted in the cloud that can access authorized Google Apps data using the same technology that powers add-ons. The Execution API extends the ability to execute Apps Script code and unlocks the power of Docs, Sheets, Forms, and other supported services for developers.
One of our launch partners, Pear Deck, used the new API to create an interactive presentation tool that connects students to teachers by converting slide decks into interactive experiences. Their app calls the Execution API to automatically generate a Google Doc customized for each student, so everyone gets a personalized set of notes from the presentation. Without the use of Apps Script, their app would be limited to using PDFs and other static file types. Check out the video below to see how it works.
Bruce McPherson, a Google Developer Expert (GDE) for Google Apps, says: “The Execution API is a great tool for enabling what I call ‘incremental transition’ from Microsoft Office (and VBA) to Apps (and Apps Script). A mature Office workflow may involve a number of processes currently orchestrated by VBA, with data in various formats and locations. It can be a challenge to move an entire workload in one step, especially an automated process with many moving parts. This new capability enables the migration of data and process in manageable chunks.” You can find some of Bruce’s sample migration code using the Execution API here.
The Google Apps Script Execution API is live and ready for you to use today. To get started, check out the developer documentation and quickstarts. We invite you to show us what you build with the Execution API!
[[GPPShare sharedInstance] shareDialog]
[[GPPShare sharedInstance] nativeShareDialog]
<script type="text/javascript"> // The API developer key obtained from the Google APIs Console. var developerKey = 'ABC123 ... '; // Use the API Loader script to load google.picker. function loadPicker() { gapi.load('picker', {'callback': createPicker}); } // Create and render a Picker object for searching images. function createPicker() { var picker = new google.picker.PickerBuilder(). addView(google.picker.ViewId.IMAGE_SEARCH). setDeveloperKey(developerKey). setCallback(pickerCallback). build(); picker.setVisible(true); } </script> <script type="text/javascript" src="https://apis.google.com/js/api.js?onload=loadPicker"> </script>
Google Analytics users can use the Core Reporting API to save time by building dashboards and automating complex reporting tasks. This API exposes over 250 data points (dimensions and metrics), and new data is added every few months. For many developers, it can be difficult to keep their applications up to date with all the latest data.
To make things easier, today we are launching the new Google Analytics Metadata API to simplify data discovery. The Metadata API contains all the queryable dimensions and metrics included in the Core Reporting API. We’ve also added attributes for each dimension and metric, such as the web or app name, full text description, grouping, metric calculations, deprecation status, and whether the data is queryable in segments. You can check out at a live Metadata API response here.
You now have programmatic access to generate the same list of dimensions and metrics we use to generate our public documentation.
When you create tools to query the Core Reporting API, you can use the Metadata API to automatically update your user interfaces. For example, Analytics Canvas, a popular third-party Google Analytics data extraction tool, uses the Metadata API to keep its query building interface up to date.
According to James Standen, founder of Analytics Canvas, "In the past, keeping Analytics Canvas up to date with the Google Analytics API dimensions and metrics required a lot of manual updating to our application. The new Metadata API automates this process, saving us time, and giving our users direct access to all the great new data the instant it's available. Users love it!"
To increase data transparency, we’ve also published a new data deprecation policy for dimensions and metrics. New data we release will be announced on our changelogs and automatically added to the Metadata API. Data we decide to remove will be marked as deprecated in the Metadata API, allowing developers to gracefully remove these values from their tools.
Our goal was to make this API super easy to use. To get started, take a look at our resources:
Questions? Comments? Simply want to share in the excitement? Join the analytics developer community in our Reporting API Developer forum.
Map<String, String> params = new HashMap<String, String>(); Channel request = new Channel() .setId("unique_subscription_ID") .setType("web_hook") .setAddress(String.format("https://my-host.com/notification")) .setParams(params); service.events().watch("my_calendar@my-host.com", request).execute();
changes = service.events().list("my_calendar@my-host.com") .setUpdatedMin(lastSynchonizationTime).execute();
Over the past year we’ve added many new features to Google Analytics. Today we are releasing all of this data in the Core Reporting API.
We're most excited about the ability to query for custom dimensions and metrics using the API.
Developers can use custom dimensions to send unique IDs into Google Analytics, and then use the core reporting API to retrieve these IDs along with other Google Analytics data.
For example, your content management system can pass a content ID as a custom dimension using the Google Analytics tracking code. Developers can then use the API to get a list of the most popular content by ID and display the list of most popular content on their website.
We've added more mobile dimensions and metrics, including those found in the Mobile App Analytics reports:
Some examples of questions this new data can answer are:
If you are sending Google Analytics multiple currencies, you now have the ability to access the local currency of the transactions with this new data:
We added new time-based dimensions to simplify working with reporting data:
Sample queries:
Finally, we've added two new traffic source dimensions, including one to return the full URL of the referral.
Sample query: the top 10 referrers based on visits (using full referrer).
For a complete list of the new data, take a look at the Core Reporting API changelog. For all the data definitions, check the Core Reporting API Dimensions and Metrics explorer. As always, you can check out this new data directly within our Query Explorer tool.