NowWeb API - iOS

  • Release version: Zurich
  • Updated July 31, 2025
  • 2 minutes to read
  • The NowWeb API is a top-level global API that enables uses to instantiate a NowWeb service instance.

    NowWeb - makeWebService(instanceUrl: URL) async throws

    Creates an instance of NowWebService using the previously specified configuration.

    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 NowSDK.configure() with the desired configuration.

    Table 1. Parameters
    Name Type Description
    instanceUrl URL URL of the ServiceNow instance whose web services are to be accessed by the service.
    Table 2. Returns
    Type Description
    NowWebService If successful, returns an initialized NowWebService object.
    NowServiceError Throws one of the following errors if the method fails.
    Possible values:
    • sdkNotConfigured
    • serviceConfigurationInvalid
    • serviceDisabled
    • serviceSettingsInvalid
    • serviceSettingsNotFound
    • serviceSettingsRetrievalFailed

    The following code example shows how to call this method.

    do {
        let service = try await NowWeb.makeWebService(instanceUrl: instanceUrl)
        self.webService = service
    } catch {
        debugPrint("Web Service creation failed with error: \(error.localizedDescription)") 
    }

    NowWeb - makeWebService(instanceUrl: URL, completion: @escaping ((Result<NowWebService, NowServiceError>) -> Void))

    Creates an instance of NowWebService using the previously specified configuration. When finished, calls the specified completion handler.

    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 NowSDK.configure() with the desired configuration.

    Table 3. Parameters
    Name Type Description
    instanceUrl URL URL of the ServiceNow instance whose web services are to be accessed by the service.
    completion @escaping ((Result<NowWebService, Now​Service​Error>) -> Void) Completion handler that is called with a Result<NowWebService, NowServiceError> containing either an initialized NowWebService instance or a NowServiceError indicating why the initialization failed.
    Table 4. Returns
    Type Description
    None

    func initializeNowSDK(userEmail: String) {
      currentUser = userEmail
      let sdkConfig = NowSDKConfiguration(authorizationProvider: self, permissionDelegate: self, logLevel: .debug)
            
      do {
          try NowSDK.configure(with: sdkConfig)
          configureAnalytics()
      } catch {
          debugPrint("Could not initialize NowSDK. Error: \(error.localizedDescription)")
      }
    }

    NowWeb - makeWebService(instanceUrl: URL)

    Creates an instance of NowWebService using the previously specified configuration.

    Note:
    This method has been deprecated. You should use the async/await implementation of the method instead.

    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 NowSDK.configure() with the desired configuration.

    Table 5. Parameters
    Name Type Description
    instanceUrl URL URL of the ServiceNow instance whose web services are to be accessed by the service.
    Table 6. Returns
    Type Description
    AnyPublisher<NowWebService, NowServiceError> If successful, returns an initialized NowWebService object. If it fails, returns a NowServiceError object.

    func initializeWebService() {
      NowWeb.makeWebService(instanceUrl: instanceUrl)
        .sink { completion in
          if case .failure(let error) = completion {
            debugPrint("Web Service creation failed with error: \(error.localizedDescription)")
          }
        } receiveValue: { [weak self] service in
            self?.webService = service
        }
        .store(in: &subscriptions)
      }