# ◾ Data API - How-to Guide

# **🔍 Accessing Data from LearningSpace with the Data API**

## **What is Data API, and Why Would I Use It?**

The Data API enables you to **extract data directly from LearningSpace**, making it easier to generate **custom reports**, conduct **research**, or integrate your data into other tools. If you’ve ever wished for a way to “just export all the data,” this is it.

That said, using the API requires  some technical expertise. You won’t need to write code, but you’ll use tools and follow a few structured steps to set things up. A tech-savvy colleague will make light work of it.


---

## **Quick Start for Tech-Savvy Users 🧠**


1. **Install an API client** (e.g., [Insomnia](https://insomnia.rest/ "https://insomnia.rest/") or [Postman](https://www.postman.com/ "https://www.postman.com/")).
2. **Generate an API Key** in LearningSpace: Go to [**System**](/doc/system-manager-ar9EDnlVcL) **>** [**Security**](/doc/security-l3JLjVGibe) **>** [**Generate API Key**](/doc/how-to-generate-a-data-api-key-XUjU14AyLi).   
   Enable the **Data API Access** toggle.
3. **Run a script to get a token**:

   ```javascript
   echo "Getting token for an LS instance..."
   LS_HOST="[https://your-ls-instance.edu]"
   CLIENT_SECRET="[your-api-key]"
   API_TOKEN=$(curl "$LS_HOST/w/api/v2/auth.cgi" \
     -H "Content-Type: application/json" \
     -X POST --data '{"command":"token-for-apikey", "apiKeySecret":"'$CLIENT_SECRET'"}' | jq -r '.accessToken')
   bytes=$(echo $API_TOKEN | wc -c)
   echo "  received bytes: $bytes"
   echo "This is your API token: \n" 
   echo $API_TOKEN
   echo "\n" 
   ```
4. **Use Bearer token authentication** in Insomnia/Postman and send requests to `/api/data/v1/...`.  
   👉 [[Data API Endpoint Reference]](https://kb.learningspace.elevatehealth.net/s/ent-hs/doc/apis-in-learningspace-C5WvDxyymU#h-content-provided-by-the-data-api)
5. Use query parameters like `offset` and `limit` for pagination.


---

## **Step-by-Step Guide for Non-Tech-Savvy Users 👩‍🏫👨🏻‍🏫**

We’ll walk through how to extract a **list of Cases** from your system.

### **Step 1. Download an API Tool**

Install **Insomnia** (a free app to test APIs):  
 👉 [Download Insomnia](https://insomnia.rest/ "https://insomnia.rest/")

### **Step 2. Generate Your API Key**


1. Log in to LearningSpace.
2. Go to the [**System module**](/doc/system-manager-ar9EDnlVcL), and select the [**Security**](/doc/security-l3JLjVGibe) tab.
3. 
:::warning
   Click [**Generate API Key**](https://kb.learningspace.elevatehealth.net/doc/security-l3JLjVGibe#h-api-key).  
    🛑 **Important:** Copy the API key now. You won’t be able to see it again.

   :::

   ![](https://outline-production-attachments.s3-accelerate.amazonaws.com/uploads/03fa1014-cf0e-4191-ba80-50d24eef65d4/8a55ee80-27fd-4ddf-99b6-58608ff9a7a7/generate%20API_Security%20tab.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIA4EOUDTOVUICLPZ4P%2F20260909%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260909T120000Z&X-Amz-Expires=86400&X-Amz-Signature=c8c015ef077b6043fc9e6f53dcf0e1bc63d2e10d730940af02b629253cade4f2&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject " =380x655")

   

### **Step 3. Enable API Access**

Make sure:

* ✅ **Data API Access** is toggled ON.
* ☑️ (Optional) **All events are accessible via API by default** if checked.

### **Step 4. Get Your API Token**

Now we’ll convert your API key into a token that allows you to access the data.  

**==FOR MAC/OS USERS:==**

#### **Run a script manually**


1. Open **TextEdit** or any plain text editor.
2. Paste the following script:

   ```javascript
   echo "Getting token for an LS instance..."
   LS_HOST="[https://your-ls-instance.edu]"
   CLIENT_SECRET="[your-api-key]"
   API_TOKEN=$(curl "$LS_HOST/w/api/v2/auth.cgi" \
     -H "Content-Type: application/json" \
     -X POST --data '{"command":"token-for-apikey", "apiKeySecret":"'$CLIENT_SECRET'"}' | jq -r '.accessToken')
   bytes=$(echo $API_TOKEN | wc -c)
   echo "  received bytes: $bytes"
   echo "This is your API token: \n" 
   echo $API_TOKEN
   echo "\n" 
   ```
3. Replace:
   * `https://your-ls-instance.edu` with your LS web address
   * `your-api-key-here` with the API key from Step 2
4. Save it as `getToken.sh`
5. Open **Terminal**, navigate to the file, and run:

   ```javascript
   sh getToken.sh
   ```
6. You’ll see your **API token** (a long string). Copy and save it somewhere safe.


---

**==FOR WINDOWS USERS:==**

### **🪄** `**getToken.bat**` **– Windows Script**


1. Open **Notepad** or any plain text editor.
2. Paste the following and save the file named as `getToken.bat`, then double-click or run from Command Prompt:

```javascript
@echo off
set /p LS_HOST=Enter your LS host URL (e.g. https://your-ls-instance.edu): 
set /p API_KEY=Enter your API key: 
echo.
echo Getting token for LearningSpace...
curl -s -X POST "%LS_HOST%/w/api/v2/auth.cgi" ^
  -H "Content-Type: application/json" ^
  -d "{\"command\":\"token-for-apikey\", \"apiKeySecret\":\"%API_KEY%\"}" ^
  > token.json
echo Done! Your token has been saved to token.json
echo.
type token.json
pause
```


3. Your **API token** (a long string) will be saved in a token.json file.   
   The file will look like this:

```javascript
{"accessToken":"....token [long string of secure access token characters]...."}
```


4. You need to copy the token part (a long string of secure access token characters) and save it in a secure location.


---

### **Step 5. Open Insomnia**

You should see a blank screen.

### **Step 6. Create a New Request**

* Click the ➕ icon or use **CTRL+N / CMD+N**
* Choose **HTTP Request**  

  ![](https://outline-production-attachments.s3-accelerate.amazonaws.com/uploads/03fa1014-cf0e-4191-ba80-50d24eef65d4/ee1d52f7-2364-49ae-84b3-c04c9370551a/new-request.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIA4EOUDTOVUICLPZ4P%2F20260909%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260909T120000Z&X-Amz-Expires=86400&X-Amz-Signature=def3881d4c7ac2cc8dfe2803b5396b3c4c98c5bbbaa25e51cb449c237fa586d5&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject " =494x380")

  

### **Step 7. Add the API URL**

For a list of Cases, paste this into the URL field:

```javascript
https://your-ls-instance.edu/api/data/v1/cases
```

🧭 Tip: You can find more endpoints here 👉 [[Data API Endpoint Reference]](https://kb.learningspace.elevatehealth.net/s/ent-hs/doc/apis-in-learningspace-C5WvDxyymU#h-content-provided-by-the-data-api)

 ![](https://outline-production-attachments.s3-accelerate.amazonaws.com/uploads/03fa1014-cf0e-4191-ba80-50d24eef65d4/d2b2884b-ca9b-4532-b014-eb983ff9e09e/Screenshot%202025-05-27%20at%208.46.20.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIA4EOUDTOVUICLPZ4P%2F20260909%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260909T120000Z&X-Amz-Expires=86400&X-Amz-Signature=3802fa725682816b378fb6e1df6df455b3f0f552d3a8fce2cad9daabf8098542&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject " =428x415")


### **Step 8. Set Authentication**


1. Click the **Auth** tab
2. Choose **Bearer Token**
3. Paste your **API token** in the field

   ![](https://outline-production-attachments.s3-accelerate.amazonaws.com/uploads/03fa1014-cf0e-4191-ba80-50d24eef65d4/6d9e6ee2-7444-4141-b57d-15fd1d4817e8/Screenshot%202025-05-27%20at%208.45.27.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIA4EOUDTOVUICLPZ4P%2F20260909%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260909T120000Z&X-Amz-Expires=86400&X-Amz-Signature=f20cf157bd2879492d7dc652530b97f570c679e8d50492519cbb3a2e21d39f61&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject " =380x426")

   
   
   ![](https://outline-production-attachments.s3-accelerate.amazonaws.com/uploads/03fa1014-cf0e-4191-ba80-50d24eef65d4/7670e123-0fb1-41d4-a738-c46b0b22f9a8/Screenshot%202025-05-27%20at%208.46.27.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIA4EOUDTOVUICLPZ4P%2F20260909%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260909T120000Z&X-Amz-Expires=86400&X-Amz-Signature=fa6faa74a5aa22bc202abded6fbb578e884215c2ccc29a72b632a650e8f14511&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject " =380x402")

   

### **Step 9. Send the Request**

Click **Send**. The right panel will show your results.

🎉 Success! You’ve just pulled live data from your system.

 ![](https://outline-production-attachments.s3-accelerate.amazonaws.com/uploads/03fa1014-cf0e-4191-ba80-50d24eef65d4/5f4c149b-c452-48bf-9668-337e6c8fd90c/success.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIA4EOUDTOVUICLPZ4P%2F20260909%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260909T120000Z&X-Amz-Expires=86400&X-Amz-Signature=80e725c31f94535eefaa02bb1f4a508e1477228de0312b9913d38a89b3c350fb&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject " =494x489")


---

### **Bonus: Understand Your Result**

In the result, you’ll see:

* `total`: Total number of items
* `limit`: How many results per request (default is 100)
* `offset`: Where the results start (default is 0)

To get more results, increase the `offset`.  
 👉 For example, add `?offset=100` to the URL to get items 101–200.


---

### **Common Errors & How to Fix Them**

| ❌ Error | ✅ Fix |
|---------|-------|
| `Couldn’t resolve host` | Check if your LS address is correct or if you’re on VPN |
| `{"success":false,"message":"Not found"}` | Check for typos in the endpoint. Include `/api/` in the URL. |
| `401 Authorization required` | Make sure you're using the **token**, not the API key, in the Bearer Auth section. |
| `Timeout issue` | Adjust the *Request Timeout* setting in **Insomnia** to ensure the request has sufficient time to be processed. E.g., increase the request timeout limit from 30 to 90 seconds (or even more).  |



:::tip
For information on APIs in LearningSpace, please refer [to this link](https://kb.learningspace.elevatehealth.net/s/ent-hs/doc/apis-in-learningspace-C5WvDxyymU).

:::


:::success
[**Data API - New LearningSpace Reporting API Expansion**](https://kb.learningspace.elevatehealth.net/s/01d3ed73-9ca1-4e34-a37d-1beff735f8fb)

[APIs in LearningSpace](/doc/8b3dc0ee-b9dc-45b8-8399-54c4e2d42882) 

:::

---

**Documents**

- [User Guide](https://kb.learningspace.elevatehealth.net/s/ent-hs/doc/user-guide-WPv4VxhtWB)
- [FAQ](https://kb.learningspace.elevatehealth.net/s/ent-hs/doc/faq-YoxOQOjvnY)
- [Training Videos](https://kb.learningspace.elevatehealth.net/s/ent-hs/doc/training-videos-D2ycsEwqPt)
- [Module Introduction Videos](https://kb.learningspace.elevatehealth.net/s/ent-hs/doc/module-introduction-videos-I6OQ6H7SUT)
- [Release Notes](https://kb.learningspace.elevatehealth.net/s/ent-hs/doc/release-notes-BcFFMsc0RV)
- [Distance Learning with LearningSpace](https://kb.learningspace.elevatehealth.net/s/ent-hs/doc/distance-learning-with-learningspace-eAfwW23Hxg)
- [Preventing Copy-Paste in LearningSpace](https://kb.learningspace.elevatehealth.net/s/ent-hs/doc/preventing-copy-paste-in-learningspace-sPD0IIUuk0)
- [Important Technical Notification Regarding Adobe Flash Player](https://kb.learningspace.elevatehealth.net/s/ent-hs/doc/important-technical-notification-regarding-adobe-flash-player-eQtMLwLmTJ)
- [iPad support - Technical information](https://kb.learningspace.elevatehealth.net/s/ent-hs/doc/ipad-support-technical-information-dLmeFvKofC)
- [TeamViewer Link](https://kb.learningspace.elevatehealth.net/s/ent-hs/doc/teamviewer-link-QyKZBMqUT9)
- [YouTube videos about LearningSpace](https://kb.learningspace.elevatehealth.net/s/ent-hs/doc/youtube-videos-about-learningspace-TMb3zdc0LC)
- [Customer Aftercare One-Pager](https://kb.learningspace.elevatehealth.net/s/ent-hs/doc/customer-aftercare-one-pager-GBWMe1BcfS)
- [Case Studies](https://kb.learningspace.elevatehealth.net/s/ent-hs/doc/case-studies-VcAbFqXSz7)