Common API Methods

Last Updated on : 2023-11-02 06:24:20download

Server APIs are supported by the ITuyaSmartRequest class. Certain of these APIs are supplied with Session.

Common API methods are called with TuyaHomeSdk.getRequestInstance().

APIs with Session

<T> void requestWithApiName(String apiName, String version, Map<String, Object> postData, Class<T> object, final ITuyaDataCallback<T> callback);

Parameters

Parameter Description
apiName The name of an API.
version The version number of an API.
postData The request parameters.
object The data object returned by the server.
callback The callback.

Example

Functional description apiName version postData
Query the list of countries. tuya.m.country.list v1.0 None
Map<String, Object> postData = null;

TuyaHomeSdk.getRequestInstance().requestWithApiName("tuya.m.country.list", "1.0", postData, String.class, new ITuyaDataCallback<String>() {
    @Override
    public void onSuccess(String result) {
        Log.i("TAG" , result);
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        Log.i("TAG" , errorCode);
    }
});

APIs without Session

<T> void requestWithApiNameWithoutSession(String apiName, String version, Map<String, Object> postData, Class<T> object, final ITuyaDataCallback<T> callback);

Parameters

Parameter Description
apiName The name of an API.
version The version number of an API.
postData The request parameters.
object The data object returned by the server.
callback The callback.

Example

Functional description apiName version postData
Query a list of countries. tuya.m.country.list v1.0 None
Map<String, Object> postData = null;

TuyaHomeSdk.getRequestInstance().requestWithApiNameWithoutSession("tuya.m.country.list", "1.0", postData, String.class, new ITuyaDataCallback<String>() {
    @Override
    public void onSuccess(String result) {
        Log.i("TAG" , result);
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        Log.i("TAG" , errorCode);
    }
});