Hi there.
After following the guide on setting up the dependencies for the iOS sdk, the flow would look something like this:
- Create a manager instance:
var terra: TerraManager
Terra.instance(devId: "<YOUR-DEV-ID>", referenceId: "<YOUR-INTERNAL-USER-ID>") { manager, error in
if error == nil {
terra = manager
}
}
- Generate an auth token. For this, you should implement a backend endpoint to get the token from Terra using your dev-id, x-api-key and then call this endpoint from your mobile app (protected by your auth). For example
@app.get('/terra/sdktoken')
def get_terra_sdk_token():
# perform auth for your user if required
headers = {
"dev-id": "<YOUR-DEV-ID>",
"x-api-key": "<YOUR-API-KEY>"
}
response = requests.post("https://api.tryterra.co/v2/auth/generateAuthToken", headers=headers)
data = response.json()
return { 'token': data['token'] }
And then request this endpoint from your app and use the token
- Then initialise a connection, which should pull up the HealthKit permissions screen (this only needs to be done once):
terra.initConnection(type: .APPLE, token: token, customReadTypes: [], schedulerOn: true) { success, error in
if !success {
print("Failed to initialise connection")
}
}
- Now request data as desired (ensuring you use swift date objects):
terra.getDaily(type: .APPLE, startDate: Date, endDate: Date, toWebhook: true)