Sign In Register

How can we help you today?

Start a new topic
Answered

Examples for REST API window in Unity

Are there any examples for the REST API within Unity?

Stuff like adding, removing, or editing documents from NoSQL via JSON or other cool things?

What is the shortcode for? Does it work just like this documentation says? I just put in the request in there?


Also, stupid question, in Unity's Rest API window, it says username. Is that just my email I'm using? I can't find my username anywhere.


Best Answer
Editing the game-config from a client project would be a really bad idea.
Especially since you can preform the same tasks using custom-log events with the benefit of sending that data over secure websocekts. You dont want to me sending your api-key and server-secret from the client when you dont need to.

However, an alternative could be to create your own REST api using one of your own custom callbacks.
You can send the post-url using UnityWebRequests.

The REST api window in unity is only intended for testing, so the username and password are a player's username and password, not yours as the developer.

Hope that helps,
Sean

 


Answer
Editing the game-config from a client project would be a really bad idea.
Especially since you can preform the same tasks using custom-log events with the benefit of sending that data over secure websocekts. You dont want to me sending your api-key and server-secret from the client when you dont need to.

However, an alternative could be to create your own REST api using one of your own custom callbacks.
You can send the post-url using UnityWebRequests.

The REST api window in unity is only intended for testing, so the username and password are a player's username and password, not yours as the developer.

Hope that helps,
Sean

 

thanks the reply

      var client = new RestClient();
  client.BaseUrl = new Uri(GameSparksSettings.PortalUrl);
  client.Authenticator = new HttpBasicAuthenticator(strGSUSER, strGSPASS);
  client.Timeout = nTimeout;
       
       var request = new RestRequest();

  request.Method = Method.POST;
  request.RequestFormat = DataFormat.Json;
  request.AlwaysMultipartFormData = true;
  request.Timeout = nTimeout;
  request.Resource = "rest/games/" + strGSAPIKEY + "/mongo/preview/" + strGSCOLLECTION + "/update";

       
        string strGML = "";

  Parameter jsonDOC = new Parameter();
  jsonDOC.ContentType = "application/json";
  jsonDOC.Type = ParameterType.GetOrPost;
  jsonDOC.Name = "query";
  jsonDOC.Value = "{\"BrandId\" : { \"$oid\" : \"" + strBRANDID + "\"}, \"GameId\" : { \"$oid\" : \"" + strGAMEID + "\"}}";
  request.AddParameter(jsonDOC);

  Parameter jsonDOC2 = new Parameter();
  jsonDOC2.ContentType = "application/json";
  jsonDOC2.Type = ParameterType.GetOrPost;
  jsonDOC2.Name = "update";
  jsonDOC2.Value = "{$set : {\"setlist." + strSETINDEX + ".GMLScript\":\"" + strGML + "\"}}";
  request.AddParameter(jsonDOC2);


  System.Console.WriteLine("START  = " + DateTime.Now.ToLongDateString() + " @ " + DateTime.Now.ToLongTimeString());

  IRestResponse response = client.Execute(request);
           bool bEmptyResponse = (string.Compare(response.Content, "[]", true) == 0);

 

       var client = new RestClient();
  client.BaseUrl = new Uri(GameSparksSettings.PortalUrl);
  client.Authenticator = new HttpBasicAuthenticator(strGSUSER, strGSPASS);
  client.Timeout = nTimeout;
       
       var request = new RestRequest();

  request.Method = Method.POST;
  request.RequestFormat = DataFormat.Json;
  request.AlwaysMultipartFormData = true;
  request.Timeout = nTimeout;
  request.Resource = "rest/games/" + strGSAPIKEY + "/mongo/preview/" + strGSCOLLECTION + "/update";

       
        string strGML = "";

  Parameter jsonDOC = new Parameter();
  jsonDOC.ContentType = "application/json";
  jsonDOC.Type = ParameterType.GetOrPost;
  jsonDOC.Name = "query";
  jsonDOC.Value = "{\"BrandId\" : { \"$oid\" : \"" + strBRANDID + "\"}, \"GameId\" : { \"$oid\" : \"" + strGAMEID + "\"}}";
  request.AddParameter(jsonDOC);

  Parameter jsonDOC2 = new Parameter();
  jsonDOC2.ContentType = "application/json";
  jsonDOC2.Type = ParameterType.GetOrPost;
  jsonDOC2.Name = "update";
  jsonDOC2.Value = "{$set : {\"setlist." + strSETINDEX + ".GMLScript\":\"" + strGML + "\"}}";
  request.AddParameter(jsonDOC2);


  System.Console.WriteLine("START  = " + DateTime.Now.ToLongDateString() + " @ " + DateTime.Now.ToLongTimeString());

  IRestResponse response = client.Execute(request);
           bool bEmptyResponse = (string.Compare(response.Content, "[]", true) == 0);

Login to post a comment