# Swift – Native HTTP

## Create a class `EvntalyClient`&#x20;

```swift
import Foundation

class EvntalyClient {
    let projectToken: String
    let developerSecret: String
    let baseUrl = "https://app.evntaly.com/prod"

    init(projectToken: String, developerSecret: String) {
        self.projectToken = projectToken
        self.developerSecret = developerSecret
    }
}
```

## Track Event

```swift
func sendEvent() {
    let url = URL(string: "\(baseUrl)/api/v1/register/event")!
    var request = URLRequest(url: url)
    request.httpMethod = "POST"
    request.setValue("application/json", forHTTPHeaderField: "Content-Type")
    request.setValue(projectToken, forHTTPHeaderField: "pat")
    request.setValue(developerSecret, forHTTPHeaderField: "secret")

    let payload: [String: Any] = [
        "title": "Account License Upgraded",
        "description": "User upgraded their license to Pro",
        "message": "take care.",
        "data": [
            "user_id": "67890",
            "timestamp": "2025-01-08T09:30:00Z",
            "referrer": "social_media",
            "email_verified": false
        ],
        "tags": [],
        "notify": true,
        "icon": "⤴️",
        "apply_rule_only": false,
        "user": ["id": "0f6934fd-99c0-41ca-84f4"],
        "type": "Page View",
        "sessionID": "20750ebc-dabf-4fd4-9498-443bf30d6095_bsd",
        "feature": "Backend API",
        "topic": "@api"
    ]
    
    request.httpBody = try? JSONSerialization.data(withJSONObject: payload)
    URLSession.shared.dataTask(with: request).resume()
}
```

## Identify User

```swift
func identifyUser() {
    let url = URL(string: "\(baseUrl)/api/v1/register/user")!
    var request = URLRequest(url: url)
    request.httpMethod = "POST"
    request.setValue("application/json", forHTTPHeaderField: "Content-Type")
    request.setValue(projectToken, forHTTPHeaderField: "pat")
    request.setValue(developerSecret, forHTTPHeaderField: "secret")

    let payload: [String: Any] = [
       "id": "0f6934fd-99c0-41ca-3333",
        "email": "Alameer@evntaly.com",
        "full_name": "Alameer Ashraf",
        "organization": "Evntaly",
        "data": [
            "id": "Alameer-23",
            "email": "Alameer@evntaly.com",
            "Location": "Egypt",
            "timezone": "Africa/Cairo"
        ]
       ]

    request.httpBody = try? JSONSerialization.data(withJSONObject: payload)
    URLSession.shared.dataTask(with: request).resume()
}

```

For additional help, contact support at **<support@evntaly.com>**.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://evntaly.gitbook.io/evntaly/sdks/curl/swift-native-http.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
