---
sourceDocument: Xanadu API 참조
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ko-KR/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - ko-KR

ft:publication_title :

    - Xanadu API 참조

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# 인스턴스에서 공용 REST API와 ServiceNow 상호 작용

# 인스턴스에서 공용 REST API와 ServiceNow 상호 작용 {#ariaid-title1}

* 릴리스 버전: Xanadu
* 
* 업데이트 날짜 2024년 08월 01일
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 소요 시간: 3분

Mobile SDK 애플리케이션이 인스턴스에서 ServiceNow 공용 REST API를 호출할 수 있도록 Android 하는 기능을 제공합니다.
[NowAPIService](https://servicenow-prod.fluidtopics.net/qSnkK~UWDRSbjJUx7VfJjg#NowAPIServiceAndroidInterface "NowAPIService 인터페이스는 지정된 ServiceNow REST API에서 요청을 수행하는 기능을 제공합니다.") API를 사용하면 기본 ServiceNow 공용 [REST API](https://servicenow-prod.fluidtopics.net/Rv9pynAqgtVdOYWnS774Tg "REST 인터페이스를 사용하여 인스턴스의 데이터에 액세스합니다.")와 상호 작용하거나 인스턴스 내에서 사용자 지정 REST API를 작성하고 애플리케이션에서 호출할 수 있습니다Android.

REST API를 ServiceNow 호출하기 전에[makeNowAPIService()](https://servicenow-prod.fluidtopics.net/TonaY~tponLeovFZUT6Uwg#NDataSDK-makeNowAPIService_S_O_O "NowAPIService 서비스의 인스턴스를 만들고 초기화합니다. 이 서비스를 사용하면 인스턴스에서 노출하는 공용 REST API에 액세스할 수 있습니다 ServiceNow .") 메서드를 호출하여 서비스 인스턴스를 만들어야 합니다. 성공하면 서비스 인스턴스가 콜백에 반환되고, 그렇지 않으면 오류가 throw됩니다.  
다음은 NowAPIService 개체를 초기화하는 방법을 보여 줍니다.

    /**
     * Helper class used to handle different Now service instances. It has an application scope or is Singleton
     */
    @Singleton
    class SdkManager @Inject constructor() {

        private var nowApiService: NowAPIService? = null

        /**
         * Create the NowAPIService once in the lifetime of the application inside the Application class or another manager class
         * that will be injected into other classes via dagger/hilt.
         * NowAPIService should be created after initializing the NowSDK
         */
        suspend fun getNowApiService(): NowAPIService? {
            if (nowApiService != null) return nowApiService

            return NowDataSDK.makeAPIService(URL("https://instance-name.service-now.com")).getOrThrow()
                .also { this.nowApiService = it }
        }

    }

NowAPIService 개체가 초기화되면 NowAPIService [data()](https://servicenow-prod.fluidtopics.net/qSnkK~UWDRSbjJUx7VfJjg#NAPIServ-data_S_S_S_S "지정된 ServiceNow 인스턴스에서 지정된 REST API를 호출합니다.") 메서드를 사용하여 호출할 REST 엔드포인트와 모든 관련 매개 변수를 지정합니다.

     suspend fun makeNowApiCall() {
      val apiService = sdkManager.getNowApiService()

      val apiPath = "api/now/table/sn_customerservice_case"
      val endpoint = NowAPIService.Endpoint(HttpMethod.GET, apiPath, true)
      val fieldNames = "sys_id,number,short_description,number,priority,state," +
        "opened_at,account.name,account.number,contact.name,contact.email," +
        "contact_type,assignment_group.name,assigned_to.name"

      val queryParamsMap = mapOf("sysparm_fields" to fieldNames, "sysparm_limit" to "10")

      val queryParams = QueryParams.Builder().addAll(queryParamsMap).build()

      val response = runCatching {
        apiService?.data(endpoint = endpoint, queryParams = queryParams)?.execute()
      }

      if (response.isSuccess) {
        val resultString = response.getOrNull()?.body?.let { String(it) }
      } else {
        // Handle error
      }
    }


