Common API Methods

Last Updated on : 2022-02-17 07:14:16download

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 API name.
version The version number of an API.
postData postData
object The data object returned by the server.
callback The callback.

Example

Functional description apiName version postData
Returns a list of countries. tuya.m.country.list 1.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 API name.
version The version number of an API.
postData The data sent by post.
object The data object returned by the server.
callback The callback.

Example

Functional description apiName version postData
Returns a list of countries. tuya.m.country.list 1.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);
    }
});