<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Elliott on Medium]]></title>
        <description><![CDATA[Stories by Elliott on Medium]]></description>
        <link>https://medium.com/@elliott_37086?source=rss-2cde8f8f2035------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*u7SO4dBhiieNpy6P</url>
            <title>Stories by Elliott on Medium</title>
            <link>https://medium.com/@elliott_37086?source=rss-2cde8f8f2035------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:30:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@elliott_37086/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Mobile App Basics: iOS Swift UI (Part 3)]]></title>
            <link>https://medium.com/terraapi/mobile-app-basics-ios-swift-ui-part-3-2bf8c26d0431?source=rss-2cde8f8f2035------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bf8c26d0431</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[deeplink]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Elliott]]></dc:creator>
            <pubDate>Tue, 25 Apr 2023 10:13:28 GMT</pubDate>
            <atom:updated>2023-04-25T10:13:28.165Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ymwpY1lBxuixKDcWWMhvRg.png" /></figure><p>So far we have explored basic components of an iOS app using Swift UI. Here we will discuss a bit more on some built in views specifically:</p><ul><li>Building a customised pop up screens</li><li>Deep linking back to your app</li></ul><blockquote>Customisable pop-up screens</blockquote><p>For this, let’s say we wish to create a customisable DatePicker for our app. There are many ways to do this, but an elegant way would be to create a custom pop-up. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*aAg5UmEMIgvntt4PiFqecA.jpeg" /></figure><p>This way you get your user focused on the date picker. First let’s the background screen. Following knowledge previously used in Part 1 and 2, this can be done quite easily:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*6ONXXkk0OWxugfcT6tOttw.jpeg" /></figure><pre>struct DataRequestView : View {<br>    <br>    var body: some View {<br>        GeometryReader{ geometry in<br>            VStack{<br>                ZStack{<br>                    HStack{<br>                        BackButton(path: $path).padding(.leading, 10)<br>                        Spacer()<br>                    }<br>                    Text(&quot;Request Data&quot;).font(Font.custom(&quot;Poppins-Bold&quot;, size: 16))<br>                }.padding(.top, 10)<br>                    .frame(width: geometry.size.width, height: 24, alignment: .center)<br>                ZStack{<br>                    Rectangle()<br>                        .fill(Color.white)<br>                        .cornerRadius(16)<br>                        .shadow(color: Color.blockShadow, radius:6, x: 0, y: 2)<br>                    VStack(spacing: 30){<br>                        HStack{<br>                            Text(&quot;Choose Date&quot;)<br>                                .font(Font.custom(&quot;Poppins-Bold&quot;, size: 24))<br>                                .padding([.leading, .top], 24)<br>                            Spacer()<br>                        }<br>                        ZStack{<br>                            Rectangle()<br>                                .stroke(Color.init(.sRGB, red: 0.92, green: 0.92, blue: 0.92, opacity: 1), lineWidth: 1)<br>                                .cornerRadius(8)<br>                            VStack{<br>                                HStack{<br>                                    Text(&quot;From: &quot;).font(Font.custom(&quot;Poppins-Regular&quot;, size: 14)).padding(.leading, 12)<br>                                    Spacer()<br>                                }.padding(.top, 8)<br>                                HStack{<br>                                    Text(ISO8601DateFormatter.string(from: Date(), timeZone: TimeZone.current, formatOptions: [.withDay, .withYear, .withMonth, .withDashSeparatorInDate])).font(Font.custom(&quot;Poppins-Regular&quot;, size: 16)).padding(.leading, 12)<br>                                    Spacer()<br>                                    Image(&quot;calendar&quot;).frame(width: 18, height: 19.5).padding(.trailing, 12)<br>                                        .onTapGesture {<br>                                            // Show <br>                                        }<br>                                }.padding([.bottom, .top], 8)<br>                            }.frame(alignment: .center)<br>                        }.frame(width: geometry.size.width * 0.8, height: 50, alignment: .center).padding(.top, 20)<br>                        ZStack{<br>                            Rectangle()<br>                                .stroke(Color.init(.sRGB, red: 0.92, green: 0.92, blue: 0.92, opacity: 1), lineWidth: 1)<br>                                .cornerRadius(8)<br>                            VStack{<br>                                HStack{<br>                                    Text(&quot;To: &quot;).font(Font.custom(&quot;Poppins-Regular&quot;, size: 14)).padding(.leading, 12)<br>                                    Spacer()<br>                                }<br>                                .padding(.top, 8)<br>                                HStack{<br>                                    Text(ISO8601DateFormatter.string(from: Date(), timeZone: TimeZone.current, formatOptions: [.withDay, .withYear, .withMonth, .withDashSeparatorInDate])).font(Font.custom(&quot;Poppins-Regular&quot;, size: 16)).padding(.leading, 12)<br>                                    Spacer()<br>                                    Image(&quot;calendar&quot;).frame(width: 18, height: 19.5).padding(.trailing, 12)<br>                                        .onTapGesture {<br>                                            // Show date picker view<br>                                        }<br>                                }.padding([.bottom, .top], 8)<br>                            }.frame(alignment: .center)<br>                        }.frame(width: geometry.size.width * 0.8, height: 50, alignment: .center).padding(.top, 16)<br>                        Spacer()<br>                        Text(&quot;The data you’re requesting will be displayed for the date range you select here.&quot;)<br>                            .font(Font.custom(&quot;Poppins-Regular&quot;, size: 14))<br>                            .multilineTextAlignment(.center)<br>                            .frame(width: geometry.size.width * 0.7, height: 109, alignment: .center)<br>                            .background(<br>                                Rectangle()<br>                                    .fill(Color.init(.sRGB, red: 240/255, green: 246/255, blue:255/255, opacity: 1))<br>                                    .cornerRadius(8)<br>                                    .frame(width: geometry.size.width * 0.8, height: 109, alignment: .center)<br>                            ).padding(.bottom, 20)<br>                    }.frame(alignment: .center)<br>                }.padding(.top, 40)<br>                    .frame(width: geometry.size.width*9/10, height: 500, alignment: .center)<br>                Spacer()<br>                ZStack{<br>                    Rectangle()<br>                        .fill(Color.white)<br>                        .ignoresSafeArea(.all)<br>                        .frame(height: 120)<br>                    HStack{<br>                        Text(&quot;Cancel Request&quot;)<br>                            .font(Font.custom(&quot;Poppins-SemiBold&quot;, size: 14))<br>                            .padding(.leading, 16)<br>                            .onTapGesture {<br>                                // Go back<br>                            }<br>                        Spacer()<br>                        Button(action: {<br>                            // Continue<br>                        }, label: {<br>                            Text(&quot;Continue&quot;)<br>                                .font(Font.custom(&quot;Poppins-SemiBold&quot;, size: 14))<br>                                .foregroundColor(Color.white)<br>                                .background(<br>                                    Rectangle()<br>                                        .fill(Color.darkBackground)<br>                                        .cornerRadius(22)<br>                                        .frame(width: 122, height: 37)<br>                                )<br>                        }).padding(.trailing, 40)<br>                    }<br>                }.frame(width: geometry.size.width, alignment: .center)<br>            }.frame(width: geometry.size.width, height: geometry.size.height, alignment: .center)<br>        }.navigationBarBackButtonHidden(true)<br>        .background(Color.appBackground, ignoresSafeAreaEdges: .all)<br>    }<br>}</pre><p>In this flow, we want to display the DatePicker when the user presses the little calendar icon. Hence, we want a onTapGesture property on our Calendar image.</p><p>We can use the trick we did in Part 2: introduce a State variable to say when to show the DatePicker:</p><pre>struct DataRequestView : View {<br>    @State var showDatePicker: Bool = false<br>    var body: some View {<br>        ...<br>                        ZStack{<br>                            Rectangle()<br>                                .stroke(Color.init(.sRGB, red: 0.92, green: 0.92, blue: 0.92, opacity: 1), lineWidth: 1)<br>                                .cornerRadius(8)<br>                            VStack{<br>                                HStack{<br>                                    Text(&quot;From: &quot;).font(Font.custom(&quot;Poppins-Regular&quot;, size: 14)).padding(.leading, 12)<br>                                    Spacer()<br>                                }.padding(.top, 8)<br>                                HStack{<br>                                    Text(ISO8601DateFormatter.string(from: Date(), timeZone: TimeZone.current, formatOptions: [.withDay, .withYear, .withMonth, .withDashSeparatorInDate])).font(Font.custom(&quot;Poppins-Regular&quot;, size: 16)).padding(.leading, 12)<br>                                    Spacer()<br>                                    Image(&quot;calendar&quot;).frame(width: 18, height: 19.5).padding(.trailing, 12)<br>                                        .onTapGesture {<br>                                            showDatePicker.toggle()<br>                                        }<br>                                }.padding([.bottom, .top], 8)<br>                            }.frame(alignment: .center)<br>                        }.frame(width: geometry.size.width * 0.8, height: 50, alignment: .center).padding(.top, 20)<br>          ...<br>        .background(Color.appBackground, ignoresSafeAreaEdges: .all)<br>    }<br>}</pre><p>We can then create a new View that takes in a Binding variable. This view will what the user sees when they tap on the calendar icon:</p><pre>struct DatePickerView: View{<br>    @Binding var showPicker: Bool<br>    <br>    var body: some View{<br>          VStack{<br>              <br>          }<br>      }<br>}</pre><p>We can now use the sheets in SwiftUI to display the DatePicker as a popup. In our DataRequestView:</p><pre>struct DataRequestView : View {<br>    @State var showDatePicker: Bool = false<br>    var body: some View {<br>        GeometryReader{geometry in<br>         ...           <br>        }.navigationBarBackButtonHidden(true)<br>        .background(Color.appBackground, ignoresSafeAreaEdges: .all)<br>        .sheet(isPresented: $showStartDatePicker, content: {<br>            DatePickerView(showPicker: $showDatePicker)<br>        })<br>    }<br>}</pre><p>This will display DatePickerView whenever the calendar icon is tapped on as a sheet laying over the current DataRequestView .</p><p>The problem here is that the sheet has a completely white background…. but we want a clear one. To combat that, we need to create a custom background that is simply a “clear” colour background:</p><pre>struct RemoveBackgroundColor: UIViewRepresentable{<br>    func makeUIView(context: Context) -&gt; UIView{<br>        return UIView()<br>    }<br>    <br>    func updateUIView(_ uiView: UIView, context: Context) {<br>        DispatchQueue.main.async {<br>            uiView.superview?.superview?.backgroundColor = .clear<br>        }<br>    }<br>}</pre><p>This is simply a UIViewRepresentable class that can be used as a background in the .background modifier:</p><pre>struct DataRequestView : View {<br>    @State var showDatePicker: Bool = false<br>    var body: some View {<br>        GeometryReader{geometry in<br>         ...           <br>        }.navigationBarBackButtonHidden(true)<br>        .background(Color.appBackground, ignoresSafeAreaEdges: .all)<br>        .sheet(isPresented: $showStartDatePicker, content: {<br>            DatePickerView(showPicker: $showDatePicker)<br>              .background(RemoveBackgroundColor())<br>        })<br>    }<br>}</pre><p>Finally, the only thing we need to build out is the DatePickerView . For this, we can use the DatePicker view from Swift UI:</p><pre>struct DatePickerView: View{<br>    @Binding var showPicker: Bool<br>    @State var shownDate: Date = Date()<br>    <br>    var body: some View{<br>        GeometryReader{ geometry in<br>            VStack(spacing: 0){<br>                Spacer()<br>                DatePicker(&quot;&quot;, selection: $shownDate, displayedComponents: [.date]).datePickerStyle(.wheel)<br>                    .labelsHidden()<br>                    .frame(width: geometry.size.width ,height: 212, alignment: .center)<br>                    .background(Color.white)<br>                ZStack{<br>                    Rectangle()<br>                        .fill(Color.black)<br>                    VStack{<br>                        Text(&quot;Done&quot;)<br>                            .font(Font.custom(&quot;Poppins-SemiBold&quot;, size: 14))<br>                            .foregroundColor(Color.white)<br>                            .padding(.top, 12)<br>                        Spacer()<br>                    }<br>                }.frame(width: geometry.size.width , height: 60)<br>                .onTapGesture {<br>                    showPicker.toggle()<br>                }<br>            }<br>        }.ignoresSafeArea(.all)<br>    }<br>}</pre><p>This requires a state variable that is a Date object to be passed in to the view to get the date returned from the picker. We also simply toggle showPicker which is binded to the state variabled passed into this view to stop displaying it.</p><p>Putting this together will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*KdUPfsjGXVloZDrHXptPYw.gif" /></figure><blockquote>Deeplinking</blockquote><p>Another method to improve user experience is automatically linking the user back to your app when they perhaps has been redirected somewhere else to complete an action (for example logging into another app).</p><p>The way to do this is by deep linking! To set this up, it is rather simple…</p><p>You will need to add a URL Type to your project: Under your app target, go to Info (where your Info.plist is displayed). At the bottom, there is a tab called URL Types:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*VaTp7oBivirDn94ZYclx_Q.png" /></figure><p>Add a URL Type as shown above. The identifier is your app’s identifier, typically will be the reverse of your domain (tryterra.co) and some name you assign to your app (co.tryterra.terraficapp). The URL Schemes is what allows the phone to know where to direct the user to. This will essentially replace the https in the URLs you are familiar with.</p><p>Simply having this setting, if you go into your phone’s safari and type in terraficapp:// in the link tab, it will prompt you to be redirected to the app!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*BhsCSiIOPxrX_0u8k1M3gg.gif" /></figure><p>Finally, in order to catch this URL and perform actions according to it, there is a modifier that you can add to views:</p><pre>ContentView()<br>    .onOpenURL { url in<br>        // Do something according to URL<br>    }</pre><blockquote>Build it out</blockquote><p>There are so many things SwiftUI has to offer. So far we have only touched the basics.</p><p>The best way to master all of this is to go and build out an app for yourself!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bf8c26d0431" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terraapi/mobile-app-basics-ios-swift-ui-part-3-2bf8c26d0431">Mobile App Basics: iOS Swift UI (Part 3)</a> was originally published in <a href="https://medium.com/terraapi">Terra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mobile App Basics: iOS Swift UI (Part 2)]]></title>
            <link>https://medium.com/terraapi/mobile-app-basics-ios-swift-ui-part-2-32c899ea077f?source=rss-2cde8f8f2035------2</link>
            <guid isPermaLink="false">https://medium.com/p/32c899ea077f</guid>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[blog]]></category>
            <dc:creator><![CDATA[Elliott]]></dc:creator>
            <pubDate>Mon, 17 Apr 2023 11:39:30 GMT</pubDate>
            <atom:updated>2023-04-17T11:39:30.032Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GRTrwdUxOwlJA97DL8BAwA.jpeg" /></figure><p>In the previous article, we explored basic styling and view building in Swift UI for a mobile app which includes:</p><ul><li>Importing your own images</li><li>Using your own fonts</li><li>Using primitive views (Rectangle, Circle, Text, Button)</li></ul><p>Knowing all of this, we can now go ahead and learn how to direct the app user to different Views or functionalities. In this article, we will cover some other topics including:</p><ul><li>Navigating the app to different views</li><li>Changing a view’s state dynamically</li></ul><blockquote>The Main View</blockquote><p>For the purposes of our demonstration app, we can let the app user select their path at the ContentView View. For now, we have created our own view called WidgetInfo, and we can link the user to this View with a button click fromContentView.</p><p>For the design, let’s go with this in the ContentView :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/0*zPdvkBKOZK5Qp1ru.png" /></figure><p>On the trigger for Connect Widget button, we will want to link them to WidgetInfo.</p><p>The design for this is simple. We will simply be re-using the knowledge we know from Part 1:</p><pre>struct ContentView: View {<br>    var body: some View {<br>        VStack {<br>            Image(&quot;TERRA&quot;)<br>                .imageScale(.large)<br>                .foregroundColor(.accentColor)<br>                .padding([.bottom], 32)<br>            <br>            Button {<br>                // link to Widget Info Page<br>            } label: {<br>                Text(&quot;Connect Widget&quot;)<br>                    .foregroundColor(Color.white)<br>                    .font(Font.custom(&quot;Poppins-Regular&quot;, size: 13))<br>                    .frame(width: 290, height: 50)<br>            }.background(<br>                Rectangle()<br>                    .fill(Color.darkBackground)<br>                    .cornerRadius(6.5)<br>            )<br>            <br>            Button {<br>                // Go to Connect device page<br>            } label: {<br>                Text(&quot;Connect Device&quot;)<br>                    .foregroundColor(Color.white)<br>                    .font(Font.custom(&quot;Poppins-Regular&quot;, size: 13))<br>                    .frame(width: 290, height: 50)<br>            }.background(<br>                Rectangle()<br>                    .fill(Color.lightBackground)<br>                    .cornerRadius(6.5)<br>            ).padding([.top], 16)<br>            <br>        }<br>        .padding()<br>    }<br>}</pre><blockquote>Navigation Stack</blockquote><p>The question now is, how do we link the user to WidgetInfo when the button is pressed in our View?</p><p>We can actually do this with what SwiftUI calls a NavigationStack (or NavigationView ). To do this, we simply need to wrap our entire View in a navigation stack:</p><pre>struct ContentView: View {<br>    var body: some View {<br>        NavigationStack{<br>            VStack {<br>                Image(&quot;TERRA&quot;)<br>                    .imageScale(.large)<br>                    .foregroundColor(.accentColor)<br>                    .padding([.bottom], 32)<br>                <br>                Button {<br>                // link to Widget Info Page<br>                } label: {<br>                    Text(&quot;Connect Widget&quot;)<br>                        .foregroundColor(Color.white)<br>                        .font(Font.custom(&quot;Poppins-Regular&quot;, size: 13))<br>                        .frame(width: 290, height: 50)<br>                }.background(<br>                    Rectangle()<br>                        .fill(Color.darkBackground)<br>                        .cornerRadius(6.5)<br>                )<br>                <br>                Button {<br>                    // Go to Connect device page<br>                } label: {<br>                    Text(&quot;Connect Device&quot;)<br>                        .foregroundColor(Color.white)<br>                        .font(Font.custom(&quot;Poppins-Regular&quot;, size: 13))<br>                        .frame(width: 290, height: 50)<br>                }.background(<br>                    Rectangle()<br>                        .fill(Color.lightBackground)<br>                        .cornerRadius(6.5)<br>                ).padding([.top], 16)<br>                <br>            }<br>            .padding()<br>        }<br>    }<br>}</pre><p>The next thing we would need to use is a NavigationLink . Lucky for us the views Button and NavigationLink contains similar arguments, and in our case, we can actually just replace Button with NavigationLink . The only thing else we would need to add would be to call our WidgetInfo view when the link is triggered:</p><pre>struct ContentView: View {<br>    var body: some View {<br>        NavigationStack{<br>            VStack {<br>                Image(&quot;TERRA&quot;)<br>                    .imageScale(.large)<br>                    .foregroundColor(.accentColor)<br>                    .padding([.bottom], 32)<br>                <br>                NavigationLink {<br>                    WidgetInfo()<br>                } label: {<br>                    Text(&quot;Connect Widget&quot;)<br>                        .foregroundColor(Color.white)<br>                        .font(Font.custom(&quot;Poppins-Regular&quot;, size: 13))<br>                        .frame(width: 290, height: 50)<br>                }.background(<br>                    Rectangle()<br>                        .fill(Color.darkBackground)<br>                        .cornerRadius(6.5)<br>                )<br>                <br>                NavigationLink {<br>                    // Go to Connect BLE<br>                } label: {<br>                    Text(&quot;Connect Device&quot;)<br>                        .foregroundColor(Color.white)<br>                        .font(Font.custom(&quot;Poppins-Regular&quot;, size: 13))<br>                        .frame(width: 290, height: 50)<br>                }.background(<br>                    Rectangle()<br>                        .fill(Color.lightBackground)<br>                        .cornerRadius(6.5)<br>                ).padding([.top], 16)<br>                <br>            }<br>            .padding()<br>        }<br>    }<br>}</pre><p>Let’s see it in action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/0*yfjqpEBnl72Xh_ot.gif" /></figure><p>The back button is actually automatically added because of NavigationLink.</p><blockquote>State Variables</blockquote><p>Personally, the back button shown from the navigation stack is not the best in terms of style. Let’s create our own:</p><pre>struct BackButton: View{    <br>    var body: some View{<br>        ZStack{<br>            Circle().fill(Color.white)<br>            Image(systemName: &quot;arrow.backward&quot;).foregroundColor(Color.black)<br>        }.frame(width: 31, height: 31, alignment: .center)<br>    }<br>}</pre><p>The downside of doing so is that we will need to implement our own logic when we want to go back to the ContentView page.</p><p>Luckily, we can make use of a very cool feature of Swift UI: State and Binding variables.</p><p>Essentially, you propagate changes from one view to another and dynamically cause changes to views using these.</p><p>For our back button, we can introduce a Binding variable which we will pass into from the ContentView as a State variable. We simply want this variable to be a Bool for now that we toggle whenever the user touches this back button. For this we will use onTapGesture():</p><pre>struct BackButton: View{<br>    @Binding var toggle: Bool<br>    <br>    var body: some View{<br>        ZStack{<br>            Circle().fill(Color.white)<br>            Image(systemName: &quot;arrow.backward&quot;).foregroundColor(Color.black)<br>        }.frame(width: 31, height: 31, alignment: .center)<br>            .onTapGesture {<br>                toggle.toggle()<br>            }<br>    }<br>}</pre><p>We will use the toggle variable to represent: “Do we want to show this view or not”. This variable will be controlled by ContentView so let’s create a State variable in ContentView :</p><pre>struct ContentView: View {<br>    <br>    // The default state here is false (do not show)<br>    @State var showWidgetInfo: Bool = false<br>    <br>    var body: some View {<br>        NavigationStack{<br>...</pre><p>With this, we can then manipulate the navigation stack to determine when we want to show WidgetInfo or not by toggling showWidgetInfo. For now, we can simply replace the NavigationLink with a Button to toggle this variable when pressed:</p><pre>struct ContentView: View {<br>    <br>    @State var showWidgetInfo: Bool = false<br>    <br>    var body: some View {<br>        NavigationStack{<br>            VStack {<br>              ...<br>                Button {<br>                    showWidgetInfo.toggle()<br>                } label: {<br>                    Text(&quot;Connect Widget&quot;)<br>                        .foregroundColor(Color.white)<br>                        .font(Font.custom(&quot;Poppins-Regular&quot;, size: 13))<br>                        .frame(width: 290, height: 50)<br>                }.background(<br>                    Rectangle()<br>                        .fill(Color.darkBackground)<br>                        .cornerRadius(6.5)<br>                )<br>                <br>              ...<br>                <br>            }<br>        }<br>    }<br>}</pre><p>Finally, the magic here is, we can add a navigationDestination property to our VStack to tell the app where to go when the value of this state variable is set to true:</p><pre>struct ContentView: View {<br>    <br>    @State var showWidgetInfo: Bool = false<br>    <br>    var body: some View {<br>        NavigationStack{<br>            VStack {<br>                Image(&quot;TERRA&quot;)<br>                    .imageScale(.large)<br>                    .foregroundColor(.accentColor)<br>                    .padding([.bottom], 32)<br>                <br>                Button {<br>                    showWidgetInfo.toggle()<br>                } label: {<br>                    Text(&quot;Connect Widget&quot;)<br>                        .foregroundColor(Color.white)<br>                        .font(Font.custom(&quot;Poppins-Regular&quot;, size: 13))<br>                        .frame(width: 290, height: 50)<br>                }.background(<br>                    Rectangle()<br>                        .fill(Color.darkBackground)<br>                        .cornerRadius(6.5)<br>                )<br>                <br>                NavigationLink {<br>                    // Go to Connect BLE<br>                } label: {<br>                    Text(&quot;Connect Device&quot;)<br>                        .foregroundColor(Color.white)<br>                        .font(Font.custom(&quot;Poppins-Regular&quot;, size: 13))<br>                        .frame(width: 290, height: 50)<br>                }.background(<br>                    Rectangle()<br>                        .fill(Color.lightBackground)<br>                        .cornerRadius(6.5)<br>                ).padding([.top], 16)<br>                <br>            }<br>            .navigationDestination(isPresented: $showWidgetInfo){<br>               // Go to Widget Info View<br>             }<br>            .padding()<br>        }<br>    }<br>}</pre><p>Before we can let it navigate the user to WidgetInfo, we need to create a Binding variable in WidgetInfo View’s implementation, this way we can link our custom back button to toggle this State variable:</p><pre>struct WidgetInfo: View{<br>    <br>    @Binding var showWidgetInfo: Bool<br>    var body: some View{<br>    ...<br>    }<br>}</pre><p>We can then pass a Binding reference into WidgetInfo in ContentView as such:</p><pre>...<br>.navigationDestination(isPresented: $showWidgetInfo){<br>    WidgetInfo(showWidgetInfo: $showWidgetInfo)<br>}</pre><p>And, in WidgetInfo we will simply pass this variable along to the custom back button view.</p><p>Note: Spacer here is a built-in view that simply fills up the entire space in the HStack after the back button. In addition, we can use .navigationBarBackButtonHidden(true) on the entire view to (you guessed it) hide the hideous built-in back button.</p><pre>struct WidgetInfo: View{<br>    <br>    @Binding var showWidgetInfo: Bool<br>    <br>    var body: some View{<br>        VStack{<br>            HStack{<br>                BackButton(toggle: $showWidgetInfo )<br>                Spacer()<br>            }<br>            Image(&quot;widgetInfo&quot;)<br>            Text(&quot;Widget to connect your app to all wearables&quot;)<br>                .multilineTextAlignment(.center)<br>                .font(Font.custom(&quot;Poppins-Bold&quot;, size: 20))<br>                .frame(width: 261, height: 60)<br>                .padding([.top], 64)<br>            Text(&quot;Unlock the power of health data&quot;)<br>                .multilineTextAlignment(.center)<br>                .font(Font.custom(&quot;Poppins-Regular&quot;, size: 16))<br>                .frame(width: 296, height: 21)<br>                .padding([.top], 16)<br>            HStack{<br>                Circle().frame(width: 12, height: 12)<br>                Circle().fill(Color.lightGray).frame(width: 12, height: 12)<br>                    .padding([.leading], 4)<br>                Circle().fill(Color.lightGray).frame(width: 12, height: 12)<br>                    .padding([.leading], 4)<br>            }<br>            .padding([.top], 40)<br>            Button(action: {<br>              //<br>            }, label: {<br>                Text(&quot;Continue&quot;)<br>                    .font(Font.custom(&quot;Poppins-Regular&quot;, size: 13))<br>                    .foregroundColor(Color.white)<br>                    .frame(width: 169, height: 33)<br>                    .background(<br>                        Rectangle()<br>                            .fill(Color.darkBackground)<br>                            .cornerRadius(6.5)<br>                    )<br>                    .padding([.top], 105)<br>            }).padding()<br>        }.navigationBarBackButtonHidden(true)<br>    }<br>}</pre><p>Let’s take a look:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/0*mYlEi2Jx_BFha8pB.gif" /></figure><blockquote>and More…</blockquote><p>State and Binding variables can be used to do a lot more than a toggle . You can also have a state variable that is an Int for which can increase every time a button is pressed for example. These really help create a dynamic field to the app and gives the user a much better experience.</p><p>We will explore some more exciting topics such as Deep Linking in your app and play around with other more interesting built-in abilities of SwiftUI!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32c899ea077f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terraapi/mobile-app-basics-ios-swift-ui-part-2-32c899ea077f">Mobile App Basics: iOS Swift UI (Part 2)</a> was originally published in <a href="https://medium.com/terraapi">Terra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mobile App Basics: iOS Swift UI (Part 1)]]></title>
            <link>https://medium.com/terraapi/mobile-app-basics-ios-swift-ui-part-1-157f0637f1af?source=rss-2cde8f8f2035------2</link>
            <guid isPermaLink="false">https://medium.com/p/157f0637f1af</guid>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Elliott]]></dc:creator>
            <pubDate>Mon, 10 Apr 2023 11:02:14 GMT</pubDate>
            <atom:updated>2023-04-10T11:02:14.807Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2N5RCP6ddmE5dUvi61XPeg.png" /></figure><p>Building a native mobile app can be daunting at times especially since they require you to use a language not commonly taught or used in most scenarios.</p><p>In this article, we will explore the basics in building an app using Swift UI:</p><ul><li>Understanding the structure of the app</li><li>Creating basic screens and designs</li><li>Customising the app with your own style</li></ul><blockquote>First step forward</blockquote><p>Let’s start by first creating an app. Using XCode -&gt; File -&gt; New Project, you can create one very simply:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CsiSwiH0KiKs-F3m.png" /></figure><p>The basic app now contains an opening view called ContentView and a Terra-fic-App App struct (the entry point of the app).</p><p>Running this app on its own simply shows a blank screen with a globe in the middle saying Hello Word! . From here on, you can work off of this ContentView and start building your own views!</p><blockquote>Structuring</blockquote><p>Anything you want to build in the mobile app now that is visible to the user must conform to the View type. For example in the auto-generated ContentView file:</p><pre>struct ContentView: View {<br>    var body: some View {<br>        VStack {<br>            Image(systemName: &quot;globe&quot;)<br>                .imageScale(.large)<br>                .foregroundColor(.accentColor)<br>            Text(&quot;Hello, world!&quot;)<br>        }<br>        .padding()<br>    }<br>}</pre><p>The struct conforms to View by implementing var body: some View. This is where you would put all the “Views”. Here VStack (which probably stands for something like Vertical Stack) essentially stacks the views inside it in a vertical manner. Hence, the Image is above the “Hello World”. There is also HStack which stacks horizontally and ZStack which stacks on top of each other.</p><p>The .imageScale(.large) modifies the Image to (you guessed it) a larger scale than its default size. All the views will have customizable modifications that allow changing their size, color, position, effects, etc. The best way to get to know these is to play around with them.</p><blockquote>Creating your own View</blockquote><p>It is usually recommended to have a design before going into coding it. This way you have a picture in mind of what it should look like first. Let’s say we are looking to create a very basic view like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*Jly7-CZUFfCYC-Uv.png" /><figcaption>View Design</figcaption></figure><p>We can start from the top level. A VStack will contain all the smaller views within:</p><pre>struct WidgetInfo: View{<br>  var body: some View{<br>    VStack{<br>      <br>    }<br>  }<br>}</pre><p>We can then build from the top of the screen down. First things first are the image. You can import any images into your Assets.xcassets file. Simply at the bottom of the file press the little “+” and Import.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*tvFfLzEHakvm4JlX.png" /></figure><p>Once you have chosen the image, you should be able to see it there:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0WrYqmg1t0Ez5d0a.png" /></figure><p>That’s it! We can now use it in the view:</p><pre>struct WidgetInfo: View{<br>  var body: some View{<br>    VStack{<br>       Image(&quot;widgetInfo&quot;)<br>    }<br>  }<br>}</pre><p>Next, we need to include some text in the view. Simple Text(&quot;Widget to connect...&quot;) will work. However, we can also include our own fonts and style to make it look a bit fancier.</p><p>For this demonstration, we downloaded some fonts (.ttf) files and include them in our project (in a separate Fonts folder):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/0*MMrhaRWYB6iV0_wD.png" /></figure><p>This will be recognized in our project when we include it in our Info. plistfile. Simply add a new key called (Fonts provided by the application) and include the fonts you want as values:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Fa4EXU2aTr5tjMIU.png" /></figure><p>You should now be able to customize the text view with these fonts:</p><pre>struct WidgetInfo: View{<br>  var body: some View{<br>    VStack{<br>       Image(&quot;widgetInfo&quot;)<br>       Text(&quot;Widget to connect your app to all wearables&quot;)<br>        .multilineTextAlignment(.center) // makes sure you have multiline centering<br>        .font(Font.custom(&quot;Poppins-Bold&quot;, size: 20)) // Custom font with font size<br>        .frame(width: 261, height: 60)<br>        .padding([.top], 64)<br>       Text(&quot;Unlock the power of health data&quot;) // Line below<br>        .multilineTextAlignment(.center)<br>        .font(Font.custom(&quot;Poppins-Regular&quot;, size: 16))<br>        .frame(width: 296, height: 21)<br>        .padding([.top], 16)<br>    }<br>  }<br>}</pre><p>We will also add a frame around it to specify its “boundaries” as well as some padding which makes sure it&#39;s at least a certain distance away from the Image.</p><p>Next, let’s build the three little dots on the screen. There are two ways of doing it. We can simply export it as an image and place it there. However, we can also create an HStack with 3 small circles. First, let’s define a custom color for the light gray circle (we can just use the built-in Color.black for the first one):</p><pre>extension Color{<br>    public static var lightGray: Color{<br>        Color.init(.sRGB, red: 217/255, green: 217/255, blue: 217/255, opacity: 1)<br>    }<br>}</pre><p>We can then fill the circles with this colour as such:</p><pre>struct WidgetInfo: View{<br>  var body: some View{<br>    VStack{<br>       Image(&quot;widgetInfo&quot;)<br>       Text(&quot;Widget to connect your app to all wearables&quot;)<br>        .multilineTextAlignment(.center) // makes sure you have multiline centering<br>        .font(Font.custom(&quot;Poppins-Bold&quot;, size: 20)) // Custom font with font size<br>        .frame(width: 261, height: 60)<br>        .padding([.top], 64)<br>       Text(&quot;Unlock the power of health data&quot;) // Line below<br>        .multilineTextAlignment(.center)<br>        .font(Font.custom(&quot;Poppins-Regular&quot;, size: 16))<br>        .frame(width: 296, height: 21)<br>        .padding([.top], 16)<br>       HStack{<br>          Circle().frame(width: 12, height: 12)<br>          Circle().fill(Color.lightGray).frame(width: 12, height: 12)<br>              .padding([.leading], 4)<br>          Circle().fill(Color.lightGray).frame(width: 12, height: 12)<br>              .padding([.leading], 4)<br>      }<br>      .padding([.top], 40)<br>    }<br>  }<br>}</pre><p>Almost there! The only thing remaining the button at the bottom:</p><p>Conveniently, SwiftUI has an object called Button for which we can use:</p><pre>Button(action: {<br>     // Perform some action here<br>    // We will add this later<br>}, label: {<br>    Text(&quot;Continue&quot;)<br>        .font(Font.custom(&quot;Poppins-Regular&quot;, size: 13))<br>        .foregroundColor(Color.white)<br>        .frame(width: 169, height: 33)<br>        .background(<br>            Rectangle()<br>                .fill(Color.darkBackground)<br>                .cornerRadius(6.5)<br>        )<br>        .padding([.top], 105)<br>}).padding()</pre><p>We can add a label argument which is essentially the design for which we want the button to look.</p><p>Putting this all together:</p><pre>struct WidgetInfo: View{<br>  var body: some View{<br>    VStack{<br>       Image(&quot;widgetInfo&quot;)<br>       Text(&quot;Widget to connect your app to all wearables&quot;)<br>        .multilineTextAlignment(.center) // makes sure you have multiline centering<br>        .font(Font.custom(&quot;Poppins-Bold&quot;, size: 20)) // Custom font with font size<br>        .frame(width: 261, height: 60)<br>        .padding([.top], 64)<br>       Text(&quot;Unlock the power of health data&quot;) // Line below<br>        .multilineTextAlignment(.center)<br>        .font(Font.custom(&quot;Poppins-Regular&quot;, size: 16))<br>        .frame(width: 296, height: 21)<br>        .padding([.top], 16)<br>       HStack{<br>          Circle().frame(width: 12, height: 12)<br>          Circle().fill(Color.lightGray).frame(width: 12, height: 12)<br>              .padding([.leading], 4)<br>          Circle().fill(Color.lightGray).frame(width: 12, height: 12)<br>              .padding([.leading], 4)<br>      }<br>      .padding([.top], 40)<br>      Button(action: {<br>                    <br>      }, label: {<br>          Text(&quot;Continue&quot;)<br>              .font(Font.custom(&quot;Poppins-Regular&quot;, size: 13))<br>              .foregroundColor(Color.white)<br>              .frame(width: 169, height: 33)<br>              .background(<br>                  Rectangle()<br>                      .fill(Color.darkBackground)<br>                      .cornerRadius(6.5)<br>              )<br>              .padding([.top], 105)<br>      }).padding()<br>    }<br>  }<br>}</pre><blockquote>Finalising</blockquote><p>You can move objects around to your own liking using different paddings, x offset, y offset, or even different width/height sizes. This will depend on your own taste.</p><p>For now, this will produce a View corresponding to our original design!</p><p>For our next part, we will go through linking the different Views together as well as special variables where we can change the states of a view.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=157f0637f1af" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terraapi/mobile-app-basics-ios-swift-ui-part-1-157f0637f1af">Mobile App Basics: iOS Swift UI (Part 1)</a> was originally published in <a href="https://medium.com/terraapi">Terra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OAuth2: Authenticating users made secure]]></title>
            <link>https://medium.com/terraapi/oauth2-authenticating-users-made-secure-7a75abd00ee8?source=rss-2cde8f8f2035------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a75abd00ee8</guid>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[user-security]]></category>
            <category><![CDATA[authentication]]></category>
            <dc:creator><![CDATA[Elliott]]></dc:creator>
            <pubDate>Thu, 06 Apr 2023 11:02:07 GMT</pubDate>
            <atom:updated>2023-04-06T11:02:07.079Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ydQCTCAOSn4wRqPm99NlJA.png" /></figure><p>For anyone who has ever been curious about building an application that embeds other services inside would probably have come across this term: OAuth2 (Open Authentication 2). For instance, if you were creating an app and want to allow your users to log in through Google, Facebook, or even maybe Twitter, you will need to use each of these companies’ respective OAuth2 systems to “authenticate” your users.</p><blockquote>What is OAuth2</blockquote><p>OAuth2 is a set of rules that allow users to authenticate to third-party apps (in this case your app is the app they are using and perhaps Google is the third-party app) without exposing their credentials or identity to you. This is how it works:</p><ul><li>You first have to receive a set of credentials to use a third-party app’s OAuth2 system commonly called: client id and client secret</li><li>When creating this, you will need to fill out your app’s information such as name, company name, website, address and etc. One of which would likely be a callback URL. This is the endpoint you must set in your app to allow the third-party app to redirect your user upon logging in</li></ul><p>Typically, after authentication, you should be able to request a token, normally called access_token that is used in every request to retrieve data for the user.</p><p>For example, a typical OAuth2 Session will go as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6sG0Gefh6j60tCEW.png" /></figure><p>Every app will implement it ever so slightly different from one another. <em>Keep an eye on the documentation to see what they need!</em></p><blockquote>Let’s try one</blockquote><p>Let us try to implement Google’s OAuth2 authentication as an example. Go ahead and create an app on <a href="https://console.cloud.google.com/apis/credentials/consent">google’s developer console</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4blOc3xied3mVLgP.png" /></figure><p>On the left, go to “OAuth Consent Screen” and fill out the details there. As for testing, we can leave basically everything blank except for the email and app name.</p><p>In the scopes section, you can select as many scopes as you want (these are essentially permissions that you will request from your users). For now, we will use profile one for testing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0uw9Gr9oqRepPUXZ.png" /></figure><p>Next, add your own email address as a testing user and finish the setup!</p><p>After completing the OAuth Screen setup, you can create an (OAuth2 Client) app on the project in the Credentials Tab:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KsRQTub0e4puLGbr.png" /></figure><p>For now, we will use a local host server at port 8088 for the callback URL (they call it to redirect URI here).</p><p>This will create a set of keys:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*Xa-IS15CQSMbDbNe.png" /></figure><p><em>Save this somewhere so that no one can see it!</em></p><p>Now that the app is set up, we can use it to authenticate a new Google user into our app. For this, we will be programming in python for simplicity using Flask.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b180578d4bd83c27132ad4fd6a5749c/href">https://medium.com/media/0b180578d4bd83c27132ad4fd6a5749c/href</a></iframe><p>We can create a simple web server with Flask at port 8088 running on a local host using the following script to be our “app”.</p><p>First, we must redirect the user to Google for authentication. This can be done by generating an authentication url according to OAuth2 specifications. We can easily do this using a library in python:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c611dc6ea8a619cedc86ba40fe5fe80a/href">https://medium.com/media/c611dc6ea8a619cedc86ba40fe5fe80a/href</a></iframe><p>This function would return an authentication URL that would look similar to this: <a href="https://accounts.google.com/o/oauth2/v2/auth?response_type=code&amp;client_id=138037670983-5l4jg8utussuo13tvq1im8cn2v0c99rs.apps.googleusercontent.com&amp;redirect_uri=http%3A%2F%2Flocalhost%3A8088&amp;scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&amp;state=Xduz6uV1SwvzJ4jxsosn7MkrNlojAJ&amp;prompt=consent&amp;access_type=offline">https://accounts.google.com/o/oauth2/v2/auth?response_type=code&amp;client_id=138037670983-5l4jg8utussuo13tvq1im8cn2v0c99rs.apps.googleusercontent.com&amp;redirect_uri=http%3A%2F%2Flocalhost%3A8088&amp;scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&amp;state=Xduz6uV1SwvzJ4jxsosn7MkrNlojAJ&amp;prompt=consent&amp;access_type=offline</a></p><p>Going to this URL will prompt the user to log in and accept permissions. After logging in, Google will automatically redirect the user to the flask server at http://localhost:8088 (our redirect URL) with a few query parameters, namely:</p><ul><li>state=<a href="http://localhost:8088/?state=Xduz6uV1SwvzJ4jxsosn7MkrNlojAJ&amp;code=4%2F0AVHEtk4CYs-IInn7tAJog9H8P5rWKm5FJnOxWO4I1WDaikOyO-eu_G95dJJYhUVt8hKnig&amp;scope=profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile">Xduz6uV1SwvzJ4jxsosn7MkrNlojAJ</a> (This will be the same “state” as the one generated from generate_auth_url . You can now match it to whoever it was that wanted to login)</li><li><a href="http://localhost:8088/?state=Xduz6uV1SwvzJ4jxsosn7MkrNlojAJ&amp;code=4%2F0AVHEtk4CYs-IInn7tAJog9H8P5rWKm5FJnOxWO4I1WDaikOyO-eu_G95dJJYhUVt8hKnig&amp;scope=profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile">code=4%2F0AVHEtk4CYs-IInn7tAJog9H8P5rWKm5FJnOxWO4I1WDaikOyO-eu_G95dJJYhUVt8hKnig</a></li><li><a href="http://localhost:8088/?state=Xduz6uV1SwvzJ4jxsosn7MkrNlojAJ&amp;code=4%2F0AVHEtk4CYs-IInn7tAJog9H8P5rWKm5FJnOxWO4I1WDaikOyO-eu_G95dJJYhUVt8hKnig&amp;scope=profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile">scope=profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile</a></li></ul><p>These are all the information you need to retrieve what is called an access token from Google for the user. To get the token, we will need to make a request to Google according to their docs:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce6dba74145af08344d5a2e0bce6dc6d/href">https://medium.com/media/ce6dba74145af08344d5a2e0bce6dc6d/href</a></iframe><p>The response object will look like this:</p><pre>{<br>  &quot;access_token&quot;: &quot;ya29.a0Ael9sCP9uHr_k6QpdKeezmBi--gT8AuEdD3F8zqi8EgzpCwD0HU0bCepxyde0fpud5ev4pnx5fchVoa1bo1CjUli7jlky_p5iHPcgmCMMXS51FueSPv_PTmvrP5udP89n3n3Kb1flfIHSfY18Fp2X40xYSnxaCgYKAVISARESFQF4udJhjKerSxzFbDOgqnd-MA5Oog0163&quot;,<br>  &quot;expires_in&quot;: 3599,<br>  &quot;refresh_token&quot;: &quot;1//03zBC4HVy3AgjCgYIARAAGAMSNwF-L9IrPoBvLSJC_-nyVvcOD7hnRgZM5Xu79ATdgFkGCSv_DaPMYqfeJoy9iDzQ9m1TT1p18yY&quot;,<br>  &quot;scope&quot;: &quot;https://www.googleapis.com/auth/userinfo.profile&quot;,<br>  &quot;token_type&quot;: &quot;Bearer&quot;,<br>  &quot;id_token&quot;: &quot;eyJhbGciOiJSUzI1NiIsImtpZCI6IjFhYWU4ZDdjOTIwNThiNWVlYTQ1Njg5NWJmODkwODQ1NzFlMzA2ZjMiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhenAiOiIxMzgwMzc2NzA5ODMtNWw0amc4dXR1c3N1bzEzdHZxMWltOGNuMnYwYzk5cnMuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhdWQiOiIxMzgwMzc2NzA5ODMtNWw0amc4dXR1c3N1bzEzdHZxMWltOGNuMnYwYzk5cnMuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMDQ2MzYxOTAwODU0MjY4MTE5NjYiLCJhdF9oYXNoIjoiZU0zVUxGeGhfcXc3ZE9FejNRQzdndyIsIm5hbWUiOiJFbGxpb3R0IFl1IiwicGljdHVyZSI6Imh0dHBzOi8vbGgzLmdvb2dsZXVzZXJjb250ZW50LmNvbS9hL0FHTm15eFpzaWFjZHZJWFdUSlBNbWgyQlQ5NTZiZDZKbXZGY3hZakVpYnR6bmc9czk2LWMiLCJnaXZlbl9uYW1lIjoiRWxsaW90dCIsImZhbWlseV9uYW1lIjoiWXUiLCJsb2NhbGUiOiJlbiIsImlhdCI6MTY4MDAwNTAyNiwiZXhwIjoxNjgwMDA4NjI2fQ.B-BzE-5V8IDJDSN30vNUKJ4AD2L0X0bHAJc1CxvogBqCyN3i2pZdLCcLqa98pgcUzpm6g6EaIys4I-GfVEkaj4nFoxzpeQMvyqmtbgPxMXoeQqb3b7hUwl2xMVFqKgL0J7dSw0m4FQdy14hfLUkuWCxua9dYkhWchIJkXpncmMfNEZINEPQDbrp1TUrU70hMH4650a4IK4Z1soK5JW7d1deD5XIHjSk55B_AD2IH6pd57cI_4qVB4j6FCxBFBviZPu3_RHsHfHsTVDp58oKIwZ28kCEwCX1O8HXLfka-yYhXx-Rg0xh7WJgv68tEcZo3jgjIfkR7XAeO_-Giz8BkBg&quot;<br>}</pre><p>That’s it! It would be best if you now stored this payload somewhere (ideally in a database) and you can now access this user’s “profile” data.</p><blockquote><em>Other </em>things<em> to note</em></blockquote><p>The example above shows how to specifically authenticate users through Google for your app. Each app would do something slightly different (for example, they might require you to post a JSON data object to request the access token rather than doing it in the query parameters. However, generally speaking, the flows are always the same as the OAuth2 protocol is an international standard, and if you follow the general steps above, you should be able to implement any OAuth2 systems into your app!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a75abd00ee8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terraapi/oauth2-authenticating-users-made-secure-7a75abd00ee8">OAuth2: Authenticating users made secure</a> was originally published in <a href="https://medium.com/terraapi">Terra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Team Spotlight: Introducing Halvard]]></title>
            <link>https://medium.com/terraapi/team-spotlight-introducing-halvard-4e39e816b302?source=rss-2cde8f8f2035------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e39e816b302</guid>
            <category><![CDATA[team-spotlight]]></category>
            <category><![CDATA[fitness]]></category>
            <category><![CDATA[terra-api]]></category>
            <category><![CDATA[wearables]]></category>
            <category><![CDATA[team]]></category>
            <dc:creator><![CDATA[Elliott]]></dc:creator>
            <pubDate>Tue, 21 Mar 2023 15:29:13 GMT</pubDate>
            <atom:updated>2023-03-21T15:29:13.077Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Every week we ask a </em><a href="http://tryterra.co/"><em>Terra</em></a><em> team member to let us know who they are. Here’s </em><a href="https://www.linkedin.com/in/halvardramstad/"><em>Halvard</em></a><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*F2qbTGL7e-2m-6ZV.jpeg" /></figure><p><strong>What wearables do you use?</strong></p><p>I currently rock the <a href="https://tryterra.co/integrations/oura">Oura Ring</a> as I was fortunate enough to be able to borrow a ring from our office. I used a <a href="https://tryterra.co/integrations/whoop">WHOOP</a> before that, and I also used to wear the <a href="https://tryterra.co/integrations/garmin">Garmin</a> HRM when I rowed in my Uni days. Oh — and I also use the Garmin Forerunner 945 when I’m running and on a daily basis.</p><p><strong>Rowing… as in ergometer training — or on the water?</strong></p><p>I picked up rowing when I lived in the Netherlands a couple of years ago, as rowing is a huge part of their culture. Also, during my master’s degree at Imperial College London, I was a member of the rowing club. It was a really cool experience, but hands down one of the most physically and mentally grueling sports I’ve ever tried out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*6MRV4QGPDzz4Qv2z.png" /><figcaption>Halvard racing in the Quintin Head Regatta at the River Thames in London with Imperial College Boat Club</figcaption></figure><p><strong>What’s your background prior to coming to London and Terra?</strong></p><p>I grew up in Oslo, Norway, and played football professionally for FC Lyn Oslo in the Norwegian 2nd Division during high school, and then I moved to the United States on a scholarship to play collegiate football — or <em>soccer</em> as they call it in the states haha! I did a bachelor’s degree in Economics with a small concentration in Computer Science before I moved to London for my master’s degree in International Management at Imperial College London.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Kn3im_cft9r6vuQk.jpeg" /><figcaption>Halvard playing Division 1 football in the CAA conference in the United States</figcaption></figure><p><strong>What do you miss the most about Norway?</strong></p><p>I grew up in a family that loves to spend time outdoors. I love to go fishing and sailing in the summers and I try to go cross-country skiing as often as I can when I’m back home during the winter. Actually, I escaped back to Norway a couple of weekends ago just to be able to go skiing one more time before the snow disappears for the summer, haha!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*YSXBXxVzQeZMaUzc.jpeg" /><figcaption>Halvard cross-country skiing with his father in Geilo, Norway this past winter</figcaption></figure><p><strong>How have you found these first few months at Terra?</strong></p><p>It has been a lot of fun. We’re definitely moving at 100+ mph, which was certainly an adjustment for me early on… but I can honestly say that I’ve never been a part of a team with so many extremely smart and talented people before that I’ve now become really close with. We have a really good group of people in our office and I think that’s a major part of our success.</p><p><strong>Speed is the name of the game… So what has been your highlight so far?</strong></p><p><a href="https://blog.tryterra.co/ic-hack-2023-e0d22b583564">IC Hack </a>— without a doubt! It was such a cool experience to be able to help out with organizing our challenge for this year as a Gold Sponsor and seeing the Terra logo light up the Queen’s Tower was surreal. Imperial has so many talented young engineers and it was awesome to see what they built with our API in just a few hours.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*LxCWYXOfmxjkrtM6.jpeg" /><figcaption>The Terra Avengers holding a workshop for the hackers from Imperial at IC Hack 23</figcaption></figure><p><strong>Lastly, what’s your take on the future of wearables?</strong></p><p>Oh man, we’re just getting started… No, but seriously — I think the coolest thing about being a part of Terra at this stage is that I believe we’re just scratching the surface of what’s possible to do with wearable technology. We have come so far in just a snippet of time and I can only imagine where the wearables technology space will be in 4–5 years.</p><p>A really cool part of my role as a Growth Engineer, is that I get to talk with our <a href="https://tryterra.co/customers">customers</a> on a daily basis about their use cases with wearable technology — and it’s amazing to see some of the things that they are building with our API and I’m really excited to support these developers going forward.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*2YS7pks0dyXHNFsW.jpeg" /><figcaption>Halvard enjoying one of many protein-filled meals with the Terra Avengers family</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pvWdjMRw-Do8X6saOcqaUQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e39e816b302" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terraapi/team-spotlight-introducing-halvard-4e39e816b302">Team Spotlight: Introducing Halvard</a> was originally published in <a href="https://medium.com/terraapi">Terra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WHOOP Integration series Part 4: Data from TERRA API]]></title>
            <link>https://medium.com/terraapi/whoop-integration-series-part-4-data-from-terra-api-253b217a162?source=rss-2cde8f8f2035------2</link>
            <guid isPermaLink="false">https://medium.com/p/253b217a162</guid>
            <category><![CDATA[whoops]]></category>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[terra]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Elliott]]></dc:creator>
            <pubDate>Thu, 24 Nov 2022 13:05:00 GMT</pubDate>
            <atom:updated>2022-11-24T13:05:00.940Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_9DpWOkf6U9h5VlA8UMfug.png" /></figure><p>Continuing our Integration series on WHOOP, we are discussing the data available from our API when fetching data from WHOOP.</p><p>As a reminder, the WHOOP <a href="https://blog.tryterra.co/search?q=whoop+integration+series">series</a> contains:</p><ul><li><a href="https://blog.tryterra.co/whoop-integration-series-part-1-getting-started-with-rest-apis-707d15dc6b8a">Part 1</a>: Getting started with Rest APIs</li><li><a href="https://blog.tryterra.co/whoop-integration-series-part-2-data-available-from-the-api-ec4337a9455b">Part 2</a>: Data available from the API</li><li><a href="https://blog.tryterra.co/whoop-integration-series-part-3-integrating-with-terra-api-19d8fc36b8c3">Part 3:</a> Integrating with Terra API</li><li>Part 4: Data from TERRA API</li></ul><p>As WHOOP users may know, WHOOP provides a graph with their users’ heart rate 24/7 at one-minute intervals. However, did you know that WHOOP’s sampling frequency is among the highest in the wearables space?</p><p>As quoted by <a href="https://twitter.com/whoop/status/1231949716184862720?lang=en">WHOOP</a>:</p><blockquote>“A key differentiator of WHOOP is that its sensors collect data 100 times per second, 24 hours a day! The high sampling rate allows it to dish out statistics with great accuracy.” — <a href="https://twitter.com/HFGEnthusiast">@HFGEnthusiast</a></blockquote><blockquote>WHOOP’s API</blockquote><p>As accurate or abundant as the data from WHOOP may be, they have removed many granular details from their API. Currently, only summarised or calculated statistical data such as max, min, and average heart rate are available from their API.</p><p>However, to compensate for the lack of sampled data, WHOOP allows for integrating webhooks with their API. This means that when you integrate, you will always get the most updated events/activities for your users.</p><blockquote>Terra Webhooks</blockquote><p>Like every integration, Terra provides, Terra provides on update webhooks for WHOOP integration.</p><p>This means after authentication, you simply need to start <a href="https://blog.tryterra.co/how-tos-webhooks-5ac374e48640">listening to Terra webhook</a> events in your backend to receive the most up-to-date data for your users. For example, your user completes a workout:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*TrPRwdeJXR_Fp9wQq7RIIQ.jpeg" /></figure><p>Once this information is logged to WHOOP’s server, your backend will receive a payload with all the information shown on the device.</p><pre>{<br>    &quot;heart_rate_data&quot;: {<br>        &quot;summary&quot;: {<br>            &quot;hr_zone_data&quot;: [<br>                {<br>                    &quot;duration_seconds&quot;: 440.262,<br>                    &quot;zone&quot;: 0,<br>                    &quot;start_percentage&quot;: 0,<br>                    &quot;end_percentage&quot;: 50,<br>                    &quot;name&quot;: &quot;Resting&quot;<br>                },<br>                {<br>                    &quot;duration_seconds&quot;: 812.341,<br>                    &quot;zone&quot;: 1,<br>                    &quot;start_percentage&quot;: 50,<br>                    &quot;end_percentage&quot;: 60,<br>                    &quot;name&quot;: &quot;Very light&quot;<br>                },<br>                {<br>                    &quot;duration_seconds&quot;: 147.079,<br>                    &quot;zone&quot;: 2,<br>                    &quot;start_percentage&quot;: 60,<br>                    &quot;end_percentage&quot;: 70,<br>                    &quot;name&quot;: &quot;Light&quot;<br>                },<br>                {<br>                    &quot;duration_seconds&quot;: 0.0,<br>                    &quot;zone&quot;: 3,<br>                    &quot;start_percentage&quot;: 70,<br>                    &quot;end_percentage&quot;: 80,<br>                    &quot;name&quot;: &quot;Moderate&quot;<br>                },<br>                {<br>                    &quot;duration_seconds&quot;: 0.0,<br>                    &quot;zone&quot;: 4,<br>                    &quot;start_percentage&quot;: 80,<br>                    &quot;end_percentage&quot;: 90,<br>                    &quot;name&quot;: &quot;Hard&quot;<br>                },<br>                {<br>                    &quot;duration_seconds&quot;: 0.0,<br>                    &quot;zone&quot;: 5,<br>                    &quot;start_percentage&quot;: 90,<br>                    &quot;end_percentage&quot;: 100,<br>                    &quot;name&quot;: &quot;Maximum&quot;<br>                }<br>            ],<br>            &quot;max_hr_bpm&quot;: 127,<br>            &quot;user_max_hr_bpm&quot;: null,<br>            &quot;resting_hr_bpm&quot;: null,<br>            &quot;min_hr_bpm&quot;: null,<br>            &quot;avg_hrv_sdnn&quot;: null,<br>            &quot;avg_hrv_rmssd&quot;: null,<br>            &quot;avg_hr_bpm&quot;: 94<br>        },<br>        &quot;detailed&quot;: {<br>            &quot;hrv_samples_sdnn&quot;: [],<br>            &quot;hr_samples&quot;: [],<br>            &quot;hrv_samples_rmssd&quot;: []<br>        }<br>    },<br>    &quot;metadata&quot;: {<br>        &quot;summary_id&quot;: 553531533,<br>        &quot;upload_type&quot;: 1,<br>        &quot;end_time&quot;: &quot;2022-11-23T17:55:55.731000+00:00&quot;,<br>        &quot;city&quot;: null,<br>        &quot;country&quot;: null,<br>        &quot;start_time&quot;: &quot;2022-11-23T17:32:35.887000+00:00&quot;,<br>        &quot;state&quot;: null,<br>        &quot;name&quot;: &quot;Functional Fitness&quot;,<br>        &quot;type&quot;: 113<br>    },<br>    &quot;calories_data&quot;: {<br>        &quot;net_activity_calories&quot;: 71.7,<br>        &quot;net_intake_calories&quot;: null,<br>        &quot;calorie_samples&quot;: [],<br>        &quot;BMR_calories&quot;: null,<br>        &quot;total_burned_calories&quot;: null<br>    },<br>    &quot;distance_data&quot;: {<br>        &quot;summary&quot;: {<br>            &quot;steps&quot;: null,<br>            &quot;elevation&quot;: {<br>                &quot;gain_planned_meters&quot;: null,<br>                &quot;min_meters&quot;: null,<br>                &quot;loss_actual_meters&quot;: null,<br>                &quot;avg_meters&quot;: null,<br>                &quot;gain_actual_meters&quot;: 0.0,<br>                &quot;max_meters&quot;: null<br>            },<br>            &quot;distance_meters&quot;: 0.0,<br>            &quot;floors_climbed&quot;: null,<br>            &quot;swimming&quot;: {<br>                &quot;num_strokes&quot;: null,<br>                &quot;num_laps&quot;: null,<br>                &quot;pool_length_meters&quot;: null<br>            }<br>        },<br>        &quot;detailed&quot;: {<br>            &quot;step_samples&quot;: [],<br>            &quot;floors_climbed_samples&quot;: [],<br>            &quot;elevation_samples&quot;: [],<br>            &quot;distance_samples&quot;: []<br>        }<br>    },<br>    &quot;active_durations_data&quot;: {<br>        &quot;activity_seconds&quot;: null,<br>        &quot;moderate_intensity_seconds&quot;: 0.0,<br>        &quot;activity_levels_samples&quot;: [],<br>        &quot;vigorous_intensity_seconds&quot;: 0.0,<br>        &quot;inactivity_seconds&quot;: 812.341,<br>        &quot;num_continuous_inactive_periods&quot;: null,<br>        &quot;rest_seconds&quot;: null,<br>        &quot;low_intensity_seconds&quot;: 147.079<br>    },<br>    &quot;energy_data&quot;: {<br>        &quot;energy_planned_kilojoules&quot;: null,<br>        &quot;energy_kilojoules&quot;: 300.11462<br>    },<br>    &quot;strain_data&quot;: {<br>        &quot;strain_level&quot;: 4.7311<br>    }<br>}</pre><p>Which contains the majority of the details returned by the WHOOP device. You can then process this in your server and perform necessary operations before displaying or giving your users insights on the workout.</p><blockquote>Integration</blockquote><p>Terra provides one integration solution for all wearable companies out there. Imagine if you were to integrate with WHOOP finding out they support webhooks, then you move to another provider such as OURA and find out that they don’t. This means you will have to adapt your systems to retrieve and receive the most up-to-date data from OURA and WHOOP differently.</p><p>Integration with Terra would solve all the mismatches and inconsistent REST API designs for you so that you can focus on building the core of your product!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=253b217a162" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terraapi/whoop-integration-series-part-4-data-from-terra-api-253b217a162">WHOOP Integration series Part 4: Data from TERRA API</a> was originally published in <a href="https://medium.com/terraapi">Terra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WHOOP Integration series Part 3: Integrating with Terra API]]></title>
            <link>https://medium.com/terraapi/whoop-integration-series-part-3-integrating-with-terra-api-19d8fc36b8c3?source=rss-2cde8f8f2035------2</link>
            <guid isPermaLink="false">https://medium.com/p/19d8fc36b8c3</guid>
            <category><![CDATA[terra]]></category>
            <category><![CDATA[fitness-api]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[whoops]]></category>
            <category><![CDATA[blog]]></category>
            <dc:creator><![CDATA[Elliott]]></dc:creator>
            <pubDate>Wed, 23 Nov 2022 13:51:58 GMT</pubDate>
            <atom:updated>2022-11-24T13:07:40.681Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6PqWET0SXgnQraCe8RdIUA.png" /></figure><p>Adding WHOOP as an integration to your app is fairly straightforward thanks to the standardized integration method. Following the documentation, you simply have to implement: auth flow, data gathering, and data processing.</p><p>However, if you are building an app utilizing fitness data, you most likely are not gonna want to stop at one data provider. This means you would need to build multiple auth flows, multiple data gathering methods, and data processing systems one for each integration. How about instead of doing this, you make one integration only, and this provides you access to all the wearable companies as well (including WHOOP)?</p><p>This is where <a href="https://tryterra.co/products/api">Terra</a> comes in.</p><blockquote>Authentication</blockquote><p>Like any data flow, authentication is first and foremost, the most important part. You need to be able to get the user’s consent to retrieve their data. This can be done through our (customizable) widget:</p><pre>curl --location --request POST &#39;https://api.tryterra.co/v2/auth/generateWidgetSession&#39; \<br>--header &#39;dev-id: DEV-ID&#39; \<br>--header &#39;X-API-Key: X-API-KEY&#39;</pre><p>Where DEV-ID and X-API-KEY are credentials you receive when you sign up with <a href="https://dashboard.tryterra.co/">Terra</a>.</p><p>This will provide you with a widget URL that you can display to your user to log in with whatever provider they want:</p><pre>{<br>    &quot;expires_in&quot;: 900,<br>    &quot;session_id&quot;: &quot;aece836a-7d69-4489-82cb-1c348e68097e&quot;,<br>    &quot;status&quot;: &quot;success&quot;,<br>    &quot;url&quot;: &quot;https://widget.tryterra.co/session/aece836a-7d69-4489-82cb-1c348e68097e&quot;<br>}</pre><p>The flow would look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Vtr3iIxg1UIAErmb" /></figure><p>The user is uniquely identified by a user_id provided at the auth success page (last in the image above) URL&#39;s query parameters.</p><blockquote>Data Gathering</blockquote><p>That&#39;s it! When you have signed up with us, you can set up a webhook URL (under API -&gt; Customise) for which we will continuously send you new events for the user that is authenticated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KcqREkL77bP47R2HNRxsVg.png" /></figure><blockquote>Data Processing</blockquote><p>The data sent to your webhooks are all of the same structure. They will always contain the same formatting, same field names, and same units. For example, a webhook event from any provider (for example WHOOP) for a workout your user completed will always look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fb318b0060c432855e619550c1b12a3/href">https://medium.com/media/5fb318b0060c432855e619550c1b12a3/href</a></iframe><p>This makes processing events from Terra very simple and elegant as you simply need to pick off points you need from the payload for whatever your app requires.</p><blockquote>Advanced</blockquote><p>Now, what if you want historic data as well? Tera also has endpoints that allow you to retrieve historical data! You can make a simple HTTP request formatted as:</p><pre>curl --location --request GET &#39;https://api.tryterra.co/v2/activity?end_date=2022-10-29&amp;start_date=2022-10-28&amp;user_id=USER_ID&#39; \<br>--header &#39;dev-id: DEV-ID&#39; \<br>--header &#39;X-API-Key: X-API-KEY&#39;</pre><p>Where again, DEV-ID and X-API-KEY are credentials you receive when you sign up for <a href="https://dashboard.tryterra.co/">Terra</a>. USER_ID on the other hand, is the unique identifier we provide to you after authentication completion to identify the user that has authenticated. The request above with the requested start_date and end_date will gather (and send) the workouts the user has completed over that period of time to your webhook.</p><blockquote>Buy or Build</blockquote><p>Terra API follows a very simple and easy-to-use structure that allows integrations to WHOOP, Garmin, Fitbit, and hundreds of fitness wearables in one single integration.</p><p>You may think that if you can do one, you can go over and do all the others as much as your app would want to support.</p><p>However, there are many things to consider, such as partnerships, parsing different data models from other companies, changing your auth system slightly for every company you want to integrate with, and at the same time building a frontend structure to display all of your integrations! These can make a huge difference between if you want to <a href="https://blog.tryterra.co/buy-or-build-should-you-build-integrations-in-house-or-use-terras-api-18030ccf4560">buy or build in-house</a>.</p><p>In our Integration series on WHOOP, we are discussing the data available from our API when fetching data from WHOOP.</p><p>As a reminder, the WHOOP <a href="https://blog.tryterra.co/search?q=whoop+integration+series">series</a> contains:</p><ul><li><a href="https://blog.tryterra.co/whoop-integration-series-part-1-getting-started-with-rest-apis-707d15dc6b8a">Part 1</a>: Getting started with Rest APIs</li><li><a href="https://blog.tryterra.co/whoop-integration-series-part-2-data-available-from-the-api-ec4337a9455b">Part 2</a>: Data available from the API</li><li><a href="https://blog.tryterra.co/whoop-integration-series-part-3-integrating-with-terra-api-19d8fc36b8c3">Part 3:</a> Integrating with Terra API</li><li><a href="https://blog.tryterra.co/whoop-integration-series-part-4-data-from-terra-api-253b217a162">Part 4</a>: Data from TERRA API</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19d8fc36b8c3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terraapi/whoop-integration-series-part-3-integrating-with-terra-api-19d8fc36b8c3">WHOOP Integration series Part 3: Integrating with Terra API</a> was originally published in <a href="https://medium.com/terraapi">Terra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WHOOP Integration series Part 2: Data available from the API]]></title>
            <link>https://medium.com/terraapi/whoop-integration-series-part-2-data-available-from-the-api-ec4337a9455b?source=rss-2cde8f8f2035------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec4337a9455b</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[insights]]></category>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[fitness-api]]></category>
            <category><![CDATA[whoops]]></category>
            <dc:creator><![CDATA[Elliott]]></dc:creator>
            <pubDate>Tue, 22 Nov 2022 10:56:38 GMT</pubDate>
            <atom:updated>2022-11-24T13:07:08.648Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mpzQq0HZKGufLjsIAn5gkg.png" /></figure><p>With WHOOP’s recent announcement of their open API, we at Terra were very excited to see what we can get from their API.</p><blockquote>API vs Device Data</blockquote><p>WHOOP’s API currently can only provide a top-level summary of the user’s health data: how well they slept, how much strain they put their body through, and how well did they recover.</p><p><strong>Sleep and Recovery:</strong> The device provides you with a detailed analysis of how you’ve slept for a night, providing resting heart rates, heart rate variability, respiratory rates, amount of time spent in each sleep stage, amount of wake up events, and your heart rates over the night. If we take an example here, we can see WHOOP displays the following for a night of sleep and recovery over the week.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*LzpQJ_DTIKOxD-mA94BhxA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*d2qeA7LXLdivWw_jTbjBlA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*JM8GdP8aaUKtwLe9ajxWfA.jpeg" /></figure><p>Most of the data points above can be retrieved from the API. This would populate respective fields in Terra’s sleep data payload. For example, for the night of sleep above, the payload below is returned.</p><pre>  {<br>      &quot;readiness_data&quot;: {<br>          &quot;readiness&quot;: 76.0,<br>          &quot;recovery_level&quot;: 0<br>      },<br>      &quot;device_data&quot;: {<br>          &quot;other_devices&quot;: [],<br>          &quot;activation_timestamp&quot;: null,<br>          &quot;manufacturer&quot;: null,<br>          &quot;software_version&quot;: null,<br>          &quot;serial_number&quot;: null,<br>          &quot;name&quot;: null,<br>          &quot;hardware_version&quot;: null<br>      },<br>      &quot;metadata&quot;: {<br>          &quot;start_time&quot;: &quot;2022-09-11T01:08:42.703000+07:00&quot;,<br>          &quot;is_nap&quot;: false,<br>          &quot;end_time&quot;: &quot;2022-09-11T10:02:11.493000+07:00&quot;,<br>          &quot;upload_type&quot;: 1<br>      },<br>      &quot;temperature_data&quot;: {<br>          &quot;delta&quot;: null<br>      },<br>      &quot;sleep_durations_data&quot;: {<br>          &quot;other&quot;: {<br>              &quot;duration_in_bed_seconds&quot;: null,<br>              &quot;duration_unmeasurable_sleep_seconds&quot;: 0.0<br>          },<br>          &quot;asleep&quot;: {<br>              &quot;duration_asleep_state_seconds&quot;: 30086.76,<br>              &quot;num_REM_events&quot;: 4,<br>              &quot;duration_REM_sleep_state_seconds&quot;: 8201.357,<br>              &quot;duration_deep_sleep_state_seconds&quot;: 5342.427,<br>              &quot;duration_light_sleep_state_seconds&quot;: 16542.976<br>          },<br>          &quot;sleep_efficiency&quot;: 0.9442353,<br>          &quot;hypnogram_samples&quot;: [],<br>          &quot;awake&quot;: {<br>              &quot;num_wakeup_events&quot;: 12,<br>              &quot;wake_up_latency_seconds&quot;: null,<br>              &quot;num_out_of_bed_events&quot;: null,<br>              &quot;duration_long_interruption_seconds&quot;: null,<br>              &quot;duration_awake_state_seconds&quot;: 1776.865,<br>              &quot;duration_short_interruption_seconds&quot;: null,<br>              &quot;sleep_latency_seconds&quot;: null<br>          }<br>      },<br>      &quot;respiration_data&quot;: {<br>          &quot;breaths_data&quot;: {<br>              &quot;start_time&quot;: null,<br>              &quot;max_breaths_per_min&quot;: null,<br>              &quot;avg_breaths_per_min&quot;: 15.058594,<br>              &quot;end_time&quot;: null,<br>              &quot;on_demand_reading&quot;: null,<br>              &quot;samples&quot;: [],<br>              &quot;min_breaths_per_min&quot;: null<br>          },<br>          &quot;oxygen_saturation_data&quot;: {<br>              &quot;start_time&quot;: null,<br>              &quot;end_time&quot;: null,<br>              &quot;samples&quot;: [],<br>              &quot;avg_saturation_percentage&quot;: 97.63333<br>          },<br>          &quot;snoring_data&quot;: {<br>              &quot;start_time&quot;: null,<br>              &quot;end_time&quot;: null,<br>              &quot;total_snoring_duration_seconds&quot;: null,<br>              &quot;samples&quot;: [],<br>              &quot;num_snoring_events&quot;: null<br>          }<br>      },<br>      &quot;heart_rate_data&quot;: {<br>          &quot;summary&quot;: {<br>              &quot;avg_hrv_sdnn&quot;: null,<br>              &quot;user_max_hr_bpm&quot;: null,<br>              &quot;resting_hr_bpm&quot;: 59.0,<br>              &quot;avg_hrv_rmssd&quot;: 60.33115,<br>              &quot;min_hr_bpm&quot;: null,<br>              &quot;avg_hr_bpm&quot;: null,<br>              &quot;max_hr_bpm&quot;: null<br>          },<br>          &quot;detailed&quot;: {<br>              &quot;hrv_samples_rmssd&quot;: [],<br>              &quot;hr_samples&quot;: [],<br>              &quot;hrv_samples_sdnn&quot;: []<br>          }<br>      }<br>  }</pre><p><strong>Strain:</strong> WHOOP also provides a detailed breakdown of how much strain the user has put on their body. This comes in a strain score going between 0 and 21. This score accumulates over the day as the user completes workouts, or simply by performing everyday tasks.</p><p>If we take a look at the device, the workout performed on the left produced a strain of 14.6 which on a corresponding day, produced a total strain of 18.1. The workout has details on how much time was spent on each HR zone along with heart rate statistics, calories and duration data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*J4HpUOlRLwwTF2EugWYEtA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*ARZv983rrU3I5RnuToRsTA.jpeg" /></figure><p>The workout details above can be retrieved by Terra’s API as shown below:</p><pre>{<br>    &quot;oxygen_data&quot;: {<br>        &quot;avg_saturation_percentage&quot;: null,<br>        &quot;vo2max_ml_per_min_per_kg&quot;: null,<br>        &quot;vo2_samples&quot;: [],<br>        &quot;saturation_samples&quot;: []<br>    },<br>    &quot;polyline_map_data&quot;: {<br>        &quot;summary_polyline&quot;: null<br>    },<br>    &quot;metadata&quot;: {<br>        &quot;type&quot;: 108,<br>        &quot;country&quot;: null,<br>        &quot;summary_id&quot;: 510541643,<br>        &quot;state&quot;: null,<br>        &quot;start_time&quot;: &quot;2022-09-15T12:59:50.889000+08:00&quot;,<br>        &quot;name&quot;: &quot;Activity&quot;,<br>        &quot;end_time&quot;: &quot;2022-09-15T14:45:33.507000+08:00&quot;,<br>        &quot;city&quot;: null,<br>        &quot;upload_type&quot;: 1<br>    },<br>    &quot;strain_data&quot;: {<br>        &quot;strain_level&quot;: 14.604<br>    },<br>    &quot;distance_data&quot;: {<br>        &quot;summary&quot;: {<br>            &quot;swimming&quot;: {<br>                &quot;num_laps&quot;: null,<br>                &quot;pool_length_meters&quot;: null,<br>                &quot;num_strokes&quot;: null<br>            },<br>            &quot;steps&quot;: null,<br>            &quot;floors_climbed&quot;: null,<br>            &quot;elevation&quot;: {<br>                &quot;avg_meters&quot;: null,<br>                &quot;gain_planned_meters&quot;: null,<br>                &quot;loss_actual_meters&quot;: null,<br>                &quot;gain_actual_meters&quot;: 0.0,<br>                &quot;min_meters&quot;: null,<br>                &quot;max_meters&quot;: null<br>            },<br>            &quot;distance_meters&quot;: 0.0<br>        },<br>        &quot;detailed&quot;: {<br>            &quot;distance_samples&quot;: [],<br>            &quot;floors_climbed_samples&quot;: [],<br>            &quot;elevation_samples&quot;: [],<br>            &quot;step_samples&quot;: []<br>        }<br>    },<br>    &quot;heart_rate_data&quot;: {<br>        &quot;summary&quot;: {<br>            &quot;user_max_hr_bpm&quot;: null,<br>            &quot;min_hr_bpm&quot;: null,<br>            &quot;max_hr_bpm&quot;: 167,<br>            &quot;hr_zone_data&quot;: [<br>                {<br>                    &quot;end_percentage&quot;: 50,<br>                    &quot;duration_seconds&quot;: 0.0,<br>                    &quot;name&quot;: &quot;Resting&quot;,<br>                    &quot;start_percentage&quot;: 0,<br>                    &quot;zone&quot;: 0<br>                },<br>                {<br>                    &quot;end_percentage&quot;: 60,<br>                    &quot;duration_seconds&quot;: 339.38,<br>                    &quot;name&quot;: &quot;Very light&quot;,<br>                    &quot;start_percentage&quot;: 50,<br>                    &quot;zone&quot;: 1<br>                },<br>                {<br>                    &quot;end_percentage&quot;: 70,<br>                    &quot;duration_seconds&quot;: 2058.107,<br>                    &quot;name&quot;: &quot;Light&quot;,<br>                    &quot;start_percentage&quot;: 60,<br>                    &quot;zone&quot;: 2<br>                },<br>                {<br>                    &quot;end_percentage&quot;: 80,<br>                    &quot;duration_seconds&quot;: 2552.245,<br>                    &quot;name&quot;: &quot;Moderate&quot;,<br>                    &quot;start_percentage&quot;: 70,<br>                    &quot;zone&quot;: 3<br>                },<br>                {<br>                    &quot;end_percentage&quot;: 90,<br>                    &quot;duration_seconds&quot;: 1392.925,<br>                    &quot;name&quot;: &quot;Hard&quot;,<br>                    &quot;start_percentage&quot;: 80,<br>                    &quot;zone&quot;: 4<br>                },<br>                {<br>                    &quot;end_percentage&quot;: 100,<br>                    &quot;duration_seconds&quot;: 0.0,<br>                    &quot;name&quot;: &quot;Maximum&quot;,<br>                    &quot;start_percentage&quot;: 90,<br>                    &quot;zone&quot;: 5<br>                }<br>            ],<br>            &quot;avg_hr_bpm&quot;: 134,<br>            &quot;avg_hrv_sdnn&quot;: null,<br>            &quot;avg_hrv_rmssd&quot;: null,<br>            &quot;resting_hr_bpm&quot;: null<br>        },<br>        &quot;detailed&quot;: {<br>            &quot;hrv_samples_rmssd&quot;: [],<br>            &quot;hrv_samples_sdnn&quot;: [],<br>            &quot;hr_samples&quot;: []<br>        }<br>    },<br>    &quot;power_data&quot;: {<br>        &quot;avg_watts&quot;: null,<br>        &quot;power_samples&quot;: [],<br>        &quot;max_watts&quot;: null<br>    },<br>    &quot;active_durations_data&quot;: {<br>        &quot;low_intensity_seconds&quot;: 2058.107,<br>        &quot;activity_levels_samples&quot;: [],<br>        &quot;activity_seconds&quot;: null,<br>        &quot;rest_seconds&quot;: null,<br>        &quot;moderate_intensity_seconds&quot;: 2552.245,<br>        &quot;inactivity_seconds&quot;: 339.38,<br>        &quot;num_continuous_inactive_periods&quot;: null,<br>        &quot;vigorous_intensity_seconds&quot;: 1392.925<br>    },<br>    &quot;energy_data&quot;: {<br>        &quot;energy_kilojoules&quot;: 4064.4888,<br>        &quot;energy_planned_kilojoules&quot;: null<br>    }<br>    ...<br>}</pre><blockquote>Left Out</blockquote><p>From the data points analyzed above, you may have noticed two very important fields missing that are shown on the device but not retrieved by the API:</p><p><strong>Heart Rates</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qwYVPkZG7bfdRa62fxucBg.png" /></figure><p>WHOOP provides a dashboard with all the user’s heart rates measured by the device (at 1 minute intervals). This information are used by many developers to make in-depth analytics on their users’ health profile.</p><p><strong>Sleep Samples</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9RFmom1z737eULs2dGjz-A.png" /></figure><p>WHOOP provides in detail the times the user goes from awake to light sleep, light sleep to deep sleep, deep sleep to rem sleep and etc. This information is essential for apps that wish to track sleep closely for their users. Knowing when they go from light sleep to deep sleep allows the developer to further suggest how to maximize the time spent in deep sleep (for better recovery).</p><blockquote>API Potentials</blockquote><p>The device data left out of the API are common data fields provided by fitness wearable companies such as GARMIN, FITBIT, and OURA in their APIs. They are what enable developers to make truly personalized apps that can change the health and fitness market.</p><p>We at Terra enable our developers to do so already by providing as much data as possible from every integration we do, from our <a href="https://tryterra.co/products/api">fitness API</a>.</p><p>In our Integration series on WHOOP, we are discussing the data available from our API when fetching data from WHOOP.</p><p>As a reminder, the WHOOP <a href="https://blog.tryterra.co/search?q=whoop+integration+series">series</a> contains:</p><ul><li><a href="https://blog.tryterra.co/whoop-integration-series-part-1-getting-started-with-rest-apis-707d15dc6b8a">Part 1</a>: Getting started with Rest APIs</li><li><a href="https://blog.tryterra.co/whoop-integration-series-part-2-data-available-from-the-api-ec4337a9455b">Part 2</a>: Data available from the API</li><li><a href="https://blog.tryterra.co/whoop-integration-series-part-3-integrating-with-terra-api-19d8fc36b8c3">Part 3:</a> Integrating with Terra API</li><li><a href="https://blog.tryterra.co/whoop-integration-series-part-4-data-from-terra-api-253b217a162">Part 4</a>: Data from TERRA API</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec4337a9455b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terraapi/whoop-integration-series-part-2-data-available-from-the-api-ec4337a9455b">WHOOP Integration series Part 2: Data available from the API</a> was originally published in <a href="https://medium.com/terraapi">Terra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WHOOP Integration series Part 1: Getting started with Rest APIs]]></title>
            <link>https://medium.com/terraapi/whoop-integration-series-part-1-getting-started-with-rest-apis-707d15dc6b8a?source=rss-2cde8f8f2035------2</link>
            <guid isPermaLink="false">https://medium.com/p/707d15dc6b8a</guid>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[whoops]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Elliott]]></dc:creator>
            <pubDate>Mon, 21 Nov 2022 10:36:37 GMT</pubDate>
            <atom:updated>2022-11-24T13:43:52.171Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1uimDnEgiMGifchlJmF1bA.png" /></figure><p>For years, Garmin, Fitbit, Polar, and other fitness tracking companies have allowed their developer enthusiasts to access their data through (mainly) REST APIs. This has allowed these companies&#39; user base to grow as more and more apps and tools are developed around their data.</p><p>After about six months since WHOOP started syncing its data outside of its ecosystem (exclusively to <a href="https://blog.tryterra.co/whoop-syncs-health-data-to-apple-health-ee298d328f41">Apple Health</a>), WHOOP has followed suit and started exposing its API endpoints to allow other developers to access and play with their data.</p><blockquote>Getting Started</blockquote><p>Like Terra&#39;s API, WHOOP&#39;s API is a <a href="https://blog.tryterra.co/how-tos-using-rest-apis-b8d98fc8f03b">REST API</a> that allows you to gather data using HTTP requests in a specific format.</p><p>Typically REST APIs that allow you to gather data from users will have to follow a series of the same steps:</p><ul><li>Authentication</li><li>Data Gathering</li><li>Data Processing</li></ul><p><strong>Authentication: </strong>Like a lot of recent APIs, WHOOP&#39;s authentication system is done through OAuth2. However, everyone&#39;s OAuth2 system is always slightly different. This would cause a hassle if you integrated with WHOOP and other OAuth2 authentication systems yourself.</p><p>Terra has abstracted this system away from you and allows you to follow a single auth flow for every provider there is. However, you were to integrate to WHOOP through OAuth2, you will have to keep track of ACCESS TOKENs and REFRESH TOKENs internally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*posGoM6rDZLhra3dU0cWtg.png" /></figure><p>The user_id the parameter is linked to one user per wearable (for example, WHOOP).</p><p><strong>Data Gathering: </strong>After authentication, you could typically request data from the REST API using the credentials retrieved (in OAuth2, this would be the Access Token). However, every company has its own access token for each user with different expiry times. Terra has abstracted this requirement away and allows you to simply request data using the user_id returned by the authentication process through Terra (regardless of the data provider company)</p><p>Now through Terra, you can request data from <a href="https://developer.whoop.com/docs/introduction">WHOOP&#39;s API endpoints</a> using the user_id. If you are interested in the user&#39;s workout data, you can use the following endpoint: https://api.tryterra.co/activity</p><p>The request could be made as such:</p><pre>curl --location --request GET &#39;https://api.tryterra.co/activity?user_id=USER_ID&amp;start_date=2022-10-01&amp;end_date=2022-10-30&#39; \<br>--header &#39;dev-id: DEV-ID&#39;<br>--header &#39;x-api-key: X-API-KEY&#39;</pre><p>This method is usually useful if you wish to retrieve historical data. If you wish to continuously receive data on update, you can open a webhook endpoint to accept Terra’s webhook events. This will reduce the load on your servers to continuously make HTTP requests as well as making sure you get the most updated events from WHOOP (or any other integrations).</p><p><strong>Data Processing</strong>: finally, after gathering the data, you will need to process it. Every REST API sends data differently; thus, you must write a parser for every datatype and wearable. Terra has again abstracted this away and only sends data in one format regardless of the data provider.</p><p>The request above returns JSON format data for the specific user_id WHOOP activity. For another company, for example, FITBIT, the only difference in this payload would be that the provider field will be FITBIT .</p><pre>{<br>  &quot;status&quot;: &quot;success&quot;,<br>  &quot;data&quot;: [<br>      &quot;metadata&quot;: {<br>        &quot;state&quot;: null,<br>        &quot;upload_type&quot;: 0,<br>        &quot;start_time&quot;: &quot;2022-11-18T08:58:21.958766+00:00&quot;,<br>        &quot;type&quot;: 18,<br>        &quot;name&quot;: &quot;Cross Country Skiing&quot;,<br>        &quot;summary_id&quot;: &quot;229630376069&quot;,<br>        &quot;city&quot;: null,<br>        &quot;country&quot;: null,<br>        &quot;end_time&quot;: &quot;2022-11-18T09:47:21.958766+00:00&quot;<br>      },<br>      &quot;strain_data&quot;: {<br>        &quot;strain_level&quot;: 6.149371915562675<br>      },<br>      &quot;heart_rate_data&quot;: {<br>        &quot;summary&quot;: {<br>          &quot;min_hr_bpm&quot;: null,<br>          &quot;hr_zone_data&quot;: [<br>            {<br>              &quot;start_percentage&quot;: 0,<br>              &quot;duration_seconds&quot;: 390,<br>              &quot;name&quot;: &quot;Resting&quot;,<br>              &quot;zone&quot;: 0,<br>              &quot;end_percentage&quot;: 50<br>            },<br>            {<br>              &quot;start_percentage&quot;: 50,<br>              &quot;duration_seconds&quot;: 504,<br>              &quot;name&quot;: &quot;Very light&quot;,<br>              &quot;zone&quot;: 1,<br>              &quot;end_percentage&quot;: 60<br>            },<br>            ...<br>          ],<br>          &quot;avg_hr_bpm&quot;: 118.42194006578433,<br>          &quot;max_hr_bpm&quot;: 158.16932189285052,<br>          &quot;avg_hrv_rmssd&quot;: null,<br>          &quot;resting_hr_bpm&quot;: null,<br>          &quot;avg_hrv_sdnn&quot;: null,<br>          &quot;user_max_hr_bpm&quot;: null<br>        },<br>        &quot;detailed&quot;: {<br>          &quot;hr_samples&quot;: [],<br>          &quot;hrv_samples_sdnn&quot;: [],<br>          &quot;hrv_samples_rmssd&quot;: []<br>        }<br>      },<br>      &quot;active_durations_data&quot;: {<br>        &quot;activity_seconds&quot;: null,<br>        &quot;inactivity_seconds&quot;: 2643.4844720203464,<br>        &quot;rest_seconds&quot;: null,<br>        &quot;moderate_intensity_seconds&quot;: 2101.2303060321888,<br>        &quot;activity_levels_samples&quot;: [],<br>        &quot;vigorous_intensity_seconds&quot;: 2342.994113043535,<br>        &quot;low_intensity_seconds&quot;: 549.4035406958508,<br>        &quot;num_continuous_inactive_periods&quot;: null<br>      },<br>      ...<br>    }<br>  ],<br>  &quot;user&quot;: {<br>    &quot;provider&quot;: &quot;WHOOP&quot;,<br>    &quot;last_webhook_update&quot;: null,<br>    &quot;user_id&quot;: &quot;013a6120-ea0f-4973-ad3b-4ac11112617e&quot;,<br>    &quot;scopes&quot;: null<br>  },<br>  &quot;type&quot;: &quot;activity&quot;<br>}</pre><p>Using this data, you can take anything from WHOOP&#39;s API (and any other fitness companies&#39; data) and display or manipulate it for special features in your app.</p><blockquote>Continue On</blockquote><p>This is a game changer from WHOOP&#39;s side, allowing developers to access data through their REST API. As the fitness and health sector continuously grows globally, more companies are looking to develop with fitness data. This allows them to add one more integration (rather than a big one) to their platform.</p><p>If you are integrated with <a href="https://dashboard.tryterra.co/">Terra</a> already, your infrastructure just got another integration overnight!</p><p>In our Integration series on WHOOP, we are discussing the data available from our API when fetching data from WHOOP.</p><p>As a reminder, the WHOOP <a href="https://blog.tryterra.co/search?q=whoop+integration+series">series</a> contains:</p><ul><li><a href="https://blog.tryterra.co/whoop-integration-series-part-1-getting-started-with-rest-apis-707d15dc6b8a">Part 1</a>: Getting started with Rest APIs</li><li><a href="https://blog.tryterra.co/whoop-integration-series-part-2-data-available-from-the-api-ec4337a9455b">Part 2</a>: Data available from the API</li><li><a href="https://blog.tryterra.co/whoop-integration-series-part-3-integrating-with-terra-api-19d8fc36b8c3">Part 3:</a> Integrating with Terra API</li><li><a href="https://blog.tryterra.co/whoop-integration-series-part-4-data-from-terra-api-253b217a162">Part 4</a>: Data from TERRA API</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=707d15dc6b8a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terraapi/whoop-integration-series-part-1-getting-started-with-rest-apis-707d15dc6b8a">WHOOP Integration series Part 1: Getting started with Rest APIs</a> was originally published in <a href="https://medium.com/terraapi">Terra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Webhooks vs HTTP]]></title>
            <link>https://medium.com/terraapi/webhooks-vs-http-1563452ca0a9?source=rss-2cde8f8f2035------2</link>
            <guid isPermaLink="false">https://medium.com/p/1563452ca0a9</guid>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[fitness-api]]></category>
            <category><![CDATA[terra]]></category>
            <category><![CDATA[webhooks]]></category>
            <dc:creator><![CDATA[Elliott]]></dc:creator>
            <pubDate>Tue, 15 Nov 2022 15:39:14 GMT</pubDate>
            <atom:updated>2022-11-15T15:39:14.167Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F4IU-pSJO1Y_48fnbpJ6_g.png" /></figure><p>HTTP (HyperText Transfer Protocol) has become a widely used standard protocol for communications between a server and a client.</p><p>Want to check your email? You (client) navigating to the email site will prompt an HTTP request to the server and return the emails you have in your inbox.</p><p>Want to buy new protein bars? You searching for ‘protein bars’ online will also prompt an HTTP request to the server and return your back results for ‘protein bars’. This happens basically everywhere on the web. However, have you ever thought about the magic that happens when you pay using a third-party website (perhaps Stripe), and you receive an email from the company that sells your protein bars with your invoice right after payment? That’s most likely due to a webhook event.</p><blockquote>Webhook Event and HTTP Requests</blockquote><p>HTTP requests are fun and all. However, how can you expect real-time event updates like the email of your purchase invoice with a simple server query? One way would be to constantly make requests to see if the update is available or not. Another (better way) is by utilizing webhooks.</p><p><a href="https://medium.com/terraapi/how-tos-webhooks-5ac374e48640">Webhooks</a> are nothing but simply an open endpoint on a server that accepts HTTP requests. Upon receiving this request, the server acts on it. For example, you pushing that purchase button on the portal creates an event that tells the original seller about your payment. This event is communicated to the original seller in the form of an HTTP request. The original seller would have an open endpoint (webhook) that will accept this request and send you an email with the invoice for your purchase.</p><p>In a way, you could then say all webhook events are HTTP requests but not all HTTP requests are webhook events.</p><blockquote>Why use Webhooks?</blockquote><p>The question then remains, why do we not just keep asking the server if the payment is complete or not? Theoretically, nothing is “wrong” with constantly asking (keep making HTTP requests) if the payment is done or not (this is called polling). However, this method of requests is incredibly wasteful in terms of resources and quite often undesired.</p><p>It is almost like instead of waiting for your waiter/waitress to bring you your food at a restaurant, you go up to the waiter/waitress and constantly ask if the food is done or not. What if you ordered a 7-course meal? You would have to constantly ask about 7 different items. It is a tad bit overkill. Why not just sit down and wait for your food?</p><blockquote>Be resourceful</blockquote><p>In the end, the decision to either use simple HTTP requests, webhooks, or other communication methods in your server comes down to you. Making use of different methods for different use cases can help you keep your service fast and efficient.</p><p>If you are expecting data but do not know when it will become available, try to use a webhook implementation. If you want to know something right away to display to your customers, make an HTTP request to the server.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1563452ca0a9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/terraapi/webhooks-vs-http-1563452ca0a9">Webhooks vs HTTP</a> was originally published in <a href="https://medium.com/terraapi">Terra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>