Updated on 2022-02-24 GMT+08:00

Calling Service APIs

You can call other service APIs only after the NorthApiClient instance is configured by following the instructions provided in Initializing and Configuring Certificates. The following APIs are used as an example to describe how to call service APIs:

Authentication

1
2
3
4
5
6
7
8
//After the NorthApiClient instance is obtained, use the NorthApiClient to obtain the authentication instance.
Authentication authentication = new Authentication(northApiClient);

//Call the service API provided by the authentication instance, for example, getAuthToken.
AuthOutDTO authOutDTO = authentication.getAuthToken();

//Obtain the required parameters from the returned authOutDTO, for example, accessToken.
String accessToken = authOutDTO.getAccessToken();

Subscription

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
//After the NorthApiClient instance is obtained, use the NorthApiClient to obtain the subscription instance.
SubscriptionManagement subscriptionManagement = new SubscriptionManagement(northApiClient);

//Set the first input parameter SubDeviceDataInDTO in the subDeviceData API.
SubDeviceDataInDTO sddInDTO = new SubDeviceDataInDTO();
sddInDTO.setNotifyType("deviceDataChanged");
//Modify the callback IP address and port number based on site requirements.
ddInDTO.setCallbackUrl("https://XXX.XXX.XXX.XXX:8099/v1.0.0/messageReceiver");
try {
   //Call the service API provided by the subscription class instance subscriptionManagement, for example, subDeviceData.
    SubscriptionDTO subDTO = subscriptionManagement.subDeviceData(sddInDTO, null, accessToken);
    System.out.println(subDTO.toString());
} catch (NorthApiException e) {
    System.out.println(e.toString());
}

Device Registration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
//After the NorthApiClient instance is obtained, use the NorthApiClient to obtain the device management instance.
DeviceManagement deviceManagement = new DeviceManagement(northApiClient);

//Set the first input parameter RegDirectDeviceInDTO2 in the regDirectDevice API. 
RegDirectDeviceInDTO2 rddInDTO = new RegDirectDeviceInDTO2();
String nodeid = "86370303XXXXXX"; //this is a test imei
String verifyCode = nodeid;
rddInDTO.setNodeId(nodeid);
rddInDTO.setVerifyCode(verifyCode);
rddInDTO.setTimeout(timeout);

//Call the service API provided by the device management instance deviceManagement, for example, regDirectDevice.
RegDirectDeviceOutDTO rddod = deviceManagement.regDirectDevice(rddInDTO, null, accessToken);

//Obtain the required parameters from the returned rddod structure, for example, deviceId.
String deviceId = rddod.getDeviceId();
NOTE:

For details about mandatory parameters, see Northbound Java SDK API Reference. If a parameter is not required, it can be left empty or set to null.