Update Wellness Data with Scriptable iOS Widgets

I wanted a really short shortcut to update wellness data. Here is what I am doing with Scriptable.
https://scriptable.app/
It’s an App to write custom js code for creating widgets. It can show basic charts, data, text and so on.
It can also handle Alerts. Here is how I update the wellness data:

  1. Create a new Script:
    (Remember to update to your credentials)
let moodScale = ["Great", "Good", "Ok", "Grumpy"];
let motivationScale = ["Extreme", "High", "Average", "Low"];

let mood = await presentAlert("Mood", moodScale);
let motivation = await presentAlert("Motivation", motivationScale);

let moodValue = mood + 1;
let motivationValue = motivation + 1;

// Today
let date = new Date();
let formattedDate = date.toISOString().split('T')[0];

// Update your crediantials
let athleteId = "i12345"; // ### Update this
let apiUrl = `https://intervals.icu/api/v1/athlete/${athleteId}/wellness/${formattedDate}`;

let payload = {
  "mood": moodValue,
  "motivation": motivationValue
};

// Basic Auth Informationen
let username = "API_KEY"; 
let password = "password"; // ### Update this with your API Key
let credentials = `${username}:${password}`;
let encodedCredentials = btoa(credentials); // Base64-Encodierung der Anmeldedaten

let request = new Request(apiUrl);
request.method = "PUT";
request.headers = {
  "accept": "*/*",
  "Content-Type": "application/json",
  "Authorization": `Basic ${encodedCredentials}`
};
request.body = JSON.stringify(payload);


try {
    let putResponse = await request.load();
  
    // Check values
    let getRequest = new Request(apiUrl);
    getRequest.method = "GET";
    getRequest.headers = {
    "accept": "*/*",
    "Authorization": `Basic ${encodedCredentials}`
    };

    let getResponse = await getRequest.loadJSON();

    if (getResponse.mood == moodValue && getResponse.motivation == motivationValue) {
    console.log("Mood and Motivation values updated successfully.");
    } else {
    console.error("Failed to verify updated values.");
    } 
    
  } catch (error) {
    console.error(`Error while updating wellness data: ${error}`);
  }
    
  async function presentAlert(title, options) {
    let alert = new Alert();
    alert.title = title;
    for (let option of options) {
      alert.addAction(option);
    }
    let index = await alert.present();
    return index;
  }

The script will look like this in the Scriptable App

  1. Create a shortcut with the shortcut app to run the scriptable script (confusing, but it is necessary because so we can put a bookmark on the home screen) :


    Select the Scriptable script and important to select ‚Run in App‘!

  2. Share the shortcut on the home screen
    IMG_4069

  3. Every Morning tap the icon. It will prompt:


The result is written to intervals.icu
IMG_1587

Just three clicks to update two values :slight_smile:

##########
You could also skip step 2 to 4 and just create a notification for every morning:
Click on script settings:
IMG_4070

Click on Notifications
Add Daily notification every morning.
It will then notify every day.

If you click on the notification , the script will be executed

1 Like

Found out this app a week+ ago. Still hadn’t had time to actually go thru it