Sign In Register

How can we help you today?

Start a new topic

Create downloadables from REST API

Using Unity3D.
We have defines for each level stored in XML files which we would like to put in downloadables.
That way we can change the levels and even add new ones without it being required for our players to update the game.
Right now for each new level we add, we have to first go to the downloadables section on the portal to create the shortcode and upload the xml there.

We can already update the levels using the REST API, but it would be very helpful if we could create new ones as well from within the Unity Editor.
(Now it returns: "Short code [DEF_LEVEL_2] Unknown" if we try upload a new one).

I can imagine this feature being a great addition for other types of games (like when there's a level editor for players) as well.

Is there already a way to do this?

Thanks in advance.

Hi Fries,

There's no way to do this right now, though with XML files I can imagine they are small enough to use with the UploadUrlRequest and then send them our way. You could then create a custom collection to store level details (uploadId, name, an image of what the level looks like, etc) and and use cloud code to query all level's stored in GameSparks. This would actually be great for a game that has constantly expending levels or one that allows users to create and upload their own, like Super Meat Boy.

In the mean time I'll forward on your request to create downloadables from the REST API as I can see how useful it could be.


Any news on this? I could definitely make use of uploading downloadables. If this feature is being worked on I think allowing metadata to be added to downloadables could be useful too, particularly if you could access the downloadables data via cloud code. My intention is to upload Asset Bundles with version numbers and have the client get a list of downloadables and their version numbers (or something of that nature). While this would be ideal, uploading my planned downloadables manually and keeping a metaCollection with version numbers up to date should not require an insurmountable amount of effort.

As was mentioned UploadUrlRequest could work as an alternative, would it be reliable with Asset Bundles potentially as large as ~5MB? Although I don't like the idea of not being able to see uploads in the configurator.

It seems to me that player uploaded data and downloadables could potentially benefit from being combined into a single file system. One that is viewable from the configurator, has metadata, and comes with Cloud Code APIs that can be used to query said meta data.

I've managed to come up with a workaround, by simulating the actions when creating a downloadable from your web browser:

First add this function to "Assets/GameSparks/Editor/GameSparksEditorFormUpload.cs":


    public static string CreateFile(string gameId, string url, string shortCode, string fileName, string username, string password)
        url += "?gameId=" + gameId;
        FileParameter param = new FileParameter(GetBytesFromFile(fileName), Path.GetFileName(fileName));
        param.FileName = fileName;
        IDictionary<string, object> postParams = new Dictionary<string, object>();
        postParams.Add("shortCode", shortCode);
        postParams.Add("binaryContentFile", param);

        return MultipartFormDataPost(url, postParams, username, password); 

 Then add this function to the file "Assets/GameSparks/Editor/GameSparksRestApi.cs"


  public static String sendNewDownloadable(string apiKey, string username, string password, string shortCode, string fileName)
        string url = HOST + "games/binaries/edit.html";
        String ret = null;
            ret = GameSparksEditorFormUpload.CreateFile(apiKey.Substring(0, 6), url, shortCode, fileName, username, password);
        catch (WebException we)
            ret = "{\"responseCode\":-1,\"errorMessage\":\"" + we.Message + "\"}";
        return ret;


Finally, you can call the function like this:


string result = GameSparksRestApi.sendNewDownloadable(apiKey, login, pass, shortCode, fullPath);



Thank you!

So my asset bundle upload/download process is almost entirely automated now! But I ran into a single snag, uploading a downloadable with the same short code as an existing one does not replace the old one. When the downloadable ID is included in the request the file is properly replaced. Unfortunately there does not appear to be a simple automated way to get the id.

So I have a new request, can the "games/binaries/edit.html" endpoint be modified to replace downloadable with the same shortcode without need of id? This doesn't seem like it would create any issues. If not that then maybe return the downloadable id when calling the edit endpoint (it returns nothing right now so I also don't see that causing issues). But just not needing the id to replace would be ideal.

If any changes like that are off the table can someone confirm if the downloadable id can be trusted to be the same as long as it exists? If all I gotta do is scrape the id off the website after the first upload and store it on my end that's not too bad at all.

I'd like to bump this issue up...

Being able to automate the creation/update of downloadables will be a key issue for my team....

The setDownloadable function in GameSparksRestApi.cs (Unity api) properly replaces existing downloadables of the same name. So automated creation/update works fine now.

I'll have to look closer at their cs code...

thanks for the tip!

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
 public class Upload
    public void UploadFile()
       System.Net.ServicePointManager.ServerCertificateValidationCallback +=
  delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
  System.Security.Cryptography.X509Certificates.X509Chain chain,
  System.Net.Security.SslPolicyErrors sslPolicyErrors)
  return true; // **** Always accept
       private static string HOST = "";

       private static string REST_URL = HOST + "rest/";
       string apiKey, string username, string password, string shortCode, string fileName;
       string url = REST_URL + apiKey + "/binarycontent/" + shortCode;

  String ret = null;
       FileParameter param = new FileParameter(GetBytesFromFile(fileName), Path.GetFileName(fileName));
  param.FileName = fileName;

  IDictionary<string, object> postParams = new Dictionary<string, object>();
  postParams.Add("binaryContentFile", param);

  return MultipartFormDataPost(url, postParams, username, password);


Is there an easy way to do this from the Gamespark Unity SDK?

I have a bunch of level data file I would like to upload to the "Downloadables" section but I can't figure out an easy way to do it, am I missing something?

See my previous comment, this is exactly what I needed as well. Code is included in comment

I'm asking for an official solution on the unity sdk not for a workaround :) but thanks

Any help from the official support?

Hi Enrico,

There is basic support for this within the Unity Editor. If you click "GameSparks" in the top bar in the editor and then select "Rest Api" the following window will pop up.


You can then add the shortCode, your portal userName and password and selected file. Then hit POST. This file should now be in your Downloadables on the portal. You can also upload directly through our documentation page here.



1 person likes this
Login to post a comment