Access Brazil CVM Filings with Swift
Need a Swift CVM filings API client for Brazilian public companies? apicvm is plain HTTPS JSON. Use URLSession, a Bearer token, and the /v1/* routes — there is no official Swift package.
The problem
iOS/macOS tools and server-side Swift services that ingest Brazil filings usually hit:
- Portal HTML that changes without notice
- ZIP dumps without stable document UUIDs
- Missing typed JSON models for resolve → list → download
A thin HTTP client against a fixed contract is easier to keep in a shared module.
Setup
export APICVM_URL='https://apicvm.dev'
export APICVM_KEY='apicvm_...' # from /signup
Resolve a ticker
import Foundation
let base = ProcessInfo.processInfo.environment["APICVM_URL"]!
let key = ProcessInfo.processInfo.environment["APICVM_KEY"]!
var comps = URLComponents(string: "\(base)/v1/companies/resolve")!
comps.queryItems = [
URLQueryItem(name: "query", value: "PETR4"),
URLQueryItem(name: "by", value: "ticker"),
]
var req = URLRequest(url: comps.url!)
req.setValue("Bearer \(key)", forHTTPHeaderField: "Authorization")
let (data, _) = try await URLSession.shared.data(for: req)
print(String(data: data, encoding: .utf8)!)
List DFP documents
var list = URLComponents(string: "\(base)/v1/documents")!
list.queryItems = [
URLQueryItem(name: "ticker", value: "PETR4"),
URLQueryItem(name: "type", value: "DFP"),
URLQueryItem(name: "year", value: "2024"),
URLQueryItem(name: "perPage", value: "20"),
]
var listReq = URLRequest(url: list.url!)
listReq.setValue("Bearer \(key)", forHTTPHeaderField: "Authorization")
let (listData, _) = try await URLSession.shared.data(for: listReq)
Download a PDF
let fileURL = URL(string: "\(base)/v1/documents/\(documentId)/file")!
var fileReq = URLRequest(url: fileURL)
fileReq.setValue("Bearer \(key)", forHTTPHeaderField: "Authorization")
let (fileData, _) = try await URLSession.shared.data(for: fileReq)
try fileData.write(to: URL(fileURLWithPath: "petr4-dfp.pdf"))
File download does not consume extraction credits.
curl cross-check
curl -H "Authorization: Bearer $APICVM_KEY" \
"$APICVM_URL/v1/companies/resolve?query=PETR4&by=ticker"
Current limitations
- Text extraction (
POST /v1/document-text-extractions) is async via callback — not a sync Swift return value. perPagemax is 50; paginate withpage.- Corpus coverage depends on ingestion; empty lists are not "company never filed".
Next steps
Ready to integrate?
Get an API key and start querying Brazilian CVM filings programmatically.