API: Step-by-Step

Introduction

In this section, we tell you about how you can use the API to develop your projects.
This step-by-step guide describes the step-by-step process of working with connecting to the API and performing some actions.


Connect to API and Check API Status

Most requests to our platform are made through API. To work with any method or platform object, you should send a POST-request of the following form:

https://cp.ocugine.pro/api/OBJECT_NAME/METHOD_NAME/

So, in order to receive any data or perform actions with API objects that are tied to your project, you need to fulfill the requests using the above method. However, before you start working with API, you must make sure that it is connected and available for work.

To do this, you need to send a POST-request by using following API URL:

https://cp.ocugine.pro/api/state/init/

As with all API methods, the server will return a response in the form of a JSON-object. If the server did not return the JSON-object in response to your request, then most likely the services are currently unavailable.

If everything went well and the connection to the server is present, then in response to the request that you sent earlier, you should receive the following response:

{
    "complete": true,
    "message": null,
    "data": {
        "version": "0.9.1b",
        "build": 902,
        "developer": "Intelligence Solutions",
        "url": "https://cp.ocugine.pro/api/",
        "online": true
    }
}

This means that everything went well. You can also get information about the current version of the platform in this object.


Check API Keys

To identify your application on the server, you must send the following data as arguments to the POST request:

Name Type Desc
app_id double Your Application ID. You can see your Application ID here.
app_key string Your Application Client Key. You can see your Client Key here.

Send this data to the following URL:

https://cp.ocugine.pro/api/utils/check_keys/

This way you can check your APP_ID and CLIENT_KEY. If your data is valid, server returns:

{
    "complete": true,
    "message": "",
    "data": []
}

API User Authentication

In order for your users to work with their data inside your application, you must authorize it. To do this, follow these steps:

  • Get Authentication Links using method OAuth.get_link;
  • Open this link in new browser window for end-user from your application;
  • After the user has closed the window, turn to the method of obtaining the token.

So, to generate a link for authorization of the user in the application, it is necessary to send the following POST request:

https://cp.ocugine.pro/api/oauth/get_link/

The request parameters should include:

Name Type Desc
app_id double Your Application ID. You can see your Application ID here.
app_key string Your Application Client Key. You can see your Client Key here.
grants (Not necessary) array / string Array of parameters for access request, or "all" for requesting all rights.
lang (Not necessary) string The language in which the server response comes. The default is determined automatically.

Request Data Example

{
    "app_id": 1,
    "app_key": "example_key",
    "grants": ["profile", "achivements", "cloud_data"]
}

Response Example

{
    "complete": true,
    "auth_url": "https://cp.ocugine.pro/oauth/login/?key=AUTH_KEY",
    "auth_key": "AUTH_KEY"
}

After receiving the link for authorization, you must redirect your user to this link. Remember your AUTH_KEY inside your application to get token. If successful, you can get a user token for your application using Auth Key.

To obtain a token, send a POST request to the following URL:

https://cp.ocugine.pro/api/oauth/get_token/

The request parameters should include:

Name Type Desc
app_id double Your Application ID. You can see your Application ID here.
app_key string Your Application Client Key. You can see your Client Key here.
auth_key string Auth Key. Then you get your token - auth key will be removed
lang (Not necessary) string The language in which the server response comes. The default is determined automatically.

After that, you will receive the following response from the server:

{
    "complete": true,
    "access_token": "TOKEN_EXAMPLE",
    "grants": "all"
}

When you received an access token, you can use them, to get access for objects with requested grants. For example, if you are requested a grant "profile" for your application, your users can find other players in your game.


Send API Requests

The user token should be transferred in those cases when he needs to work with his data. In this case, we mark in the documentation those methods for which a token is required.

Now that you have everything you need, you can fully work with all API methods.

For example, you can send request and reset user token:

https://cp.ocugine.pro/api/oauth/logout/

The request parameters should include:

Name Type Desc
access_token string User token.

API Objects Documentation

In order to work most effectively with all the API capabilities, you need to study the documentation on working with each object of our platform, which you can access through this interface.

You can learn more about every object:

If you have any questions about API - you can ask us here.


SDK (API Wrappers)

To work with API - you can use our SDK to not access the services directly. They will help you establish the connection between the platform and the final product in just a few lines of code.
You can see more information about SDK here.