These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

EVE Technology Lab

 
  • Topic is locked indefinitely.
 

Assets API return location

Author
Trayuni
Ministry of War
Amarr Empire
#1 - 2013-01-17 13:24:11 UTC  |  Edited by: Trayuni
I'm new to the API scene so sort of worming my way through it and learning as i go.

I want to return the number of assets I have in a particular station, veldspar for example.
So far I have:

=ImportXML("https://api.eveonline.com/char/AssetList.xml.aspx?vcode=????&keyID=????&locationID=????", "sum(//row[@typeid=1230]/@quantity)")

It returns the correct item however it lists the total quantity i have in every location. Not station specific.
What am i doing wrong? What?
TheSkeptic
Federal Navy Academy
Gallente Federation
#2 - 2013-01-17 15:06:45 UTC  |  Edited by: TheSkeptic
Pretty sure the api call doesn't take a locationID on the querystring.

Personally I parse all my assets into a db and generate my own xml for googledocs rather than hitting the api directly.

but maybe try something like: sum(//row[@typeid=1230 and @locationid=1234567]/@quantity)


Edit: Edited to correct the case of the locationid attribute after we discovered it was the case of the attribute name that failed testing this solution.

...

Trayuni
Ministry of War
Amarr Empire
#3 - 2013-01-17 15:39:39 UTC
Thanks for the help TheSkeptic,

That's along the lines of what I am looking for.
I was hoping to check the supply of an item across different characters. (again only in one station)

Pardon my ignorance, but I'm not familiar with creating my own database or xml code. This is something I hope to learn eventually. For now I'm merely looking for a quick fix to this single API query. I was hoping not to build anything large or complex.

TheSkeptic wrote:
... try something like: sum(//row[@typeid=1230 and @locationID=1234567]/@quantity)


I tried working around this but couldn't get it to work.
Again I'm terribly new to this sort of thing, i tried pasting it into the formula like so:

=ImportXML("https://api.eveonline.com/char/AssetList.xml.aspx?vcode=????&keyID=????&locationID=????", "sum(//row[@typeid=1230 and @locationID=1234567]/@quantity)")

This doesnt quite work.
Any more suggestions?
TheSkeptic
Federal Navy Academy
Gallente Federation
#4 - 2013-01-17 16:12:41 UTC  |  Edited by: TheSkeptic
As mentioned I don't think the AssetList call takes a locationID querystring value.

http://wiki.eve-id.net/APIv2_Char_AssetList_XML

Shouldn't it be your CharacterID instead
(unless you can leave it out in the case of character only customisable keys? - personally never tried)

Although given you report it's giving a total of all stations I'll assume it is ignoring the querystring value and returning your full list.

Out of curiosity what did you use for the locationID value?

You don't have to give the actual value for opsec... but some detail into how you derived the value to use.

Edit:

So I had a quick look at one of my asset files used for parsing to refresh.

Given it's items in a hangar it's unlikely to have both typeID and locationID on the same row... but the typeID will exist in children of the locationID row.

my xpaths are pretty rusty but maybe something like this might get you a little further.

sum(//row[@locationID=1234567]/rowset/row[@typeid=1230]/@quantity)

Sub in the stationID for 1234567

...

Trayuni
Ministry of War
Amarr Empire
#5 - 2013-01-17 16:46:40 UTC
Many thanks for your continued help TheSkeptic. Big smile

I've removed the locationID from the string as you mentioned. I'm starting to understand this change after a little more reading.

TheSkeptic wrote:
...Out of curiosity what did you use for the locationID value?...

I was using value of 60003304 for the only station in Adahum system (reference http://biotronics.basicaware.de/eve/download/StationID2Name.txt)

My fomula now stands at:

=ImportXML("https://api.eveonline.com/char/AssetList.xml.aspx?vcode=????&keyID=????", "sum(//row[@locationID=60003304]/rowset/row[@typeid=2395]/@quantity)")

I changed the type id to something I actually had in station (oops), however it still returns a value of 0.
No error message though.



TheSkeptic
Federal Navy Academy
Gallente Federation
#6 - 2013-01-17 18:55:02 UTC
okay... spent a little time when I got home looking into this and have a better answer.

Your xpath is basically this: "sum(//row[@locationid='xxx']/rowset/row[@typeid='xxx']/@quantity)"
Also ensure the attribute names are lowercase.

Now, if you still get nothing back. You are probably out of luck for like an hour or so.

Over the last day or so I've been noticing issues with the api and some calls hanging.

My guess is your request has done this and google has cached an empty result or something. Best bet is try again later.

The above failed for me on google, but even the simple call you had that returned your eve wide total failed and said 0 so I was suspicious.

I then tested the above xpath by doing the api call on my own server and saved the xml file locally, I then put it in the webspace and let google call that directly and the xpath filter worked as expected.

Hope this helps.

...

Trayuni
Ministry of War
Amarr Empire
#7 - 2013-01-17 20:05:02 UTC
I dont really understand why but my eve wide total seems to work when i use this:

=ImportXML("https://api.eveonline.com/char/AssetList.xml.aspx?vcode=????&keyID=????", "sum(//row[@typeid=2395]/@quantity)")

This returns a correct result after a few different tests.
I then used the following formula in hope for a station search:

=ImportXML("https://api.eveonline.com/char/AssetList.xml.aspx?vcode=????&keyID=????", "sum(//row[@locationid='60003304']/rowset/row[@typeid=''2395']/@quantity)")

This pulled an (incorrect) result of 0.

It's getting late for me so I will have to try again tomorrow after some more reading into the workings of xpath.
Thanks again for your continued help TheSkeptic

PS.
A little background on why I'm after this particular query.
I'm setting up a small buying program between close friends. The idea is that i use their API to see if they have any Proteins for sale in station. If they do I send them a buy contract with however many I need at the time. At which point they can just hit accept on the contract.
The query allows me to see if the person has enough available proteins(or whatever) for me to buy
TheSkeptic
Federal Navy Academy
Gallente Federation
#8 - 2013-01-17 20:30:46 UTC
Trayuni wrote:
sum(//row[@locationid='60003304']/rowset/row[@typeid=''2395']/@quantity)


If that is a direct copy/paste you have an extra ' in the typeid

try this: sum(//row[@locationid='60003304']/rowset/row[@typeid='2395']/@quantity)

...

Trayuni
Ministry of War
Amarr Empire
#9 - 2013-01-17 20:53:59 UTC
I guess that was a small typo when I was removing the API code for the forum. Top marks for attention to detail!

The formula on my sheet was entered correctly though. Still 0 result :(
TheSkeptic
Federal Navy Academy
Gallente Federation
#10 - 2013-01-17 21:19:57 UTC  |  Edited by: TheSkeptic
argh... I interesting... I'd make a mistake examining the asset doc before I left work. *facepalm*

We were close ealier tbh with this:

TheSkeptic wrote:

but maybe try something like: sum(//row[@typeid=1230 and @locationID=1234567]/@quantity)


This probably didn't work because I gimped the attribute name with the capital ID.

sum(//row[@locationid=60003304 and @typeid=2395 ]/@quantity)

Going down to the Rowset and next group of rows is only required for looking inside ships/cans/corp hangars etc

...

Trayuni
Ministry of War
Amarr Empire
#11 - 2013-01-18 02:02:11 UTC
Couldn't sleep much knowing I had this to test out after I read your reply on my phone.
Tested it out and its working well :)

There was a delay in the query, when I first opened the sheet. Perhaps for reasons you expected.
I left it a while and it was working after a coffee break.

For anyone interested here was the final solution to check assets in station.

=ImportXML("https://api.eveonline.com/char/AssetList.xml.aspx?vcode=____&keyID=____", "sum(//row[@locationid=____ and @typeid=____ ]/@quantity)")

I really appreciate the help TheSkeptic, left you a small donation ingame.
TheSkeptic
Federal Navy Academy
Gallente Federation
#12 - 2013-01-18 09:25:26 UTC
Great to hear that worked and sorted the issue out for you!

My guess is the delay when you first open the sheet is google hitting the api, caching and parsing the xml.

Depending how much stuff (or in my case junk) you have scattered all over eve asset xml dumps can large fairly quickly.

...

Jim Augus
State War Academy
Caldari State
#13 - 2013-02-18 20:15:57 UTC  |  Edited by: Jim Augus
this worked out great for personal assets thank you.

However, looking to expand upon this a bit.

I am trying currently to work out an importXML function to be able to return a quantity of a specific item located in a specific corp hangar array in space.

currently attempting to use

=ImportXML("https://api.eveonline.com/corp/AssetList.xml.aspx?vcode=XXX&keyID=XXX", "sum(//row[@itemID=XXX and @locationid=XXX and @typeid=XXX ]/@quantity)")

Getting a return of 0

Their are multiple CHA's at the same tower and in system at other towers with multiples of the same item in them. I am trying to identify the specific CHA and narrow my quantity return to that specific CHA. I was attempting to use the itemid field as a way to narrow to the specific CHA as it seems to be an identifier for that specific CHA.

Any help?
Jim Augus
State War Academy
Caldari State
#14 - 2013-02-18 20:44:07 UTC  |  Edited by: Jim Augus
I had mistakenly had the url as a /char/ instead of /corp/. After making the change the error is coming back as "The data could not be retrieved please check the url"

I can toss the URL with the vcode and keyid in a browser and pull up the raw xml data of the assets but google docs doesnt like it for some reason.

I am under the assumption that the API key you need to make this work is as follows.

A director level API with Character set to the specific director char, type set to corporate and only check mark I would need is on corp asset list. Is this correct?

hummm
Gunlab
Labby Transports
#15 - 2013-03-07 17:28:40 UTC  |  Edited by: Gunlab
Hey Im using

=ImportXML("https://api.eveonline.com/char/AssetList.xml.aspx?vcode=___&keyid=___&locationid=____", "sum(//row[@typeid=___]/@quantity)")

This works, the other solutions posted didnt work for me in google.

But how do i get several items i.e all mineral types in one call?

something like "sum(//row[@typeid=__ and @typeid=__ and..." my xpath is experience is 35 minutes old :P

i wanna fetch all mineral types and display them in google spreadsheet. And i dont wanna use the importXML command more than necessary.

Edit:

seems the locationid doesnt work when u add it this way. if i add locationid after sum it returns 0.
TheSkeptic
Federal Navy Academy
Gallente Federation
#16 - 2013-03-08 15:28:24 UTC
Jim Augus wrote:
this worked out great for personal assets thank you.

However, looking to expand upon this a bit.

I am trying currently to work out an importXML function to be able to return a quantity of a specific item located in a specific corp hangar array in space.

currently attempting to use

=ImportXML("https://api.eveonline.com/corp/AssetList.xml.aspx?vcode=XXX&keyID=XXX", "sum(//row[@itemID=XXX and @locationid=XXX and @typeid=XXX ]/@quantity)")

Getting a return of 0

Their are multiple CHA's at the same tower and in system at other towers with multiples of the same item in them. I am trying to identify the specific CHA and narrow my quantity return to that specific CHA. I was attempting to use the itemid field as a way to narrow to the specific CHA as it seems to be an identifier for that specific CHA.

Any help?


I think the issue is in your xpath search, the typeID you want the quantity on needs to be moved out.

instead of this:
sum(//row[@itemID=XXX and @locationid=XXX and @typeid=XXX ]/@quantity)

try something like:
sum(//row[@itemID=XXX and @locationid=XXX]/rowset/row[@typeid=XXX]/@quantity)

...