{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":327,"path":"api-reference/developer-guides/mobsdk-and-interact-rest_api.md","title":"Interact with the public REST API on a ServiceNow instance","bundle":null,"doc_type":null,"release":"australia","body":"\n# Interact with the public REST API on a ServiceNow instance\n\nThe Mobile SDK provides functionality that enables Android applications to call the public REST API on a ServiceNow instance.\n\nUsing the [NowAPIService](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/NowAPIServiceAndroidInterface.md) API you can interact with any of the base ServiceNow public [REST APIs](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-apis/api-rest.md), or create custom REST APIs within the instance and call those from your Android application.\n\nBefore making a call to a ServiceNow REST API, you must call the[makeNowAPIService\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/NowDataSDKAndroidAPI.md) method to create an instance of the service. The service instance is returned in the callback if successful otherwise, an error is thrown.\n\nThe following shows how to initialize a NowAPIService object:\n\n```\n/**\n * Helper class used to handle different Now service instances. It has an application scope or is Singleton\n */\n@Singleton\nclass SdkManager @Inject constructor() {\n\n    private var nowApiService: NowAPIService? = null\n\n    /**\n     * Create the NowAPIService once in the lifetime of the application inside the Application class or another manager class\n     * that will be injected into other classes via dagger/hilt.\n     * NowAPIService should be created after initializing the NowSDK\n     */\n    suspend fun getNowApiService(): NowAPIService? {\n        if (nowApiService != null) return nowApiService\n\n        return NowDataSDK.makeAPIService(URL(\"https://instance-name.service-now.com\")).getOrThrow()\n            .also { this.nowApiService = it }\n    }\n\n}\n```\n\nOnce the NowAPIService object is initialized, use the NowAPIService [data\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/NowAPIServiceAndroidInterface.md) method to specify the REST endpoint to call and all of its associated parameters:\n\n```\n suspend fun makeNowApiCall() {\n  val apiService = sdkManager.getNowApiService()\n\n  val apiPath = \"api/now/table/sn_customerservice_case\"\n  val endpoint = NowAPIService.Endpoint(HttpMethod.GET, apiPath, true)\n  val fieldNames = \"sys_id,number,short_description,number,priority,state,\" +\n    \"opened_at,account.name,account.number,contact.name,contact.email,\" +\n    \"contact_type,assignment_group.name,assigned_to.name\"\n\n  val queryParamsMap = mapOf(\"sysparm_fields\" to fieldNames, \"sysparm_limit\" to \"10\")\n\n  val queryParams = QueryParams.Builder().addAll(queryParamsMap).build()\n\n  val response = runCatching {\n    apiService?.data(endpoint = endpoint, queryParams = queryParams)?.execute()\n  }\n\n  if (response.isSuccess) {\n    val resultString = response.getOrNull()?.body?.let { String(it) }\n  } else {\n    // Handle error\n  }\n}\n```\n\n"}}