How do I use JSON to PUT data to the API?

0 favourites
  • 8 posts
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • Hello Constructors!

    I need some assistance with implementing this concept to Construct 3.

    Actuallu i will catch accessToken, roundId and gameId (from query) when the game opens.

    example info (for using):

    "roundId": "623050765ae70f4af678e2a1",

    "gameId": "6231e6bb7f94b624b3d570cb",

    "accessToken": eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MjI4OTA4NTczMDM5MDk1MDM1NzU0NDkiLCJpYXQiOjE2NDg1NTUyNzN9.9ICtNHu0EfsmV5GqiVnC9vAhvMCVPeypdO-O5A4RrrA

    will be sent with each point increase (put method):

    example request:

    const headers = {

    'Content-Type': 'application/json',

    'Authorization': accessToken will be here

    };

    const data = { roundId, gameId, score }

    const response = await axios.put('http://appearncash.com/rounds/completeRoundGame', data, { headers });

    The code which i wrote is something like in image 1, could you all please guide me me know how to resolve it?

    Here is the link to download the code

    https://drive.google.com/file/d/1WFx6wsY3NNLIrKh65A27VoHUf0p83yum/view?usp=sharing

    Your response in this regard will highly be appreciated. Thanks in advance!

  • I tried your link, but it says access is denied. Tried opening it yourself in an incognito browser tab.

    From my experience, you need to send all JSON fields as URL parameters, for example:

  • Thank you so much dop2000 for your support.

    Could you please assist me with AccessToken? should it be also send as a variable or what it is for?

  • I have tried with Ajax -> post to URL, but it isn't worked. even i tried the to put the accesstoken in the variables but haven't any good luck.

  • You missed a few "&" characters. Try this:

    "gameid=" & Game_ID & "&roundid=" & Round_ID & "&score=" & Score

    I'm not sure about the access token. If it needs to be sent in the same request then yes, you need to add it to the string.

    Did you check error messages in the console log? The problem may be with something else, for example it could be CORS issue because you are using http protocol.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I got it, I used these but unfortunately, it is still not working.

    Yeah, you are right that it might have a problem with HTTP requests.

    Do you know a complete succecced sample or tutorial of how to send and receive data through JSON from Mongodb?

  • Sorry, I don't, try googling.

    I would suggest checking the error message in the browser console first, otherwise you can only guess what the problem really is.

  • Dear dop2000 Thank you so much for your precious time and reply, your suggestion really assists me with it.

    I would like to know about the progress through which i got succeeded in the search.

    I used JSON and Ajax to post the data, as shown in the image below and the result is also.

    Thanks once again.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)