0

So I'm trying to get a player's CSGO inventory using Valve's API, but I can't get it to work since it's giving me the no 'access-control-allow-origin' header is present on the requested resource. error, so I tried using jsonp but I'm not sure if it supports it. So I was wondering how I would get someone's inventory? A ton of other sites can get it but I don't know what I need to do. Any help is appreciated :)

I'm using javascript/jQuery if that helps at all

Connor S
  • 25
  • 7
  • Which endpoint are you trying to hit? You're trying to do a cross-origin AJAX request on an endpoint that doesn't have a CORS header set, which is most likely an incorrect endpoint. – Daniel T. Feb 25 '17 at 02:53
  • @DanielT. what do you mean by endpoint? And if I'm doing it wrong then what do I need to do to fix it? Sorry if I'm asking dumb questions, I'm kinda new to this and still learning – Connor S Feb 25 '17 at 05:37
  • What URL are you trying to connect to? – Daniel T. Feb 25 '17 at 06:54
  • @DanielT. im trying to use [this](http://steamcommunity.com/inventory/76561197962837077/730/2?l=english&count=5000) – Connor S Feb 25 '17 at 15:29

1 Answers1

0

You cant get access to the inventory via jsonp because steam disallows CORS requests (they need to set the headers).

Since steam is not providing an option to enable this you need to proxy the inventory request through your own server.

Basic structure

So you need to write your own REST API Proxy to achieve this:

  1. Get Request from your application with the steam community as parameter. Should be look something like localhost:8080/inventory/76561197961239110
  2. On your server make a request to this url: http://steamcommunity.com/inventory/76561197961239110/570/2?l=english&count=5000
  3. Get the response and probably even edit it to your needs (like delete unnecessary properties).
  4. Return the response in JSON to your Frontend application. You can also enable jsonp there (read for example this question and the answers).
Community
  • 1
  • 1
Kevin Peters
  • 121
  • 1
  • 7
  • so is [this](https://dzone.com/articles/building-simple-api-proxy) a good guide on how to do that? I have no idea where to begin with it so if you know of a better guide it would be appreciated :) – Connor S Feb 25 '17 at 15:42
  • Read through this: https://github.com/andrewda/node-steam-guide Its very basic but will lead you through – Kevin Peters Feb 25 '17 at 18:57