NowChat API - iOS

  • Release version: Australia
  • Updated March 12, 2026
  • 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?)

    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.
    Table 1. Parameters
    Name Type Description
    instanceUrl URL URL of the ServiceNow instance providing chat services.
    delegate NowChatServiceDelegate Optional. Delegate object that implements the NowChatServiceDelegate protocol.
    Table 2. Returns
    Type Description
    AnyPublisher<NowChatService, NowServiceError> If successful, returns an initialized NowChatService object. If it fails, returns a NowServiceError object.

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

    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.
    Table 3. Parameters
    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, Now​Service​Error>) -> Void) Completion handler that is called containing either an initialized NowChatService instance or a NowServiceError indicating why the initialization failed.
    Table 4. Returns
    Type Description
    None

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