Sign In Register

How can we help you today?

Start a new topic

REST API Put Property

Hi, I'm trying to change one of my property's fields using REST api in cloud code with put request. When I want to set the body of the PUT, it doesn't work and gives me this error:

json can't serialize type : class org.mozilla.javascript.ConsString 


what should I do?





var myProperty = "testtesttest_1";


var url = "https://config2.gamesparks.net/restv2/game/{apikey}/config/~properties/" + myProperty;

var propertyId = "/~properties/" + myProperty;


body = 

{

  "@id": propertyId,

  "description": "Test rest api",

  "name": myProperty,

  "shortCode": myProperty,

  "value": 

  {

      "CoinReward_ForMatch": 15000,

      "CoinReward_Others": 3,

      "TheBool": false

  }

};


var TheHttpUrl = Spark.getHttp(url);

TheHttpUrl.setBasicAuth(myUsername, myPassword);

TheHttpUrl.setHeaders({"Accept": "application/json"});

TheHttpUrl.setHeaders({"Content-Type": "application/json"});

var response = TheHttpUrl.putJson(body);

var response_string = response.getResponseJson();

var response_code = response.getResponseCode();


2 people have this question

Facing same issue, any way to resolve?

try this 
body = JSON.parse(JSON.stringify(body));

Login to post a comment