# Getting Started with Sites Source: https://www.nianticspatial.com/docs/nsdk/how-to/sites/getting_started/?platform=swift ## Overview The Sites feature provides an API for querying hierarchical data in the Niantic Spatial platform. This guide will help you get started using Sites in your application. The Sites feature organizes data in a hierarchical structure: **Organization** -> **Site** -> **Asset**. Your application starts at the **Organization** level, which is resolved directly from your access token (see below). ## Requirements The Sites feature requires authentication using Niantic Spatial Auth. Your application must be authenticated before using any Sites API methods. To authenticate: 1. Ensure you have access the [Niantic Spatial Portal](https://scaniverse.nianticspatial.com) where you can manage your organizations, sites, and assets. 2. Set up auth in your application by following the [Auth guide](https://www.nianticspatial.com/docs/nsdk/auth_getting_started) ## Your access token and Organization Your access token is scoped to an Organization. That tells the SDK which Organization's data your app can access. Use `requestSelfOrganizationInfo` to get that Organization's information. For a code example, see [Get your organization](#2-get-your-organization). ## Basic Usage The Sites API follows a simple pattern: Make requests and handle results. All requests are asynchronous and return struct data that represents the Sites entity you are requesting. ### 1. Acquire a Sites Session ```swift let sitesSession = nsdkSession.acquireSitesSession() ``` ### 2. Get your organization Resolve your organization directly from the access token with `requestSelfOrganizationInfo`. ```swift let orgResult = try await sitesSession.requestSelfOrganizationInfo() if let organization = orgResult?.organizations.first { print("Organization: \(organization.name)") let orgId = organization.id } ``` ### 3. Query Sites Browse sites within an organization, using the `orgId` from the previous step: ```swift let sitesResult = try await sitesSession.requestSitesForOrganization(orgId: orgId) if let sites = sitesResult?.sites { for site in sites { print("Site: \(site.name)") } } ``` ### 4. Query Assets Discover spatial assets available at a site: ```swift let assetsResult = try await sitesSession.requestAssetsForSite(siteId: siteId) if let assets = assetsResult?.assets { for asset in assets { print("Asset: \(asset.name) (\(asset.assetType))") } } ``` ### 5. Choose a Site for VPS2 localization To precisely localize to a Site, retain its **Site ID** from the Site query and confirm it has a production VPS asset. The Site ID identifies the localization target; the localized asset ID identifies the VPS map that matched after localization. ```swift let assetsResult = try await sitesSession.requestAssetsForSite(siteId: siteId) // Split the lookup into intermediate values to keep the example easy to read. let assets: [AssetInfo] = assetsResult?.assets ?? [] let vpsAsset: AssetInfo? = assets.first { (asset: AssetInfo) in asset.assetType == .vpsInfo && asset.deployment == .production } let canLocalize = vpsAsset != nil // Use siteId with vps2Session.localize(siteId:) to start map-relative localization. ``` To start map-relative localization for a Site, pass its Site ID to `localize(siteId:)`. For an example that localizes to a Site and places content at the localized asset, see [Place virtual content with VPS2](https://www.nianticspatial.com/docs/nsdk/how-to/vps2/placing_virtual_content/). To learn which status to read while waiting for localization, see [Tracking states](https://www.nianticspatial.com/docs/nsdk/features/vps2/#tracking-states). ## Next Steps - Explore the full [API reference](https://www.nianticspatial.com/docs/api/swift/NSDK.class-NSDKSitesSession)