Help with API code

0 favourites
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hi everyone.

    I need to include an API code in the game I'm developing and I have no idea how to do it. Could someone be so kind as to give me some tips on this? I can share the code, which is quite small. Thanks in advance for any help.

  • Any good soul willing to give a quick lesson on this process of linking an api in the construct game, please?

  • Hi. If it is not a secret it would be better to say which API you want to pull.

    I think the response will be higher.

    For example, I can't give lessons, but if I've worked with such an API, I'll share an example.

  • Hi Igor. Thanks for answering

    Here's a copy of the code I need to include in the game:

    POST
    
     {
     “method": ‘game_launch’,
     “agent_code": ******
     “agent_token": ‘0123456789’,
     “user_code": ‘test’,
     “provider_code": ‘TEST’,
     “game_code": ‘XXXXXXXX’, // Optional - When it is empty, lobby url is returned.
     “lang": ”en”
     }
    
    //which will return a url already logged into the session
    
    RETURN
    {
     “status": 1,
     “msg": ‘SUCCESS’,
     “launch_url": ”http://”
     }
    
    //where it will play your system will take data and insert it via webhook on my site
    
    Collect balance data
    POST
    {
     “method": ‘money_info’,
     “agent_code": ******
     “agent_token": ‘0123456789’,
     }
    RETURN
     {
     “status": 1,
     “msg": ‘SUCCESS’,
     “agent": {
     “agent_code": ******
     “balance": 1000000,
     }
     }
    
    //To change the balance is
    POST
     {
     “method": ‘win’,#Lose
     “agent_code": ******
     “agent_token": ‘0123456789’,
     “user_code": ‘test’,
     “amount": 10000
     }
    RETURN
    {
     “status": 1,
     “msg": ”SUCCESS”
     “agent_balance": 100000,
     “user_balance": 10000
     }
    
  • It's quite simple, you constantly send a POST request with a string in the string and put the data as they require. The only thing is that you will need to format this string with data correctly (quotation marks or brackets, etc).

    You should get a response and this response will contain a string with data in the format they specify. You parse this string into the data you need via tokenat.

    And so constantly, of course in the code you need to provide for communication failures and errors, so that you do not spam them with requests too often otherwise they at the server level will block you.

    I have attached a screenshot with a piece of code for the POST request and response, this is an example data you should enter your own.

  • Thanks Igor, but it is greek for me :(

    I will try to understand. Thank you anyway

  • Just to see if I'm on the right track. I took this example from another post.

    I'd have to include the data and then send the post as shown, right?

    POST
    
     {
     “method": ‘game_launch’,
     “agent_code": ******
     “agent_token": ‘0123456789’,
     “user_code": ‘test’,
     “provider_code": ‘TEST’,
     “game_code": ‘XXXXXXXX’, // Optional - When it is empty, lobby url is returned.
     “lang": ”en”
     }
    
    //which will return a url already logged into the session
    
    RETURN
    {
     “status": 1,
     “msg": ‘SUCCESS’,
     “launch_url": ”http://”
     }
    
    

    EDITED:

    Then the server will return the information that I'm logged in, right? Do I use this information to open this URL or do I not need to do anything with it?

  • Just to see if I'm on the right track. I took this example from another post.

    I'd have to include the data and then send the post as shown, right?

    Hi. Yes you are on the right track, you have collected all the data you need into a json object and you are passing this object. After that the server should send you a response like this. (status1msgSUCCESSlaunch_urlhttp://google.com)

    The question remains whether the data in this object looks the way the server expects it to look or not.

    But I'm doing it easier, I'm just like on the screen.

  • Thanks for the explanations and the suggestion. I'll use variables to make it more handy.

    The right thing to do would be to create an empty template, with just a few buttons and fields, so that I can check that everything is working. Then I'll post C3 here for you to take a look at and perhaps make some changes or improvements. Is that ok?

  • I don't know how to help anymore, you just need to put together a small template and try it until you succeed.

  • I have a question about how to work with returns. How do I check if the message is equal to SUCCESS so that I can send the second POST?

    EDITED:

    In your example you used URL as URL instead of the http address. Is this a variable that is not declared with the others?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • In fact, things are different from what I had understood. The first POST is made by the game portal server and returns the URL where the game will be located, with the user already logged into the portal.

    RETURN
    {
     “status": 1,
     “msg": ‘SUCCESS’,
     “launch_url": ”http://...”
     }
    

    Then I need to check the credit balance and then update the balance at the end of the game

    //Get Account Balance
    curl --location 'https://...' \
    --header 'Content-Type: application/json' \
    --data '{
    “method": ‘user_balance’,
    “user_code": ”000”
    }'
    
    
    //Define whether you won or lost
    curl --location 'https://...' \
    --header 'Content-Type: application/json' \
    --data ' {
    “method": ‘transaction’,
    “user_code": ‘000’,
    “game_type": ******
    “slot": {
    “provider_code": ******
    “game_code": ******
    “type": ‘BASE’,
    “used_credit": 10,
    “win_credit": 0,
    “txn_id": *****
    }
    
  • I have a question about how to work with returns. How do I check if the message is equal to SUCCESS so that I can send the second POST?

    Посмотрите, содержат ли полученные данные необходимые ключи, и если да, разберите их.

    Construct3 имеет множество системных функций для разбора текста.

    EDITED:

    In your example you used URL as URL instead of the http address. Is this a variable that is not declared with the others?

    It's just a variable containing the address, you can insert a string with the site address.

  • In fact, things are different from what I had understood.....

    Maybe you should find someone to solve this problem for you, I'm sure that any API has documentation and an example of how to use it, not the pieces you give here.

    Perhaps there is a colleague who is free now, I don't have time to solve your problem. I thought some general advice would help, but I see that in this case someone needs to sit down and do the work.

  • Could someone please help me with this? I don't need anyone to do anything for me, just explain how to do to identify a RETURN and how to check information (balance(using GET I presume)). Please,step by step. To update the data using POST, I think that the way it was explained, I could understand. Thanks.

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