API call

Updated at:

This topic describes how to call the Mobi OpenAPI.

You can call the Mobi OpenAPI using the official Alibaba Cloud software development kit (SDK). The following table lists the core parameters.

Parameter name

Parameter value

x-acs-product

mobi

x-acs-version

2024-04-11

RegionId

cn-beijing

Domain

mobi.aliyuncs.com

The following example shows how to call the Mobi OpenAPI using Java. The call logic is similar for SDKs in other languages.

Add the SDK reference

If you use Maven for dependency management, add the following code to reference the official Alibaba Cloud SDK.

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-core</artifactId>
    <version>4.7.3</version>
</dependency>
Note

For more information, see the official latest SDK.

Get a JWT token

The following code uses the official Alibaba Cloud SDK to call the JWT token generation API.

public class Example {

    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", "access key", "secret key");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();

        request.setSysDomain("mobi.aliyuncs.com");
        request.setSysProtocol(ProtocolType.HTTPS);
        request.setSysMethod(MethodType.POST);
        request.setSysVersion("2024-04-11");
        request.setSysAction("GenerateNativeUserToken");
        request.putQueryParameter("RegionId", "cn-beijing");
        request.putQueryParameter("WorkspaceId", "workspace id");
        request.putQueryParameter("Username", "username");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

Sample output

{"RequestId":"A5863101-****-****-****-46E2F54E7F60","Data":{"ExpiresIn":1800,"TokenType":"Bearer","RefreshToken":"","Scope":"profile email groups","AccessToken":"","RefreshExpiresIn":1800}}

Refresh a JWT token

The following code calls the JWT token generation API using the official Alibaba Cloud SDK.

public class Example {

    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", "access key", "secret key");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();

        request.setSysDomain("mobi.aliyuncs.com");
        request.setSysProtocol(ProtocolType.HTTPS);
        request.setSysMethod(MethodType.POST);
        request.setSysVersion("2024-04-11");
        request.setSysAction("RefreshNativeUserToken");
        request.putQueryParameter("RegionId", "cn-beijing");
        request.putQueryParameter("WorkspaceId", "17205062027392");
        request.putQueryParameter("RefreshToken", "refresh token");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

Sample output

{"RequestId":"AFC35A89-****-****-****-5B50C8D58BEB","Data":{"ExpiresIn":1800,"TokenType":"Bearer","RefreshToken":"","Scope":"profile email groups","AccessToken":"","RefreshExpiresIn":1800}}