App Store Content Lookup
Relevant source files
The following files were used as context for generating this wiki page:
The App Store Content Lookup system within ipatool provides the functionality to query Apple's iTunes Search API to retrieve detailed metadata for iOS applications. This system is essential for identifying specific apps via bundle identifiers or search terms, which subsequently enables operations like purchasing and downloading encrypted IPA packages.
The lookup process serves as the entry point for most user workflows, translating human-readable search terms or developer-facing bundle IDs into the internal App data structures used by the rest of the application.
Core Components and Architecture
The lookup functionality is primarily managed by the appstore struct, which implements the AppStore interface. It utilizes a specialized searchClient to communicate with external iTunes APIs.
The App Data Structure
All lookup and search operations return an App object (or a collection of them), which encapsulates the necessary metadata for an iOS application.
| Field | Type | Description |
|---|---|---|
ID | int64 | The unique Apple Adam ID for the application. |
BundleID | string | The unique bundle identifier (e.g., com.example.app). |
Name | string | The display name of the application. |
Version | string | The current version string. |
Price | float64 | The price of the application. |
Sources: pkg/appstore/app_test.go:49-55, pkg/appstore/appstore_search.go:42-45
Lookup Logic
The Lookup function is used when the specific BundleID of an application is known. It resolves the account's storefront to a country code and queries the iTunes lookup endpoint.
mermaid
flowchart TD
Start[Invoke Lookup/Search] --> ResolveStore[Resolve Country Code from StoreFront]
ResolveStore --> BuildURL[Construct iTunes API URL]
BuildURL --> SendReq[Send HTTP GET Request]
SendReq --> CheckStatus{Status OK?}
CheckStatus -- No --> Err[Return Error]
CheckStatus -- Yes --> ParseJSON[Unmarshal JSON Results]
ParseJSON --> ValidateCount{Results > 0?}
ValidateCount -- No --> NotFound[Return App Not Found]
ValidateCount -- Yes --> ReturnOut[Return App Metadata]
Sources: [pkg/appstore/appstore_lookup.go:20-43](https://github.com/majd/ipatool/blob/HEAD/pkg/appstore/appstore_lookup.go#L20-L43), [pkg/appstore/appstore_search.go:18-38](https://github.com/majd/ipatool/blob/HEAD/pkg/appstore/appstore_search.go#L18-L38)
## Search vs. Lookup Logic
The module differentiates between searching by keywords and looking up a specific application via its bundle identifier. Both utilize the iTunes Search API but target different parameters.
### App Lookup (By Bundle ID)
The `Lookup` function is used when the exact `BundleID` is known (e.g., `com.apple.Numbers`). It restricts results to a single entry and specifically queries for `software` and `iPadSoftware` entities.
* **Endpoint:** `https://itunes.apple.com/lookup`
* **Logic:** It resolves the country code from the account's storefront, builds the query, and returns an error if no results are found.
* Sources: [pkg/appstore/appstore_lookup.go:21-43](https://github.com/majd/ipatool/blob/HEAD/pkg/appstore/appstore_lookup.go#L21-L43)
### App Search (By Term)
The `Search` function allows for keyword-based discovery. It accepts a `Limit` parameter to control the number of returned results.
* **Endpoint:** `https://itunes.apple.com/search`
* **Parameters:** Includes `term`, `country`, `entity` (software), and `limit`.
* Sources: [pkg/appstore/appstore_search.go:18-38](https://github.com/majd/ipatool/blob/HEAD/pkg/appstore/appstore_search.go#L18-L38), [pkg/appstore/appstore_search.go:50-58](https://github.com/majd/ipatool/blob/HEAD/pkg/appstore/appstore_search.go#L50-L58)
## API Request Configuration
The requests are standard HTTP GET calls with URL-encoded parameters. The system uses the `iTunesAPIDomain` and specific paths for search and lookup.
### Query Parameters
| Parameter | Value/Source | Description |
| :--- | :--- | :--- |
| `entity` | `software,iPadSoftware` | Limits results to iOS/iPadOS applications. |
| `media` | `software` | Specifies the media type. |
| `bundleId` | `input.BundleID` | (Lookup only) The unique app identifier. |
| `term` | `input.Term` | (Search only) The keyword to search for. |
| `country` | `countryCode` | Derived from the user's StoreFront ID. |
Sources: [pkg/appstore/appstore_lookup.go:53-61](https://github.com/majd/ipatool/blob/HEAD/pkg/appstore/appstore_lookup.go#L53-L61), [pkg/appstore/appstore_search.go:50-58](https://github.com/majd/ipatool/blob/HEAD/pkg/appstore/appstore_search.go#L50-L58)
## Data Flow and Sequence
The following sequence diagram shows the interaction between the `appstore` implementation and the HTTP client during a lookup operation.
Error Handling
The lookup system handles several failure scenarios:
- Invalid StoreFront: If the provided storefront ID cannot be mapped to a country code, the operation fails before making a network request. Sources: pkg/appstore/appstore_lookup.go:22-24
- Network/HTTP Failures: Errors from the
searchClientor non-200 status codes are wrapped with metadata for debugging. Sources: pkg/appstore/appstore_lookup.go:29-35 - No Results: If the iTunes API returns 0 results, the module returns a specific "app not found" error. Sources: pkg/appstore/appstore_lookup.go:37-39
Summary
The App Store Content Lookup module provides a streamlined interface for resolving iOS app metadata. By abstracting the complexities of Apple's iTunes Search API—such as regional storefront mapping and JSON unmarshaling—it enables the rest of the ipatool project to interact with applications using a consistent App data model. This module is essential for identifying the salableAdamId required for subsequent purchase and download operations.