Command: get-version-metadata
Relevant source files
The following files were used as context for generating this wiki page:
The get-version-metadata command is a specialized utility within the ipatool ecosystem designed to retrieve detailed metadata for a specific version of an iOS application from the Apple App Store. This command is typically used in conjunction with the list-versions command, which provide the external version identifiers required to query specific historical or current metadata for an app.
The primary purpose of this command is to resolve an external-version-id into human-readable information, specifically the display version string (e.g., "1.0.0") and the official release date. It serves as a bridge between the raw version IDs used by Apple's internal APIs and the versioning information visible to end-users.
Sources: cmd/get_version_metadata.go:13-17, README.md:144-148
Command Architecture and Execution Flow
The command is implemented using the cobra library and follows a retry-based execution pattern to handle transient authentication issues, such as expired password tokens.
Logic Flow
- Input Validation: The command ensures that either an
app-idor abundle-identifieris provided, along with the mandatoryexternal-version-id. - Account Retrieval: It fetches the current authenticated account information.
- Session Management: If a "password token expired" error is encountered, it attempts to re-login the user before retrying the metadata request.
- App Resolution: If a bundle identifier is used instead of an app ID, it performs a lookup to find the corresponding app metadata.
- API Request: It invokes the App Store service to fetch metadata specifically for the provided version identifier.
Sources: cmd/get_version_metadata.go:21-68
The diagram above illustrates the execution flow of the command, highlighting the integration of account management and the App Store API.
Sources: cmd/get_version_metadata.go:28-87
Data Structures and API Interaction
The command relies on specific data structures to pass inputs to the App Store package and handle the returned results.
Input and Output Models
| Structure | Field | Type | Description |
|---|---|---|---|
| GetVersionMetadataInput | Account | Account | Authenticated user account details. |
| App | App | Targeted application info (ID). | |
| VersionID | string | The external version identifier. | |
| GetVersionMetadataOutput | DisplayVersion | string | Human-readable version (e.g., "2.1.4"). |
| ReleaseDate | time.Time | Official release timestamp. |
Sources: pkg/appstore/appstore_get_version_metadata.go:11-20
App Store Request Construction
The request is sent as a POST request to the Apple Private App Store API. It uses a guid derived from the machine's MAC address and payloads formatted as Apple Plists (XML).
func (t *appstore) getVersionMetadataRequest(acc Account, app App, guid string, version string) http.Request {
payload := map[string]interface{}{
"creditDisplay": "",
"guid": guid,
"salableAdamId": app.ID,
"externalVersionId": version,
}
// ... constructs http.Request with XMLPayload
}
Sources: pkg/appstore/appstore_get_version_metadata.go:56-74
Technical Implementation Details
Metadata Extraction
The service parses the response from Apple's servers, which contains an items list (referenced as songList in the internal XML structure). The metadata for the version is extracted from the Metadata map using keys returned in the Plist response.
- Release Date: Parsed from the
releaseDatefield using thetime.RFC3339format. - Display Version: Extracted from the
bundleShortVersionStringfield.
Sources: pkg/appstore/appstore_get_version_metadata.go:48-54, pkg/appstore/appstore_download.go:94-96
Error Handling
The command specifically monitors for various failure types returned by the App Store API:
FailureTypePasswordTokenExpired: Triggers the retry logic in the command layer.FailureTypeSignInRequired: Treated similarly to an expired token.FailureTypeLicenseNotFound: Returns a specificErrLicenseRequirederror.
Sources: pkg/appstore/appstore_get_version_metadata.go:34-40, pkg/appstore/appstore_get_version_metadata_test.go:88-124
Usage and Configuration
Command Flags
| Flag | Shorthand | Type | Required | Description |
|---|---|---|---|---|
--app-id | -i | int64 | No* | The numerical ID of the target app. |
--bundle-identifier | -b | string | No* | The bundle ID of the target app. |
--external-version-id | string | Yes | The ID of the specific version. |
*Note: Either --app-id or --bundle-identifier must be provided.
Sources: cmd/get_version_metadata.go:91-95, README.md:155-160
Conclusion
The get-version-metadata command is a vital component for users who need to audit or specifically target historical versions of iOS applications. By leveraging the same underlying download request infrastructure as the download command but targeting metadata fields, it provides precise versioning and release information essential for advanced App Store interactions within ipatool.
Sources: pkg/appstore/appstore_get_version_metadata.go:58-74, README.md:144-148