---
sourceDocument: Référence de l’API Xanadu
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/fr-FR/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - fr-FR

ft:publication_title :

    - Référence de l’API Xanadu

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Interagir avec l'API REST publique sur une ServiceNow instance

# Interagir avec l'API REST publique sur une ServiceNow instance {#ariaid-title1}

* Rversion finale: Xanadu
* 
* Mis à jour 1 août 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 1 minute de lecture

Il Mobile SDK fournit une fonctionnalité qui permet Android aux applications d'appeler l'API REST publique sur une ServiceNow instance.
À l'aide de l'API [NowAPIService](https://servicenow-prod.fluidtopics.net/1gaWh_B1G47NVk0nXBk8Tg#NowAPIServiceAndroidInterface "L’interface NowAPIService permet d’effectuer des demandes sur une API REST spécifiée ServiceNow ."), vous pouvez interagir avec n'importe quelle [API REST](https://servicenow-prod.fluidtopics.net/ognU3bWLgmSWsYoMIFICFA "Utilisez des interfaces REST pour accéder aux données de votre instance.") publique de base ServiceNow ou créer des API REST personnalisées au sein de l'instance et les appeler à partir de votre Android application.

Avant d'effectuer un appel à une ServiceNow API REST, vous devez appeler la méthode[makeNowAPIService()](https://servicenow-prod.fluidtopics.net/ziGYMG0hPLCyWHRk8Wn2nw#NDataSDK-makeNowAPIService_S_O_O "Crée et initialise une instance du service NowAPIService. Ce service vous permet d’accéder aux API REST publiques exposées par votre ServiceNow instance.") pour créer une instance du service. En cas de réussite, l'instance de service est renvoyée dans le rappel. Sinon, une erreur est générée.  
L'élément suivant montre comment initialiser un objet 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 }
        }

    }

Une fois l'objet NowAPIService initialisé, utilisez la méthode nowAPIService [data()](https://servicenow-prod.fluidtopics.net/1gaWh_B1G47NVk0nXBk8Tg#NAPIServ-data_S_S_S_S "Appelle l’API REST spécifiée sur l’instance spécifiée ServiceNow .") pour spécifier le point de terminaison REST à appeler et tous ses paramètres associés :

     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
      }
    }


