2

I am creating a program that gets the steam market prices for various CS:GO items, and compares them to one another. I am having trouble getting the steam market JSON into my program. Market JSON Here is my code:

using (WebClient webClient = new System.Net.WebClient())
{
    WebClient n = new WebClient(); // <-- error on this line
    string json = n.DownloadString("http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=P250%20%7C%20Valence%20(Factory%20New");
    dynamic array = JsonConvert.DeserializeObject(json);
    test.Text = array.lowest_price.ToString(); ;
}

I am getting this error when instanciating WebClient():

An unhandled exception of type 'System.Net.WebException' occurred in System.dll

Additional information: The remote server returned an error: (500) Internal Server Error.

Is this even a valid JSON? If not, is there an alternative? I heard backpack.tf has an api as well. Would this be better? Thanks

zed
  • 2,298
  • 4
  • 27
  • 44
  • 1
    Why are you instantiating WebClient twice? – Steve Nov 09 '15 at 23:43
  • Oh wow. Didn't even notice that. Still causes the same error – CaptainUnicorn Nov 09 '15 at 23:44
  • If you click on View Detail in the exception window, you should be able to see in the response property or the Inner Exception which should give you more information. – Steve Nov 09 '15 at 23:45
  • 2
    The error is "500 Internal Service" error - that means something went wrong with the service on the server your client is contacting. Unless you have access to that service and server, you most likely won't be able to determine anything further. You'll need to contact the service owner. – Tim Nov 09 '15 at 23:47
  • The URL you are using is wrong. Paste it in a browser address and see what result you get. Here is a [URL that works](http://steamcommunity.com/market/priceoverview/?currency=3&appid=730&market_hash_name=StatTrak%E2%84%A2%20P250%20%7C%20Steel%20Disruption%20%28Factory%20New%29) from [Get the price of an item on Steam Community Market with PHP and Regex](http://stackoverflow.com/questions/23055673/get-the-price-of-an-item-on-steam-community-market-with-php-and-regex/25665733#25665733) – KiwiPiet Nov 09 '15 at 23:55
  • 3
    Your URL in code is missing an end bracket ')' – KiwiPiet Nov 09 '15 at 23:58

2 Answers2

1

Looks like the URL is malformed. I.just tried http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Shadow%20Case and it returned a good response.

Of particular note is the enclosed parenthesis in your URL.

Chet
  • 3,461
  • 1
  • 19
  • 24
0

Fixed code:

using (var webClient = new System.Net.WebClient())
{
    var json = webClient.DownloadString("http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=P250%20%7C%20Valence%20(Factory%20New)");
    dynamic array = JsonConvert.DeserializeObject(json);
    var price = array.lowest_price.ToString(); ;
}
KiwiPiet
  • 1,304
  • 14
  • 21