MuxForms on Swift uses URLSession.shared.data(for:) with a POST request to the submit API, JSONEncoder for the body, and Authorization Bearer ingest secret. Handle HTTP 422 to show validation errors.
Docs
SwiftUI and UIKit apps submit with URLSession—encode a Codable struct that matches your MuxForms field names.
| API | Usage |
|---|---|
| URLSession | POST JSON |
| Codable | Payload struct |
| Keychain | Store ingest secret |
| Combine | Optional async wrapper |
import Foundation
struct ContactPayload: Encodable {
let email: String
let message: String
let platform = "ios"
let _hp = ""
}
func submitContact(email: String, message: String, secret: String) async throws {
let url = URL(string: "https://www.muxforms.com/api/v1/forms/FORM_UUID/submit")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("Bearer \(secret)", forHTTPHeaderField: "Authorization")
request.httpBody = try JSONEncoder().encode(ContactPayload(email: email, message: message))
let (_, response) = try await URLSession.shared.data(for: request)
guard let http = response as? HTTPURLResponse, http.statusCode == 200 else {
throw URLError(.badServerResponse)
}
}Support reads the same inbox as your marketing site.
Upgrade to Pro