{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":243,"path":"api-reference/cllent-mobile-api-reference/NowDataAPIiOS.md","title":"NowData framework - iOS","bundle":null,"doc_type":null,"release":"australia","body":"\n# NowData framework- iOS\n\nThe NowData framework contains methods that enable the instantiation of NowData services, such as NowGraphQLService, NowTableService, NowAPIService \\(for custom APIs\\), andNowAttachmentService.\n\n**Parent Topic:**[Mobile SDK - iOS](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/MobileSDKiOSAPI.md)\n\n## NowData - makeApiService\\(instanceUrl: URL, path: String, completion: @escaping \\(\\(Result&lt;NowApiService, NowServiceError&gt;\\) -&gt; Void\\)\\)\n\nCreates an instance of NowApiService, and once complete, calls the specified completion handler.\n\n<table id=\"table_ff3_4pw_kqb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ninstanceUrl\n\n</td><td>\n\nURL\n\n</td><td>\n\nURL of the ServiceNow instance whose REST APIs are to be accessed by the service.\n\n</td></tr><tr><td>\n\npath\n\n</td><td>\n\nString\n\n</td><td>\n\nAPI path. For example, if the API call is `https://xxx.service-now.com/api/now/sg/incident`, the path is `/api/now/sg/incident`.\n\n</td></tr><tr><td>\n\ncompletion\n\n</td><td>\n\n@escaping \\(\\(Result​&lt;[NowApiService](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/NowAPIServiceiOSAPI.md), Now​Service​Error&gt;\\) -&gt; Void\\)\n\n</td><td>\n\nCompletion handler that is called with a `Result<NowApiService, NowServiceError>` containing either an initialized `NowApiService` instance or a `NowServiceError` indicating why the initialization failed.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThe following code example shows how to call this function.\n\n```\nlet path = \"api/now/sg\"\nlet apiPublisher = apiService(for: path)\n\nfunc apiService(for path: String) -> AnyPublisher<NowAPIService, ConfigurationError> {\n  guard let instanceURL else {\n    return Fail(error: ConfigurationError.invalidInstanceURL)\n    .eraseToAnyPublisher()\n  }\n  return Future { promise in\n    NowData.makeApiService(instanceUrl: instanceURL, path: path) { (result) in\n      promise(result.mapError { .sdkError($0) })\n    }\n  }\n  .eraseToAnyPublisher()\n}\n```\n\n## NowData - makeAttachmentService\\(instanceUrl: URL, completion: @escaping \\(\\(Result&lt;NowAttachmentService, NowServiceError&gt;\\) -&gt; Void\\)\\)\n\nCreates an instance of NowAttachmentService, and after completion, calls the specified completion handler.\n\n|Name|Type|Description|\n|----|----|-----------|\n|instanceUrl|URL|URL of the ServiceNow instance whose attachments are to be accessed by the service.|\n|completion|@escaping \\(\\(Result​&lt;[NowAttachmentService](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/NowAttachmentServiceiOSAPI.md), Now​Service​Error&gt;\\) -&gt; Void\\)|Completion handler that is called with a `Result<NowAttachmentService, NowServiceError>` containing either an initialized `NowAttachmentService` instance or a `NowServiceError` indicating why the initialization failed.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following code example shows how to call this function.\n\n```\n….\nguard \n  let jwtUrl = URL(string: \"http://13.57.38.237:8080\"),\n  let instanceUrl = URL(string: \"https://mobilecoresdk.service-now.com\") else {\n    return\n  }\n\n// AuthorizationProvider – struct conforming to NowSDKAuthorizationProviding protocol\nlet authorizationProvider = AuthorizationProvider(userEmail: \"sdk@servicenow.com\", jwtProviderUrl: jwtUrl, clientId: \"deb8756b452d201039231ca568f26511\")\n        \n// PermissionProvider – class conforming to DevicePermissionDelegate protocol\nlet permissionProvider = PermissionProvider()\nlet config = NowSDKConfiguration(authorizationProvider: authorizationProvider, permissionDelegate: permissionProvider, logLevel: .debug)\n\t\ndo {\n  try NowSDK.configure(with: config)\n  initializeAttachmentService (with: instanceURL)\n} catch {\n  // Return ConfigurationError.sdkError(error)\n}\n…..\n\nfunc initializeAttachmentService(instanceUrl: instanceURL) { result in\n  switch result {\n    case .success(let service)\n      self?.attachmentService = service\n    case .failure(let error)\n      debug.print(“Creating Attachment service failed with error: \\(error.localizedDescription)”)\n      self?.attachmentService = nil\n  }\n}\n\n```\n\n## NowData - makeGraphQLService\\(instanceUrl: URL, completion: @escaping \\(\\(Result&lt;NowGraphQLService, NowServiceError&gt;\\) -&gt; Void\\)\\)\n\nCreates an instance of NowGraphQLService, and once complete, calls the specified completion handler.\n\n|Name|Type|Description|\n|----|----|-----------|\n|instanceUrl|URL|URL of the ServiceNow instance providing GraphQL services.|\n|completion|@escaping \\(\\(Result​&lt;[NowGraphQLService](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/NowGraphQLServiceiOSAPI.md), Now​Service​Error&gt;\\) -&gt; Void\\)|Completion handler that is called with a `Result<NowGraphQLService, NowServiceError>` containing either an initialized `NowGraphQLService` instance or a `NowServiceError` indicating why the initialization failed.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nfunc initializeGraphQLService(instanceUrl: URL) {\n  makeGraphQLService(instanceUrl: instanceUrl) { [weak self] result in\n    switch result {\n    case .success(let service):\n      self?.graphQLService = service\n    case .failure(let error):\n      debugPrint(\"Creating GraphQL service failed with error: \\(error.localizedDescription)\")\n      self?.graphQLService = nil\n    }\n  }\n}\n```\n\n## NowData - makeTableService\\(instanceUrl: URL, completion: @escaping \\(\\(Result&lt;NowTableService, NowServiceError&gt;\\) -&gt; Void\\)\\)\n\nCreates an instance of NowTableService, and after it completes, calls the specified completion handler.\n\n|Name|Type|Description|\n|----|----|-----------|\n|instanceUrl|URL|URL of the ServiceNow instance whose tables are to be accessed by the service.|\n|completion|@escaping \\(\\(Result​&lt;[NowTableService](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/NowTableServiceiOSAPI.md), Now​Service​Error&gt;\\) -&gt; Void\\)|Completion handler that is called with a `Result<NowTableService, NowServiceError>` containing either an initialized `NowTableService` instance or a `NowServiceError` indicating why the initialization failed.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following code example shows how to call this function.\n\n```\nfunc initializeTableService(for instanceUrl: URL) {\n  makeTableService(instanceUrl: instanceUrl) { [weak self] result in\n    guard let self = self else { return }\n            \n    switch result {\n      case .success(let tableService):\n        self.tableService = tableService\n        // Create a Paginator that will iterate over pages of customer support cases. The Paginator's response type will be\n        // inferred from the Paginator's type definition (e.g. `Paginator<[CustomerServiceCase]>`).\n        self.paginator = tableService.paginator(from: Self.tableName, configuration: self.fetchConfiguration)\n        // Subscribe to the Paginator's publisher so we will be able to receive paged results.\n        self.subscribeToPaginatorPublisher()\n        // As we are now ready to start fetching data, inform the view controller.\n        self.onReady(self)\n      case .failure(let error):\n        debugPrint(\"Creating table service failed with error: \\(error.localizedDescription)\")\n        self.tableService = nil\n        self.paginator = nil\n    }\n  }\n}\n```\n\n"}}