[MUSIC PLAYING] MAURICE CODIK: Good morning, everybody My name is Maurice YASH SAINI: And I’m Yash MAURICE CODIK: And we’re engineers that work on the APIs for the G Suite Editors, Docs, Sheets, and Slides And in this session, we’re going to do a deep dive on two end-to-end scenarios we built using these APIs and show you how you can build on the Docs editors So we’re going to be going through a lot of code It’s OK if you don’t follow every single line We’re going to give you links to documentation and links for you to get the code after the session But the goal of the session is to give you a taste of what a real life integration using the Docs Editors looks like, and hopefully give you some inspiration so you can go home and build your own integration So we’re going to hit on some of the things that we’ve built in the past year and also give you a sneak peek of some of the new things we’re currently working on So what are these APIs, what platforms do they run on? So the first platform we’ll talk about is Apps Script Apps Script is a JavaScript-based open platform that is built into G Suite My favorite part about Apps Script is really how easy it is to use There’s 40-plus apps and services built in It handles authentication for you It runs in the cloud It’s very easy to write a few lines of code, get data from a spreadsheet, put it into a presentation, move it around, add custom UI into Docs, Sheets, and Slides It’s an extremely productive framework and it’s really easy to get started The other types of APIs we offer are REST APIs We have two public REST APIs available today One is for Sheets The other is for Slides Yesterday we announced a developer preview of a REST APIs for Docs And we’ll show you a little bit more about that later So these REST APIs are great for server to server interactions So for example, if you have a web app internally that talks to a legacy data store, you can add an Export to Sheets button on that web app, and your code can hit your legacy on-prem data store and push that data into Sheets And it’s much easier for users to work with than having to download a CSV and upload it again into Sheets So these REST APIs bring the Docs Editors to your applications Whereas Apps Script is very well suited to bring your applications into the G Suite Editors So what do these platforms mean for your business? We know that knowledge workers spend a lot of time getting data from data sources, formatting them, uploading them somewhere else, and getting them ready for analysis And with the REST APIs in Apps Script, you have a toolkit that lets you automate a lot of those tedious workflows and let people focus on things that actually matter and add value So here’s a quote from one of our G Suite customers, Whirlpool And you can tell how pumped up he is about Apps Script and how easy it is to use and how quickly they can get valuable things out of it And hopefully after this talk and you see some Apps Script examples, hopefully you’ll be equally as pumped as Daniel is about building with Apps Script So with that background, I’d like to start going through our samples and showing you what an actual Apps Script integration looks like So for this first sample, we’re going to go through a simple invoicing workflow So let’s say your company uses Salesforce to keep track of how much customers said they will pay And it’s been a quarter since then, and now you want to find out how much they’ve actually paid you, and if there’s a difference, send them a gentle reminder with an invoice from Google Docs So I’ll switch to the demo OK, so the first thing we’ll do is that we have to figure out how much our customers actually have paid us in the past quarter So earlier at the conference, we’ve talked about a new native integration between Google Sheets and BigQuery And I’ll use that here to get the received payments from BigQuery So I’ll show you quickly the query that I ran I’m getting the accounts and the sum of the paid amounts in Q1 of this year, grouping and ordering And if I ran this query, it would generate a spreadsheet just like this with the accounts and the amounts that the customers have paid us So that’s step one The next step is let’s go to Salesforce and find how much they said they would pay So we compare the two numbers and then generate some invoices So to talk to Salesforce, I wrote a Sheets add-on An add-on is a way for you to write Apps Script and publish it to others so others can install it and use it in their spreadsheets or docs or presentations

So you can write add-ons and publish them privately into your domain or you can publish them externally as well So when you run an add-on, you get this entry in the Add-ons menu that your script creates And let’s get started, we’re going to sign into Salesforce So I click on that button The first thing it asks me to do is actually go through the Salesforce OAuth flow The script popped up the modal dialog It gave me a link to sign in I click on that We get the Salesforce OAuth page I sign in And then if you’re familiar with OAuth, the way it works is you get sent to a sign-in page You complete authentication, then you get redirected back with some tokens in the URL that you can then use to authenticate with the API that the OAuth page serves So here we’ve been redirected back from Salesforce And our Apps Script is saying success, we have the tokens, now we’re ready to go So before I get to showing you how we can actually call Salesforce, let me walk you through the things you’ve seen so far from the code perspective So the first thing you see is this onOpen function This is called every time an add-on is installed on a sheet and the sheet is opened by an end user This is commonly used to create menu items, and this is what I’m doing here You see I’m adding to the add-ons menu and I’m giving it the name of the menu item and the name of an Apps Script function that will be called when the user clicks on that menu item So the first one is this login function It grabs an instance of the Salesforce service And what this does is that I’m using an OAuth2 library It’s open source You can grab it off GitHub right here And it’s a really easy way to integrate Apps Script with public web APIs that use OAuth authentication So here I’m giving it the configuration it needs to talk to Salesforce So the login page, the URL to get tokens I’m giving it my client credentials And I’m giving it a callback that will be called to render that success page you saw earlier So this is what the callback looks like I get the request from the app framework, which is now serving regular web requests And I can give it– and based on that, I can say success or denied So that is the get Salesforce service and how that works The last part of the login flow was showing users that little dialogue that gave them the link to go to Salesforce I do that in this showLinkDialog method And this is an example of how to do very simple custom UI inside the Docs Editors using Apps Script So I’m using HTML service This lets me create templates inside of Apps Script and pass in data to them, and then render that template as a modal dialog using SpreadsheetApp showModalDialog The link dialog file is just plain HTML As you can see, there’s variables for the URL and the message that are displayed to users So that covers the code for the sign-in flow As you see, it doesn’t take a lot to get authenticated with a public API And now let’s actually call it and see what it does So I’m back in my spreadsheet And I close this out and I go back to the Add-ons menu And I want to run a query on Salesforce Salesforce has support for Salesforce Object Query Language queries, or SOQL It’s kind of like SQL, but works on Salesforce objects And if I managed my clipboard properly, it would have been there, but it’s not All right, so I pasted a simple SOQL query into the dialog I’m doing something very similar to the query I have in BigQuery I’m selecting all of my opportunities and the sum of their amounts, and I’m filtering by the ones that we have won and we have closed So I run this query, and now my Apps Script is hitting the Salesforce public API, getting the response back, and adding that as a new sheet in my spreadsheet So let’s walk through how that works It uses that same Salesforce service that I set up earlier to get the authentication tokens to make the request So before you do that, we have to ask the user for the query they want to run So again, we’re using some simple methods to get input from users now The SpreadsheetApp.getUI has a prompt method that I’m using that similar to JavaScript prompt, if you’re familiar with that End users paste in their queries We get it back And if they click OK, we go ahead and run the query itself So to run the query, we hit the Salesforce public API Here I’m using UrlFetchApp

UrlFetch is the way in Apps Script that you can hit any public web endpoint with it You just give it a URL and some parameters and headers, and you can hit any web URL you need So I’m telling it I want to run this query endpoint on the Salesforce REST API And I get back the query results as JSON, which I then parse and then put on the spreadsheet So that’s the method I’m calling here on line 58 I want to get my results And the rest of this method is taking those results that come back as a JSON object, then processing them so I can put them on the spreadsheet So I’m creating a 2D array in outputValues And I’m creating the grid that you see on my spreadsheet inside a 2D array And then I use the SpreadsheetApp API to get a range on the new sheet I just inserted of the same dimensions as the 2D array, and I pass the 2D array directly to Sheets so I can fill in those cells So you can also do this one cell at a time That’s fine too But when you’re dealing with larger data from a public API, you’ll get much better performance if you build up that 2D array and just pass it in one go OK, so we have our data from Salesforce It looks like this It doesn’t look like a great spreadsheet And I definitely don’t want to fumble around with a spreadsheet for 10 minutes here So we need to do our analysis We have to compare the numbers that we got from Salesforce with numbers we got from BigQuery earlier and see if there’s any differences in the amount of money we’ve been paid So to do that, I’m going to run a macro Macros are a new feature to Sheets that we launched earlier this year And they’re a great way to automate repetitive tasks and run them over and over again So obviously, this is a very useful feature if you’re doing manual things in a spreadsheet, but from a developer point of view, the best thing about macros is that they just generate regular Apps Script code that you can interact with and look at just like any other Apps Script So this is the macro that I just ran It grabs the active spreadsheet It does a bunch of stuff It resizes columns It sets number formats, it does a VLOOKUP It fills the cells down It adds some conditional formatting So there’s a lot of stuff going on here And the great thing about macros is that instead of you having to go through the Apps Script documentation and figuring out all those API calls you need to make to get your spreadsheet to look exactly like you want it, you can do it by hand in the editor while you’re recording a macro and get the Apps Script code that you can then use to make your spreadsheet look like what you want So instead of looking at documentation, the app just tells you It’s like having an expert in SpreadsheetApp sitting next to you telling you what to do So it’s really cool from a developer point of view as well So we’ve done our analysis We see that there’s a lot of people that owe us a lot of money So let’s go ahead and generate an invoice for the ones that are kind of outliers So we’ll start with these two And I’ll select the two rows that I’m interested in, and then I’ll go back to my demo menu and I click Generate Invoices So while that’s running, I’ll show you what it’s doing So I have this Google Doc It’s like a template invoice You see it has some variables in curly braces that correspond to the values in my spreadsheet or in Salesforce that I want to fill in with data from the spreadsheet And I’m using Apps Script to grab things from the spreadsheet and from Salesforce and I’m plugging them in to the template So here’s one that is finished generating As you can see, it looks just like the template from before But now we have the customer’s name and address We have today’s date And we have the total amount that they owe us from the spreadsheet So let’s take a look at what it takes to do something like that And you’ll find it’s pretty straightforward, I hope So from the menu, we call this generateInvoices method It grabs the active range That’s the current user selection And we read those two rows, and then we call this generateInvoice method So generateInvoice uses Drive App and Document App, two built-in APIs for Drive and Docs We make a copy of our template We put it in the Drive folder that we want it to go in We open it in Docs We run this Salesforce Object Query Language query to get the name and address of the accounts that we’re interested in And then we use the Docs API to do Find and Replace on the document We’re replacing those variables that were in curly braces with the actual values that we got out of either the spreadsheet or from Salesforce

And finally, we returned the URL, which we then put on the last column of our spreadsheet So now our invoice is ready to go We can go and send those on to our customers So the final step that I want to show you is how you can use Apps Script to summarize this information and put it in a presentation that you can show to your boss or to your leads so you can tell them that someone owes us $1.9 million So I go back to the demo I click on Generate Report And here, Apps Script is generating a chart that summarizes what I had in the table and gives me a link to the final report that I have in Google Slides So I can click on that And I can see the presentation that we just generated It’s very simple It has a title And it has the chart that we created on the spreadsheet And the cool thing about this chart is that it’s actually linked to the spreadsheet, so if you click on that Open source link, it takes you right back to where the data was so you can see the work that went into it and double check any numbers that you need So let’s see how you can generate simple presentations using Apps Script So here’s the generateReport method that I called from the menu The first thing it does is that it creates a chart As you see, the Chart API is pretty full featured It has a lot of options to it I will confess, I recorded a macro and copy-pasted this code so I could run it here So I create a chart We put it on the active sheet We insert it Then we use Slides App, which is the native integration between Apps Script and Slides This is new in the past year as well And it’s pretty straightforward to create very simple presentations, either from templates or from scratch Here, I’m grabbing the first slide It’s always the title slide We’ve put the title in the center title placeholder We append a new blank slide We add that chart that we created earlier And then we get the URL of the presentation so we can show to the user using showLinkDialog again So that’s our first demo As you can see, it’s pretty straightforward to do this kind of operation between getting data from external system, put it in Sheets, manipulating it, either by hand or using a macro, and getting things into Slides Let’s go back to the slides All right So quickly summarize what we saw We hit a public API We used the new native integration with BigQuery to get the data we need We formatted and analyzed it We pushed data into Docs using an invoice And we summarize the results in Slides So the first thing I did, I showed you that native integration with BigQuery That is available in beta If you’d like to check it out and learn about the other things that we’re doing with Sheets and BigQuery in data analysis, please go to gsuite.google.com/bq-sheets to sign up for the beta And we’d love to hear your feedback on that feature All right, so that’s it for the first demo I’d like to hand it off to Yash to tell you about our REST APIs [APPLAUSE] YASH SAINI: Thanks, Maurice So as Maurice discussed, Apps Script is a lightweight way to automate business processes Now we’re going to take a look at the Sheets and Slides REST APIs which can be used to perform bulk operations while also communicating with an on-premise system So here’s the setup You’re an account manager, and your company uses an in-house solution to track how much of your products your retail partners have sold And every quarter, you need to produce a set of presentations for your quarterly business reviews to share how your accounts are performing To do this, you start with a template presentation, and then you fill in the appropriate data for every account This is a time consuming process that we want to automate So let’s take a look at a demo to see how can you use the Sheets and Slides APIs to automate this process So here’s our template presentation You’ll notice that we have these placeholders sprinkled throughout this presentation So these placeholders correspond to customer attributes that our in-house system understands So what the first step is going to be is to take these placeholders from this presentation and put them into a spreadsheet We’re going to put them into a spreadsheet so that we have all of our placeholders and customer data in one place so we can validate it, polish it up, and get it ready to put it into our final presentations So let’s do that I’m going to run this command here, which is going to run a Python script to actually create the spreadsheet So I’m going to paste it here So I’m calling this quarterly business review tool with the create_sheet operation, and I’m passing it the ID of this template presentation

So it’s going to run and then produce the spreadsheet URL for the spreadsheet that it just created And let’s open this up So here we have a sheet that has all of the placeholders that were in the presentation So let’s take a look at how this works So this is our quarterly business review tool So the first thing is we do some auth setup And then next, we set up some service clients In this demo, we’ll be using the Slides API, Sheets API, and Drive API, so we set up the service clients for all of those Here we do some command line argument parsing Nothing too interesting going on here And then we get to the create_sheet method So the first thing that this does is it gets all the placeholders out of the presentation, as well as the title, using this presentation reader object Let’s dig in a little bit to see how it does this In the presentation reader, if you call GetTitle or GetAllPlaceholders, it first initializes the presentation So to initialize the presentation, it uses the Slides API and calls GetPresentation to retrieve an API representation of the presentation So once it has a presentation, if we were to call GetTitle, it asks for the title property and returns that And in the case of GetAllPlaceholders, we take all of the slides in the presentation, iterate over them, and on each slide, we iterate over all of the page elements A page element is just anything that’s on a slide, like a shape, image, table, et cetera So in this case, we’re going to iterate over all of the page elements in every slide, looking for shapes and tables, because those are the ones that contain text So if we find a shape, we’re going to process the text in it And if we find a table, we’re going to iterate over all of the table cells in the table, looking at all of the text in those table cells here So let’s take a look at what processing the text of a shape or table cell means So the text in a shape or table cell consists of text elements So we’re going to iterate over all of the text elements, looking for placeholders And whenever we find them, we return a list of them And then up here, we’re still collecting all of the placeholders throughout the entire presentation And then finally, we return a set of the unique ones So now, jumping back to the QBR tool, we have all of the placeholders in the presentation And now we want to finally create that spreadsheet So to do that, we’re going to define what the spreadsheet title is going to be, which is just, in this case, going to be Data Sheet for the presentation title And then we’re going to create an empty spreadsheet So we’re going to call this CreateSpreadsheet function And we’re going to pass through the Sheets service client the spreadsheet title for what we want to call the spreadsheet, as well as the sheet titles for all of the sheets we want the spreadsheet to have In this case, we just want one sheet And we’re going to call that the customer data sheet So let’s take a closer look at what this does So here’s that CreateSpreadsheet function We’re going to be calling the create method on the Sheets API And we’re going to pass in the spreadsheet that we want to create In this case, we’re just creating an empty spreadsheet So we’re going to pass in the title And then for every sheet that we want to create, pass in the sheets along with the titles associated with those sheets And then at the end, we return the created spreadsheet So great, now we have this empty spreadsheet The first thing we’re going to do is we’re going to get the spreadsheet ID and the sheet ID for the newly created spreadsheet And then using that, we can performance a subsequent operation to populate the placeholder data So we’re going to instantiate the Spreadsheet Writer object, passing it the Sheets API service client and the spreadsheet ID And then we’re going to call these methods The first method is to populate the column itself So we’re going to pass in the sheet ID, the column index that we want to write to, which is the first column, the column ID, which is placeholders, and then the values that we actually want to write to the column So I mentioned this thing that we want to call this column_id=’placeholders’ But what is this column ID? Well, in this case, we’re using a new feature in the Sheets API which is called Developer Metadata Developer Metadata lets you tag a spreadsheet, sheet, rows, or columns in your spreadsheet with metadata And this is metadata that only the developers can read And it is invisible to users So this means in this case, for example, I’m tagging this column with a placeholders metadata, so that if a user were to accidentally change a header or move a column around, the integrity of the spreadsheet is still maintained and you can still get the data that you’re looking for so your application doesn’t break So I populate the column And then after that, I call this AddTemplateIdToS preadsheetMetadata, and I pass in the template ID so that I can figure out from the spreadsheet which template is this spreadsheet talking about So here– above we were tagging a column with metadata And here, we’re tagging this spreadsheet with the template ID

And then at the end, we call this ExecuteBatchUpdate method So here it sounds like we’re populating a column And here it sounds like we’re adding the template ID to the spreadsheet metadata But here we’re just adding stuff to a batch so that we can execute them all at once And so we can execute multiple operations on your spreadsheet using just one API call So let’s take a closer look at how this works We’re going to go back to the spreadsheet writer And in this case, we’re going to look at the spreadsheet writer class The first method we called was PopulateColumn So here, we’re creating an update sales request And here we’re going to essentially just write in the values that we want to populate into the column And we add that to this request array The next thing we do is we create a developer metadata request And again, we add that to this request array Here is where we’re tagging that column with the developer metadata that we passed in using the metadata key column ID, and the value being the column ID that we passed into this method, in this case, the placeholder string The last thing we did was call this AddTemplateIdToS preadsheetMetadata method, which creates, again, a createDeveloperMetadata request But in this case, instead of here where we tagged the metadata on specific columns, here we’re tagging it to a spreadsheet And then we, again, add this request to the request array And finally, execute the batch, where we send this list of requests to the server and they all execute together Executing them in a batch helps improve the performance of your applications So let’s go back here Once we execute the batch, we finally print the spreadsheet URL so that we can access the spreadsheet Great So that covers how we got to where we are now in the demo So the next thing we want to do is populate the spreadsheet with the actual customer data So I’m going to run another command So instead of creating sheet, this time I’m going to add customers to the sheet So I’m going to want to paste in the spreadsheet ID for the spreadsheet that we just created And so I’m going to be adding customers to this spreadsheet and I’m going to pass in the customer IDs for the customers that I want to populate the spreadsheet with So I’m going to run this Great, let’s see what this did Going back to our spreadsheet, now it’s populated with our customer data Let’s take a look at how this worked So now we’re going to go to the add_customers method Here it takes in the spreadsheet ID and the list of customers we want to add And the first thing that we do is we read the placeholders from the spreadsheet that we wrote earlier We’re doing this so that we can finally query our internal data service to fetch the actual customer data So in order to read the placeholders, we’re going to first create this CustomerSpreadsheetReader object I’m going to pass in the spreadsheet ID and the Sheets API service client And then we’re going to call this ReadColumnData method And we’re going to pass in the column ID, which was the developer metadata that we tagged the column with earlier And then we call ExecuteRead ExecuteRead will then return this customer spreadsheet object that we can use to create the actual properties from the spreadsheet that we fetched when we called ExecuteRead So let’s take a closer look at how this CustomerSpreadsheetReader does this So here, the first thing we did was called ReadColumnData, and this is creating a data filter A data filter is essentially just a way to filter data in a spreadsheet A spreadsheet can have lots and lots of data in it, but sometimes you only care about certain pieces of it And you can specify what pieces you’re interested in using a data filter So a data filter can be, I want to read this specific A1 range, or like in this case, we want to read the content that’s tagged by certain specific developer metadata So I’m going to pass in the metadata key, which is our column ID, and then the metadata value, which is the column ID that we passed into the method And then I add this to a data filters dictionary And then finally, when I call ExecuteRead, I’m going to finally call the Sheet API and pass in the data filters that I want to read And then it returns to us appropriate spreadsheet You’ll notice here, we pass in also read_fields, because a spreadsheet can have lots of properties And in this case, we don’t care about most of them We only care about a very specific subset, so we’re just going to read those Finally, it comes back with this API representation of a spreadsheet And then we create this CustomerSpreadsheet object by passing through the returned spreadsheet, as well as the data filters that we created So then we return this customer spreadsheet object, and then if you recall, we then asked this customer spreadsheet

object to get us the sheet ID, which simply queries the sheet ID off of the spreadsheet object And then we called GetColumnData And we passed in the column ID to actually read from the returned spreadsheet object the values themselves So here we’re going to look up which data filter had this column ID in it, and then return the data for that appropriate part of the spreadsheet Great So going back– did I change anything? Nope So going back, now that we have the placeholders, we’re going to next process those placeholders into our query parameters These are the query parameters that we’re going to pass to our internal data service So in this case, since our placeholders map very well to the properties that our internal system understands, we’re just going to strip off the curly braces and any suffix that’s on the placeholder to get our properties, and then we add this to this properties list Then we’re going to initialize some objects that we’re going to use when we’re processing all of our customers The first one is our internal data service, which we’re calling the customer_data_service, that’s going to vend our internal customer data And then a spreadsheet writer, which is going to write the customer data, finally, to the spreadsheet So now we’re going to iterate over all of our customers And the first thing we’re going to do is get the actual customer data from our internal customer data service Here’s where we made that call, but in reality, this can be anything This can be your internal SQL database This can be an internal microservice Truly anything So then once we get the customer data, we’re going to write this customer data to the sheet We’re going to first insert a column at index 1 So inserting a new column right next to the placeholders column And then we’re going to populate that similarly to how we populated the placeholders earlier And in this case, instead of tagging it with the placeholders column ID, we’re tagging it with the actual customer ID, and we’re passing in the customer data And we do this for all of our customers And we queue up a batch of requests to populate the customer data And then finally, we just execute one write request to the Sheet API to write all of our customer data So now we have all of our customer data inside this spreadsheet So now is where I’m going to polish it up, validate the data, and make sure it looks good before generating those presentations So I’m looking at it and I see that, oh, our quarter over quarter numbers are just numbers instead of percentages Let’s fix that Cool I think our data looks good I think it’s time to start generating some presentations So to do that, I’m going to go over here and run another command Instead of adding customers, I’m going to create presentations So I’m going to pass in, again, the spreadsheet ID, which contains our customer data, and the customer IDs for all the customers I want to generate presentations for So I’m going to run that And this is going to start generating those final template– using those templates, the template earlier, generate the final presentations So it’s going to start creating that So we have one just generated for the Mars Company, one for Jupiter Let’s take a look at what one of these looks like So great Earlier we had this template with these placeholders in it Now it’s been filled in and it has all of the appropriate values that we had for this company in our spreadsheet So let’s take a closer look at how this works Now we’re getting into the create_presentations method So the first thing we do is we want to read the customer data and the placeholders from our spreadsheet So similar to how we read the placeholders when we were adding customer data, we’re going to read the placeholders again But we’re also going to read the customer data So we’re adding these We’re calling ReadColumnData to add the data filters to read all of the columns And then finally, we’re going to execute the read So we execute one read request that’s going to return all of the data specifically for the placeholders and all the customers we want to generate presentations for And then finally, we read the placeholders out so we have that available when we’re trying to generate our presentations The next thing we do is we get the template ID from our customer spreadsheet so that we know which presentation to copy in order to finally generate our presentations We do that, as well as get the title of the presentation so that we can have a decent title for our finally generated presentations And then we start generating a presentation for each customer So for each customer, the first thing we do is use the Drive API to make a copy of the template presentation And then in the copy, we replace the placeholders with the actual customer data So we finally fetch the customer data from that returned spreadsheet And then using a presentation writer,

for every placeholder and value pair, we find and replace the placeholder and update it with the actual content So here, in this case, if our placeholder ends with a dot image suffix, we’re going to replace the shape that contains that placeholder with an image And otherwise, we’re going to replace it with text And then finally, once we’ve done this throughout the presentation, we’re going to execute the batch So let’s take a look at what the presentation writer does So you’ll notice here that this looks kind of similar to what we saw earlier when we were doing this with the spreadsheet writer Here we’re creating requests and we’re appending them to a list of requests And so in the case of ReplaceAllText, we’re going to replace text with text In the case of ReplaceAllShapesWithImages, we’re going to replace shapes which have particular text with images that are referenced by this image URL, and also append these to the request list And then finally, execute the batch And then finally, once we’re done executing the batch, we’re going to print out the presentation URL And that’s it, we’re done So this wraps up the demo I’m going to switch back to the slides Great So let’s do a quick recap of what we covered So the first thing that we did was we took a template presentation, read all of the placeholders out of it, and put that information into a spreadsheet The next thing that we did was that we queried our internal service to fetch the customer data and pushed that into a spreadsheet This part, where we create our internal service, really could be anything We could call, again, our internal SQL database or we can call internal microservice And then once we pushed this data into a spreadsheet, we then tagged it with developer metadata to make it easier to read in the future and to make sure that user modifications can’t affect the structural integrity of our spreadsheet And the last thing we did was we generated presentations We made a copy of the template And then we replaced the placeholders in the copy of the template with the actual data that we fetched from the spreadsheet So as we saw, we used the Sheets and Slides API to automate a particular business process But I’m sure you’re wondering, what about a Docs API? So today we’re announcing a developer preview of the Docs API This is a REST API that works similarly to the Sheets and Slides API And I’m going to do a quick demo of how we can use the Docs REST API to generate the same template that Maurice showed earlier– excuse me, the same invoice that Maurice showed earlier Switch back to the demo So if you recall, this was an invoice template that we used earlier to generate the invoices that we wanted to use as the gentle reminders So we’re going to generate one of these using the REST API So I’m going to execute a script called generate_invoice And it outputs this document And let’s open it up Great So it generated an invoice and we used the Docs REST API to do it So let’s open up the code and see if we can follow how this works So I cheated a little bit I didn’t query Salesforce and I didn’t look up in a spreadsheet I just have the values that we’re going to put into the document right here in the script But here is where we call the Docs API to fill out the invoice So the first thing we did was created a copy of the invoice using the Drive API And then I created a list of requests and then appended those listed requests with these replaceAllText requests to replace these placeholders with their actual values And then executed the batch You’ll notice here that this looks very similar to how we did this using the Slides API We work really hard to make sure that our APIs feel consistent, so that if you’re using one of APIs, that you can start using a different one and it should just feel natural So that covers the demo Back to the slides So this API is still in development, but we’re really excited to invite you to join a developer preview program at developers.google.com/docs So to wrap things up, developers have two major ways to integrate Docs, Sheets, and Slides to automate workflows The first one is Apps Script Apps Script makes it easy for you to start writing scripts that perform actions across several G Suite services And it also runs on Google’s own infrastructure, so you don’t have to worry about managing it on your own The second are the REST APIs The REST APIs bring G Suite services to your applications

They allow you to perform bulk operations and also make it possible for you to integrate with your on-premise systems The main takeaway, though, we want you to have today is that the Docs, Sheets, and Slides Apps Script and REST APIs are approachable, and they can be used to automate parts of your workflows so people spend their time doing the work that adds value instead You can learn more about our Apps Script and REST APIs here at developers.google.com/apps script, docs, sheets, and slides And lastly, if you want to download the code that you saw here today, play with it, run it, you can do so at docsnext18.page.link/apps-script and python Thank you very much for your time [MUSIC PLAYING]