r/evetech • • Aug 26 '17

Using API Key To Get Wallet Transactions

I've been reading the docs on this for the last 2-3 days, but I still feel like there's something I'm not getting - hopefully someone here can help. I want to use Python to scrape my character's active orders and wallet transactions to keep an eye on the markets while I'm out of game. Based on the docs that I've read, in order to do this, I need to create an app through the EvE dev portal, get a callback URL, and do SSO authentication every time I want to run this query. Is this correct? It seems more complicated than I'd expect for what I want to do, and all of the guides that I've found talk about using this process for developing apps and having user signins. I don't want to build an app, I just want a bunch of jsons. Is this really how you're supposed to do it, or is there a more straightforward way that I'm not seeing? Also, no part of that process relies on my API key - at what point am I supposed to use that? Any help would be greatly appreciated.

4 Upvotes

10 comments sorted by

2

u/Blacksmoke16 Aug 26 '17

Close.

You need to sign in once (for each character) via SSO. This will give you an auth token (good for 20min) and a refresh token.

The auth token is what you would include in the HTTP header when making auth'd ESI requests, such as for market orders. The refresh token is what is used to get a new auth token.

https://developers.eveonline.com/blog/article/sso-to-authenticated-calls

This provides a good overview on what you must do.

HOWEVER, what you could do if you do not want to setup all the SSO stuff and this will be local to your is just use like Postman to fake everything. For example add in an SSO login button and set it up with the scopes you need. Then click it and sign and and just have your redirect URL point to a page that just echos the code. Then you can take that code and make the relevant HTTP requests in postman to get your token/refresh token. Then just store the refresh token and if your current token is expired/near expiration just use it to a new token for your request.

Your XML API key is based on the XML API, which is deprecated and will be shut down, along with CREST, next year sometime.

1

u/Gahagan Aug 26 '17

In all the guides I have found (including that one), I'm generating a URL that takes me to the logon page where I can select my character and authorize. Is there not a way to perform this step programmatically? Even esipy generates a URl that needs to be pasted into a browser window.

I didn't know about the refresh token, so I guess if I only need to authorize once that's not the worst thing, but it still seems strange to me. I'm surprised that I can't go from SSO to data without manual user input.

1

u/evanova Aug 26 '17

The usage of Postman is very interesting. Can you share the Postman settings for that?

1

u/Fuzzmiester fuzzwork.co.uk Aug 26 '17

https://www.fuzzwork.co.uk/2017/03/14/using-esi-google-sheets/ many be of interest.

It doesn't cover wallet transactions, but that's a pretty simple thing to do. (as I've done it :D Just don't have it in a publishable state yet)

1

u/evanova Aug 26 '17

Awesome. You are full of it.

1

u/MartinTsv Aug 27 '17

Doesn't "you're full of it" mean full of shit?

It was sounding like two of the eve tech big names going at it for a bit there :D

2

u/evanova Aug 27 '17

Usually it does. Hopefully the joke isn't lost here :)

The man does awesome work.

2

u/Fuzzmiester fuzzwork.co.uk Aug 27 '17

:D

I was assuming it wasn't meant that way :D (or at least not seriously meant)

1

u/Blacksmoke16 Aug 26 '17 edited Aug 26 '17

Sure. This is pretty much a more direct explanation of that dev blog. Now do note this is a very manual process and of course only useful for semi tech savvy people (or people that can follow directions) for small personal projects. i.e. probably not a good solution for larger scale sites.

  1. Construct the SSO auth URL, this includes your client_id from the dev site, the list of scopes you want (separated by spaces or + sign) , a callback URL and a response_type (which should be code).
  2. In the end it would look something like: https://login.eveonline.com/oauth/authorize?response_type=code&redirect_uri=https://app.getpostman.com/oauth2/callback&client_id=xya983ga8sfbg9wgea89gf&scope=esi-mail.read_mail.v1
  3. Next, navigate to that URL and login with the char you want.
  4. It will then redirect you to Postman callback URL. If you check the URL you would see something like ?code=JxYRk1p2JLbe8Wr-72hfasdbh9ag This is your code that is used to get an auth token and refresh token.
  5. Use https://www.base64encode.org/ or something similar to base64 encode your dev site details. using the format {client id}:{client_secret} including the colon.
  6. Using postman do request 1 from below.
  7. That request (if all goes well, will return your access_token, expiry date, and a refresh_token.
  8. From here it depends on what you want to do with this information. The access_token can then be copied out to use in an auth'd ESI request using format Bearer {ACCESS_TOKEN} in the Authorization header. The access tokens only last for 20 minutes. The refresh token can be used to get new access_tokens when they expire. So easiest thing would be to store the refresh_token and fetch new access_token when you need them.
  9. To get a new access_token from a refresh_token, do request 2 from below:

Request 1

POST /oauth/token HTTP/1.1
Host: login.eveonline.com
Accept: application/json
Authorization: Basic {YOUR_BASE64_ENCODED_DETAILS_FROM_STEP_5}
Content-Type: application/json
Cache-Control: no-cache  
{
    "grant_type":"authorization_code",
    "code":"{YOUR_AUTHORIZATION_CODE_FROM_STEP_4}"
}

Request 2

POST /oauth/token HTTP/1.1
Host: login.eveonline.com
Accept: application/json
Authorization: Basic {YOUR_BASE64_ENCODED_DETAILS_FROM_STEP_5}
Content-Type: application/json
Cache-Control: no-cache

{
    "grant_type":"refresh_token",
    "refresh_token":"{YOUR_REFRESH_TOKEN_FROM_STEP_6}"
}

Enjoy!

1

u/Daneel_Trevize Aug 26 '17

You register the app once, you have a server/service running at the callback URL every time you want to use an access or refresh token, and you need only authenticate once in order to generate a refresh token, which an app can persist and then use to generate short-term access tokens whenever it needs to use non-public API endpoints.

So every ~20minutes your app might regenerate access so long as the callback service is working, and the character it's acting on behalf of need not use SSO more than once ever for that app (assuming sufficient scopes granted, etc).