How do you start using API?

How do you start using API?

in API Development

Posted by: DennisChrDk.9823

DennisChrDk.9823

Hey guys

I was hoping some of you guys could help me out a bit. I just started today looking into some stuff about the API and decided to implement some of it in some google spreadsheets that I have, instead of me manually having to updating the prices. So far, I’m just trying to import some data from GW2Spidy, then I might make it more advanced later on. But my knowledge about programming is very limited.

So first of all, do anyone have any suggesting to maybe a website or a youtube channel where you could learn some of this basic stuff? Or maybe there is a place where I can see some excisting code from some gw2 related API?

So this is the scrip I’ve so far, most of it is pretty much just a rip off from some guide, but I’ve added some more lines from the gw2spidy API v0.9. http://imgur.com/saif8we
Right now I’m trying to add an auto refresh and a timer to when the prices were last updated? Could anyone help me with that? I tried adding a script with the response “price_last_changed” but it just gave me an error.
I’ve tried add an Image script as well, but whenever I use it I just get a link? I guess I’ll have to change the outpu, but how do I do that?

How do you start using API?

in API Development

Posted by: StevenL.3761

StevenL.3761

Hey!

Read these first:

API version 1: https://api.guildwars2.com/v1
API version 2: https://api.guildwars2.com/v2

Note that gw2spidy does not use the official API. It uses the same web service that the game client itself uses to access trading post data. Which is not a supported scenario.

How do you start using API?

in API Development

Posted by: DennisChrDk.9823

DennisChrDk.9823

Hey!

Read these first:

API version 1: https://api.guildwars2.com/v1
API version 2: https://api.guildwars2.com/v2

Note that gw2spidy does not use the official API. It uses the same web service that the game client itself uses to access trading post data. Which is not a supported scenario.

Thank you very much for the links, had not seen them before. I’ve actually been browsing the wiki for a while now, just to get an idea of what you would be able to extract from the API.
But a thing I can’t see is prices of the item? The only price I can find is the vendor price?

How do you start using API?

in API Development

Posted by: Alcarin.9024

Alcarin.9024

When writing code that relay on an API service, keep in mind that a connection to get data from a server is a cost (for you and for the server, in terms of hardware resource utilization and time), and you should always try to reduce as much as possible the cost of your application.
In your example, you are creating 4 connection to a server to know 4 information about an item. If you look at the url about that item, you see that you are asking to the server 4 time the same informations each time discarding all you get exept 1 piece of that ifnormations. This is a waste of resource, it’s not that much if you (for example) get information about 4 different items, but for each items you add 4 new connections, and if you want to know info about 100 items, you will make 400 connections, 1000 items=4000 connections.
Regarding time needed to get information, if every connection cost 200 ms of “idle of your program”, to get all information about a single item your program have to wait 800 ms, to get info about 4 items your program must wait 3200 ms (3,2 seconds), 100 items you have to wait 80 seconds. Reducing the amount of connection you programe idle time will be 1/4, so to get info about 100 items you only have to wait 20 seconds.

In your specific situation, you should separate connections from data elaboration.
I would do so:
Create a function that get data from gw2spidy:


function GetItem(ItemID){
    [...cut...]
    return jsonObject
}
and then create a function for each data you need, passing the jsonObject to them:

function GetItemSellValue(jsonObject){
    return (jsonObject.min_sale_unit_price /100)
}

About help on programming: I don’t know much about google spreadsheet, if you want to learn javascript there are a lot of website with guides, personally I use W3Schools and MDN as reference and some non-english for guides.
In this forum you could find a lot of examples on how to use GW2 API (not GW2Spidy API, GW2Spidy API are not developed by ArenaNet) but they are in a lot of different programming lenguage, I don’t know how much of them are in JavaScript.
You could find something in GW2 API Wrapper List or List of Application that use GW2 API.

If you have problem with some piece of code, if you ask here and post or link to your code I’m sure that someone can help you!
Don’t use images if you are sharing your code to get help, if someone want to help you and want to try your code, they have to rewrite it all, they cannot copy&paste it, use pastebin or jsfiddle) instead!

How do you start using API?

in API Development

Posted by: StevenL.3761

StevenL.3761

But a thing I can’t see is prices of the item? The only price I can find is the vendor price?

You’re looking for these:

How do you start using API?

in API Development

Posted by: DennisChrDk.9823

DennisChrDk.9823

Well I havn’t really had much time today to look into all the things that you send me, but I’ve been looking at some of it for maybe an hour or two, justto get an idea of what to do

http://pastebin.com/Qc1UbmQr

In your example, you are creating 4 connection to a server to know 4 information about an item. If you look at the url about that item, you see that you are asking to the server 4 time the same informations each time discarding all you get exept 1 piece of that ifnormations.

I see, I tried make a new script, in order to minimize the connections but I didn’t really got it to work (try take a look at the link). So the first line i guess is the part getting the data for gw2spidy, while the last part is the function?

Oh thanks didn’t see those, guess I’ll just change it when I get past the first initial part. But What jsonObject should I write? I doubte the line "var adjustedValue = (jsonObject.exchange /100); " is correct?

How do you start using API?

in API Development

Posted by: StevenL.3761

StevenL.3761

We don’t know what the JSON response will look like yet. We’re still waiting for more info on version 2 of the API and its release date.

How do you start using API?

in API Development

Posted by: Dr Ishmael.9685

Dr Ishmael.9685

Just pretend that the /v2 stub doesn’t even exist, makes everything easier.

How do you start using API?

in API Development

Posted by: DennisChrDk.9823

DennisChrDk.9823

In your specific situation, you should separate connections from data elaboration.
I would do so:
Create a function that get data from gw2spidy:


function GetItem(ItemID){
    [...cut...]
    return jsonObject
}
and then create a function for each data you need, passing the jsonObject to them:

function GetItemSellValue(jsonObject){
    return (jsonObject.min_sale_unit_price /100)
}

Can anyone help me out with this? I’m not sure how to get this to work. I set up the entire spreadsheet now, and minimized the amount of data that I import to like 30 buy/sell prices, but once in a while it gives me the error and says that the “service” was called to many times?

I just want it to update once ever hour (and maybe show what time it was updated), but I dont know how to do it myself. And can’t really find any guilds ect. online that shows how to do it?

EDIT: Changed the code a little bit, added a utility sleep function, I guess that will help a little: http://pastebin.com/BBhAJHdX

(edited by DennisChrDk.9823)

How do you start using API?

in API Development

Posted by: StevenL.3761

StevenL.3761

The point was that should have a single function that returns the entire response object. You have to do this in order to prevent your script from making multiple HTTP requests for the same json object.


function getItem(itemID) {
    var myUrl = "http://www.gw2spidy.com/api/v0.9/json/item/" + escape(itemID);
    var jsonData = UrlFetchApp.fetch(myUrl);
    var jsonString = jsonData.getContentText();
    return JSON.parse(jsonString).result;
}

var item = getItem(the_item_identifier);

var sellValue = item.min_sale_unit_price;

var salePriceChangeLastHour = item.sale_price_change_last_hour ;

var buyValue = item.max_offer_unit_price;

var offerPriceChangeLastHour = item.offer_price_change_last_hour;

How do you start using API?

in API Development

Posted by: Alcarin.9024

Alcarin.9024

Here is an example of what are you asking: http://pastebin.com/XRruKP8f

Alternatively, you can adjust downloaded value directly in download function, as shown in this example: http://pastebin.com/MYkaF1jZ

In my examples I’ve stored final values in variables because I don’t know how you use them.

How do you start using API?

in API Development

Posted by: DennisChrDk.9823

DennisChrDk.9823

Never got to say this, but thank you very much for all the help guys. My spreadsheet is working like a charm, it’s much better compared to my old one were I had to type in everything manually