---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# NowChat API - iOS

# NowChat API - iOS {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 1 minute to read

The NowChat API is a top-level global API that enables users to
instantiate a NowChat service instance.

## NowChat - makeChatService(instanceUrl: URL, delegate: NowChatServiceDelegate?) {#ariaid-title2}

Creates an instance of NowChatService with the specified configuration.
Note:  
You must initialize the SDK prior to calling this function or the completion block is called with a `sdkNotConfigured` error. To initialize the SDK, call the `NowSDK.configure()` method with the desired configuration.
{#NChat-makeChatService-pub_S_O_O__table_pft_qzv_kqb__entry__3}

| Name | Type | Description |
|-|-|-|
| instanceUrl | URL | URL of the ServiceNow instance providing chat services. |
| delegate | NowChatServiceDelegate | Optional. Delegate object that implements the NowChatServiceDelegate protocol. |
[Table 1. Parameters]

{#NChat-makeChatService-pub_S_O_O__table_pft_qzv_kqb} {#NChat-makeChatService-pub_S_O_O__table_qft_qzv_kqb__entry__2}

| Type | Description |
|-|-|
| AnyPublisher\<[NowChatService](https://servicenow-prod.fluidtopics.net/V5g0WnyO4pFrtA3ShZvYew#NowChatServiceiOSAPI "The NowChatService class provides Virtual and Live Agent chat capabilities."), NowServiceError\> | If successful, returns an initialized NowChatService object. If it fails, returns a NowServiceError object. |
[Table 2. Returns]

{#NChat-makeChatService-pub_S_O_O__table_qft_qzv_kqb}  
The following code example shows how to call this function.

    ....
    guard 
      let jwtUrl = URL(string: "http://xx.xx.xx.xxx:8080"),
      let instanceUrl = URL(string: "https://instance.service-now.com") else {
        return
      }
    // AuthorizationProvider -- struct conforming to NowSDKAuthorizationProviding protocol
    let authorizationProvider = AuthorizationProvider(userEmail: "sdk@servicenow.com", jwtProviderUrl: jwtUrl, clientId: "deb8756b452d201039231ca568f26511")
            
    // PermissionProvider -- class conforming to DevicePermissionDelegate protocol
    let permissionProvider = PermissionProvider()
    let config = NowSDKConfiguration(authorizationProvider: authorizationProvider, permissionDelegate: permissionProvider, logLevel: .debug)
    	
    do {
      try NowSDK.configure(with: config)
      let chat = setup(with: instanceUrl)
    } catch {
      // Return ConfigurationError.sdkError(error)
    }
    .....

    func initializeChatService(with instanceURL: URL) -> AnyPublisher<NowService, ConfigurationError> {
      NowChat.makeChatService(instanceUrl: instanceURL, delegate: nil)
      .mapError { .sdkError($0) }
      .map { $0 as NowService }
      .eraseToAnyPublisher()
    }

## NowChat - makeChatService(instanceUrl: URL, delegate: NowChatServiceDelegate?, completion:
@escaping ((Result\<NowChatService, NowServiceError\>) -\> Void)) {#ariaid-title3}

Creates an instance of `NowChatService` with the specified
configuration, and once complete, calls the specified completion handler.
Note:  
You must initialize the SDK prior to calling this function or the completion block is called with a `sdkNotConfigured` error. To initialize the SDK, call the `NowSDK.configure()` method with the desired configuration.
{#NChat-makeChatService_S_O_O__table_nv2_5xv_kqb__entry__3}

| Name | Type | Description |
|-|-|-|
| instanceUrl | URL | URL of the ServiceNow instance providing chat services. |
| delegate | NowChatServiceDelegate | Optional. Delegate object that implements the NowChatServiceDelegate protocol. |
| completion | @escaping ((Result\<[Now​Chat​Service](https://servicenow-prod.fluidtopics.net/V5g0WnyO4pFrtA3ShZvYew#NowChatServiceiOSAPI "The NowChatService class provides Virtual and Live Agent chat capabilities."), Now​Service​Error\>) -\> Void) | Completion handler that is called containing either an initialized `NowChatService` instance or a `NowServiceError` indicating why the initialization failed. |
[Table 3. Parameters]

{#NChat-makeChatService_S_O_O__table_nv2_5xv_kqb} {#NChat-makeChatService_S_O_O__table_ov2_5xv_kqb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 4. Returns]

{#NChat-makeChatService_S_O_O__table_ov2_5xv_kqb}  
The following code example shows how to call this function.

    func initializeChatService() {
      NowChat.makeChatService(instanceUrl: instanceUrl, delegate: self) { [weak self] result in
        guard let self = self else { return }
                
        switch result {
        case .success(let service):
          self.chatService = service
        case .failure(let error):
          debugPrint("Creating the chat service failed with error: \(error)")
        }
        self.viewState = self.makeViewState()
      }
    }


