Help Center > > Developer Guide> SDK Usage Guide on the Application Side> Huawei IoT Platform Java SDK Usage Guide> Calling Service APIs

Calling Service APIs

Updated at: Aug 28, 2019 GMT+08:00

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.

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel