I’ve been meaning to write this post for a while now, so here it finally is; How to use ESI, with google sheets.
Now, the unauthenticated endpoints are relatively easy. You’ll still need to write a little code for them, or steal it from somewhere else, but other than that, it should just work. Authenticated endpoints are another matter.
ESI uses Eve’s SSO for authentication, which means, at some point during the setup, you’ll need to handle the OAuth flow to get what’s known as a refresh token. This token is much like an XML key from the older API, allowing you to access the endpoint without any human intervention. (It’s actually used to get the access token, which allows you to do things for about 20 minutes. The refresh token can be used at will to create new access tokens)
Due to the way it works, this means you’re going to have to go to the developers site, and create a new application. Each application has a client id, and a secret, and that secret should be held closely and not revealed to the general public. So you need to create your own.
So, go to the site, log in, and click on ‘application’ up at the top. You can then click on ‘create new application’.
Give it a name and a description. I’d suggest something meaningful to you for the name, but the description isn’t important; you just need something there. Pick ‘Authentication & API Access‘ as the type.
Now you need permissions. These are what are known as ‘scopes’ in OAuth. They’re like the various things you can pick in the XML api, allowing access to various different things. What scopes you pick, is dependent on what you actually want to do with the login. When actually doing the login, you tell it which scopes you want. As long as they exist in the application definition you’re filling in now, you can get them. You don’t need to ask for them all.
For this example, I’m asking for the esi-universe.read_structures.v1 and esi-markets.structure_markets.v1 scopes. This allows me to pull the market data from a structure I have access to (and get its name). Just click them, and they should move over to the box on the right.
Now comes the ‘complicated’ bit. The callback url. When you use OAuth, you get sent to the login server, log in there, then get redirected back to the source. The callback url is where you’re sent. As you don’t have a webserver for this (probably) we’re going to use a tool called Postman to handle this step.
Fill in https://www.getpostman.com/oauth2/callback as the callback url. Click on ‘create new application’.
Finally, click on ‘view application’ next to your newly created one.
Postman is a chrome app which is designed for working with APIs. We’ll be using it to handle the initial authentication. Get it from its site. Once you’ve installed it, run it.
It should look something like this. On the authorization tab, change the drop down to ‘OAuth 2.0’. Then click the ‘get new access token’ button.
Auth URL: https://login.eveonline.com/oauth/authorize
Access Token URL: https://login.eveonline.com/oauth/token
Client ID: The ID from the application page you just created
Client Secret: the Secret Key from the application page you just created
Scope: the scopes you want, separated by spaces. So in this case:
Finally, hit ‘request token’. This should send you to the login page for Eve. If it doesn’t work, make sure you have no extra spaces at the beginning or end of the various options.
Once that’s done, and you’re authorized, you should see a token in the existing tokens box.
This lists your access token (you can ignore this, tbh. you’ll be getting a new one.), and your refresh token (this is important, so take a note of it, along with your client id and your secret.)
That’s you finished with Postman, until you want a new token for something else.
Google Sheets doesn’t handle JSON or OAuth natively. This is a bit of a pain, but the ability to add custom functions takes care of that nicely. Especially when someone else writes them for you 😉
For this example, we’ll create a new workbook.
On your new workbook, create a new sheet and call it config. Put the client id, the secret, and the refresh token into separate cells on it.
On the Data menu, pick ‘Named Ranges…’. This will open a sidebar. select the clientid cell, and click ‘add a range’. call it clientid, and hit done. Repeat with the secret, and the refresh token, calling them ‘secret’ and ‘refresh’.
you can then close the sidebar. This is just to make it easy to refer to them later.
Now, click on Tools->Script editor. This will open a new window. switch to it.
Delete the contents of Code.gs (it should be an example myFunction only. if not, you’re in uncharted waters)
Finally, on a sheet without data you care about (as this is a new workbook, sheet 1 works) use
and it should (eventually) populate with all the orders from that citadel. get the citadel id from a bookmark, asset id, or market order.
I need to do more work on this, as it’s not storing the access token anywhere (there’s an issue with the sheet doing updates on cells from custom functions)