question

unbrokencraig avatar image
unbrokencraig asked

CloudScript HTTP request with x-www-form-urlencoded

I'm trying to run a CloudScript from a PlayStream event which will call a Steam WebAPI request.

The Steam WebAPI documentation says to use x-www-form-urlencoded for the Content-Type.

I've tried a couple different ways to pass the data into the content of the http.request, but the response keeps coming back saying "Required parameter 'key' is missing"

Is there some other way I need to pass the content to the http.request other than the two methods I've tried below?

(I use the proper key and appid in my Cloudscript, just didn't want to post those publicly)


handlers.CheckEarlyAccessOwner = function (args, context)
{
    var steamid = context.playStreamEvent.PlatformUserId;
  
    var headers = {};
    
    var body = "?key=XXXXXXXXXXXXXXXXXXXXXXXXXX" + "&steamid=" + steamid + "&appid=YYYYYY";
    log.debug("Body: " + body);
  
    //var body = {
    //    key: XXXXXXXXXXXXXXXXXXXXXXXXXX,
    //    steamid: steamid,
    //    appid: YYYYYY
    //};
      	
    var url = "https://partner.steam-api.com/ISteamUser/CheckAppOwnership/v2/";
    var content = body;
    //var content = JSON.stringify(body);
    var httpMethod = "get";
    var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
      
    // The pre-defined http object makes synchronous HTTP requests
    var response = http.request(url, httpMethod, content, contentType, headers);
  
    log.debug(response.timestamp);
  
    return { responseContent: response };
}
CloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
unbrokencraig avatar image
unbrokencraig answered

Nevermind, just figured it out. Instead of filling the parameters into content, I just had to add it to the end of the url.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.