{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":222,"path":"api-reference/cllent-mobile-api-reference/NowAPIServiceAndroidInterface.md","title":"NowAPIService interface - Android","bundle":null,"doc_type":null,"release":"australia","body":"\n# NowAPIService interface- Android\n\nThe NowAPIService interface provides the ability to perform requests on a specified ServiceNow REST API.\n\n**Note:** Guest users only work for the NowAPIService interface if the REST API being accessed is configured for guest users.\n\n|Name|Type|Description|\n|----|----|-----------|\n|configuration|[NowServiceConfiguration](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/NowServiceConfigurationAndroidAPI.md)|Service configuration to associate with the protocol.|\n\n**Parent Topic:**[Mobile SDK - Android](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/MobileSDKAndroidAPI.md)\n\n## NowAPIService - data\\(endpoint: NowAPIService.Endpoint, queryParams: QueryParams, headers: Headers, body: String\\)\n\nCalls the specified REST API on the specified ServiceNow instance.\n\n<table id=\"table_u3p_dkt_4pb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nendpoint\n\n</td><td>\n\nNowAPIService.Endpoint\n\n</td><td>\n\nREST endpoint to call.\n\n</td></tr><tr><td>\n\nqueryParams\n\n</td><td>\n\nQueryParams\n\n</td><td>\n\nOptional. Query parameter object that contains the query parameters to pass in the REST call.Default: null\n\n</td></tr><tr><td>\n\nheaders\n\n</td><td>\n\nHeaders\n\n</td><td>\n\nOptional. Headers object that contains the headers to pass in the REST call.Default: null\n\n</td></tr><tr><td>\n\nbody\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Object that contains the request body and content type to pass into the REST call.Default: null\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|[Call](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/CallAndroidInterface.md)&lt;[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/)&gt;|Return results from the called REST endpoint.|\n\n```\nsuspend fun loadCases(): List<CaseItem> = withContext(Dispatchers.IO) {\n  val apiService = nowServiceManager.getNowAPIService()\n\n  val result = runCatching {\n    val response = apiService.data(NowAPIService.Endpoint(\n      relativePath = CASES_API,\n      requestMethod = HttpMethod.GET,\n      requireAuth = true)\n    ).execute()\n\n    val byteArray = response.body ?: throw Exception(\"Null Result\")\n    val buffer = Buffer()\n    val reader = JsonReader.of(buffer.write(byteArray))\n    val listType = Types.newParameterizedType(\n      List::class.java,\n      CaseItem::class.java\n    )\n\n    val resultType = Types.newParameterizedType(\n      ResultResponse::class.java,\n      listType\n    )\n    val adapter = moshi.adapter<ResultResponse<List<CaseItem>>>(resultType)\n    adapter.fromJson(reader)\n  }\n\n  if (result.isSuccess) {\n      result.getOrNull()?.result ?: throw Exception(\"Cases not in response\")\n  } else {\n      throw result.exceptionOrNull() ?: Exception(\"Error Cases\")\n  }\n}\n```\n\n"}}