Ubidots Community

[SOLVED] Retrieving data in CSV

Hi there!

Can I retrieve data from my variables in text or a file format like CSV. Thanks for your help and great job!

Yes, you can get it in two different ways:

1. Through our portal:
In the view of a variable, click on “Export to CSV”; you’ll get a CSV file with the last values of the variable:

2. Through our API

Just add the URL parameter ?format=csv when making a GET request for data. This will switch from a JSON response to a CSV response.

For example, let’s retrieve the last values of the variable “51f87c14f91b281ecfea6c8a”:

JSON format:

GET things.ubidots.com/api/v1.6/variables/51f87c14f91b281ecfea6c8a/values/?token=JmY7dCjdDx2nLAFYAvi3h1cUNyvV

CSV format:

GET things.ubidots.com/api/v1.6/variables/51f87c14f91b281ecfea6c8a/values/?token=JmY7dCjdDx2nLAFYAvi3h1cUNyvV&format=csv


All the API endpoints return by default just 30 items. The page_size parameter can help you specify how many items to retrieve:

GET http://things.ubidots.com/api/v1.6/variables/53e262127625421973e7cdb5/values?token=33LqbmTXCqbxTMjW1fz5qKDJ93t98b&page_size=2000&format=csv

Other parameters you might want to check are the start and end parameters, so you can set the time-frame for which you’d like to get your data. For the full API endpoint documentation please visit: http://ubidots.com/docs/api/v1_6/data/get_variables_id_values.html

How about get csv with python?

You can use the requests python library and the API endpoint url:



Hi @yoelblack,

An example with the library requests

import requests
import csv

req = requests.get('http://things.ubidots.com/api/v1.6/variables/VARIABLE_ID/values?token=YOUR_TOKEN&page_size=2000&format=csv')

content_utf = req.content.decode('utf-8')
csv_reader = csv.reader(content_utf.splitlines(), delimiter=',')
with open('file.csv', 'wb') as csvFile:
    mylist = list(csv_reader)
    csv_writer = csv.writer(csvFile, delimiter=',', quoting=csv.QUOTE_MINIMAL)
    for row in mylist:

kath :slight_smile:

I will try

1 Like

Is it possible to download CSV without a token?

Or alternately, is it possible to create a “read-only” token (that can be used to retrieve/view data, but not upload/modify data?)



Dear Jeff, it is possible to create tokens for a group of devices, with read and/or write permissions. This is available in our business license. If you’re a business customer feel free to drop us a note in our support channel.

Here’s more info about this feature.