Code Monkey home page Code Monkey logo

rtypeform's Introduction

API to typeform data sets

Build Status Downloads CRAN_Status_Badge codecov.io

Typeform is a company that specializes in online form building. This R package allows users to download their form results through the exposed API (V2).

** The rtypeform package now uses V2. This is a breaking change from the previous version.**

Installation

The package can be installed from CRAN

install.packages("rtypeform")

and loaded in the usual way.

library("rtypeform")

Using this package

This package can be used with either a typeform personal access token or by setting up an application and creating an OAuth access token.

A personal access token gives you full access to all of the typeform API for your typeforms and results. Note anyone with your personal access token can retrieve, update and delete your typeforms and data. To access your typeform data with a personal access token see the Personal Access Token section below.

When creating an application with an OAuth access token, explicit permission for different functionality (scopes) must be granted. See the section below on OAuth access.

If you have previously used the version 1 API this is now entirely removed. You will need to generate new tokens.

Personal Access Token

To use this package with a personal access token you need to first obtain one. It is fairly easy to obtain one. See typeform’s help page. The token will look something like

943af478d3ff3d4d760020c11af102b79c440513

OAuth Access

When you create an application that authenticates using OAuth you will use scopes to define the extent of access to a users data. This way your app can request a users permission to undertake actions on that users behalf.

This link will get you started with registering a new application on your account.

Once you have your client id and client secret you can use the rtypeform package to set these as options.

rtypeform_set_client_id(my_client_id)
rtypeform_set_client_secret(my_client_secret)

As with the personal access token. Anyone with these details can impersonate you to obtain, update and remove data, they should always be kept safe.

Having set the client id and secret, before we can obtain an access token we also need to define the scope of our application. rtypeform_set_scope takes as argument a character vector of allowed access scopes. For more information see the scopes section below.

rtypeform_set_scope("forms:read")

We can then generate a new token with

api = make_new_token()

This will open a web browser prompting the user to give permission. The token can be cached in a local .httr-oauth file between sessions.

Scopes

You define the scope at the time that the access token is generated. To discover what each scope allows access to, see here.

Using the package

Once you have this key, (either personal access token, or an oauth token created by make_new_token()) we can extract data from typeform

api = "XXXXX"
# Was get_typeforms() in V1 of the package
forms = get_forms(api)

The forms object is also contains attributes containing the total number of forms.

attr(forms, "total_items")
#> [1] 135

If you don’t pass your api token as an argument, it will attempt to read the variable typeform_api2 from your .Renviron file, via Sys.getenv("typeform_api2"). If this variable is set correctly, then you can omit the api argument

# See ?get_forms for further details
forms = get_forms()

To set the access token for the current session you can use

rtypeform_set_token(api)

set (see Efficient R programming Chapter 2 for more details).

You can download data from a particular typeform via

# Most recent typeform
form_id = forms$form_id[1]
q = get_responses(form_id, completed = TRUE)

The object q is a list. The first element is meta that contain details on the user, such as, their platform and user_agent. The other list elements are responses to each question.

There are a number of options for downloading the data. For example

q = get_responses(form_id, completed = TRUE, page_size = 100)

See the ?get_responses() help page for other options.

Looking at the responses

Since the responses is list, we get to perform lots of map operations. I find using purrr and the tidyverse make this a bit easier. To see the question types we can use string a few map() commands together

library("tidyverse")
question_types = q[-1] %>% # Remove the meta
   map(~select(.x, type)) %>%
   map_df(~slice(.x, 1)) %>%
   pull()

Example: Multiple Filters / Order

Imagine we only want:

  • completed results, so we add the parameter completed = TRUE.
  • a maximum of 5 results, so we add the parameter page_size = 5.
  • results since 2018-01-01 11:00:00.
since = "2018-01-01 11:00:00"
# convert to date-time 
since = lubridate::ymd_hms(since)
q = get_responses(form_id, completed = TRUE, 
                  page_size = 5, since = since)

Other information

  • If you have any suggestions or find bugs, please use the github issue tracker.
  • Feel free to submit pull requests.

Development of this package was supported by Jumping Rivers

rtypeform's People

Contributors

csgillespie avatar ignasa avatar jamierowen avatar johnmcintyrejr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rtypeform's Issues

Themes

  • Create theme
  • Retrieve themes
  • Retrieve theme
  • Update theme
  • Delete theme

From #13

Via SO thread

I think I'd consider returning separate components for and 100% completed and less than 100% completed answers:

library(purrr)
library(dplyr)

res <- httr::GET("https://api.typeform.com/v1/form/JlCM2J",
           query=list(key="ecab3f590a2af4ca55468adc95686a043bbf6c9a"))

httr::content(res, as="text") %>%
  jsonlite::fromJSON(simplifyVector=FALSE) -> tmp

http_status <- tmp$http_status

stats <- tmp$stats

map_df(tmp$questions, flatten_df) -> questions

keep(tmp$responses, ~.$completed ==1) %>%
  map_df(flatten_df) -> completed

glimpse(completed)
## Observations: 1
## Variables: 35
## $ completed                          <chr> "1"
## $ token                              <chr> "b84567f64cedf2b0050eb0c209...
## $ browser                            <chr> "default"
## $ platform                           <chr> "other"
## $ date_land                          <chr> "2016-12-17 12:21:06"
## $ date_submit                        <chr> "2016-12-17 12:22:29"
## $ user_agent                         <chr> "Mozilla/5.0 (Windows NT 10...
## $ referer                            <chr> "https://gowtham11.typeform...
## $ network_id                         <chr> "fdebc44ea7"
## $ textfield_38991412                 <chr> "A"
## $ dropdown_38991418                  <chr> "Accounting"
## $ textarea_38991420                  <chr> "A"
## $ textfield_38991413                 <chr> "A"
## $ textarea_38991421                  <chr> "A"
## $ listimage_38991426_choice          <chr> "Company"
## $ textfield_38991414                 <chr> "A"
## $ website_38991435                   <chr> "http://A.com"
## $ textarea_38991422                  <chr> "A"
## $ listimage_38991427_choice          <chr> "Sincere"
## $ listimage_38991428_choice          <chr> "Male"
## $ list_38991436_choice               <chr> "17 or younger"
## $ list_38991437_choice               <chr> "Upper class"
## $ listimage_38991429_choice_49501105 <chr> "Store"
## $ listimage_38991430_choice          <chr> "Product"
## $ textarea_38991423                  <chr> "A"
## $ listimage_38991431_choice          <chr> "Techy"
## $ listimage_38991432_choice_49501124 <chr> "Fuchsia Rose"
## $ listimage_38991433_choice          <chr> "Classic"
## $ list_38991438_choice               <chr> "$3,000 or less"
## $ listimage_38991434_choice_49501140 <chr> "Brand Design"
## $ textarea_38991424                  <chr> "A"
## $ textfield_38991415                 <chr> "A"
## $ dropdown_38991419                  <chr> "Afghanistan"
## $ email_38991439                     <chr> "[email protected]"
## $ textarea_38991425                  <chr> "A"

keep(tmp$responses, ~.$completed ==0) %>%
  map_df(flatten_df) -> not_completed

glimpse(not_completed)
## Observations: 1
## Variables: 9
## $ completed   <chr> "0"
## $ token       <chr> "27181b2b95f69f0024f198194ec48561"
## $ browser     <chr> "default"
## $ platform    <chr> "other"
## $ date_land   <chr> "2016-12-16 04:01:40"
## $ date_submit <chr> "0000-00-00 00:00:00"
## $ user_agent  <chr> "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWe...
## $ referer     <chr> "https://gowtham11.typeform.com/to/JlCM2J"
## $ network_id  <chr> "8c7fd4d289"

You could return the 5 components as a list():

list(
  http_status=tmp$http_status,
  stats=tmp$stats,
  questions=tmp$questions,
  completed_responses=completed,
  uncompleted_responses=not_completed
)

and give it a class name which wld enable having a special print.class() method for it to show the summary data and the responses in a tad nicer format.

Not sure I'd spend more time on it unless you see lots of folks using typeform for their forms.

(Just realized I hadn't logged out of the work github acct to post this. Rest assured it's @hrbrmstr)

Does not return the questions

Hi,

The object returned with get_results returns only the identifiers of the question but not the question itself. Am I missing something and should I get these elsewhere?

Thanks,

Dan

Automatic type identification

parsed$responses$answers presently returns everything as character this could force someone who is actually working with the data to need to convert columns on an ad hoc basis. Recommend adding a method for automatic type conversion using utils::type.convert()

Images

  • Retrieve image by size
  • Retrieve background by size
  • Retrieve choice image by size
  • Create image
  • Retrieve images collection
  • Retrieve image
  • Delete image

Following #13

Workspaces

  • Retrieve workspaces
  • Create workspace
  • Retrieve workspace
  • Update workspace
  • Delete workspace

Error: All nested columns must have the same number of elements.

Hello everyone. I always used the package rtypeform for getting responses of my type forms to elaborate them in shiny dashboard.

This morning, when from the script I run the command
responses <- get_responses(form_id = form_id, api = api, page_size = 1000)
with my form_id and api, I get the error:
"Error: All nested columns must have the same number of elements."

I used before the version 2.0.0, when I got the error:
"Errore: lexical error: invalid char in json text.
<meta http-equ
(right here) ------^"
So I updated from this GitHub repository to version 2.0.0.9003

I'm using Open 3.5.1 in Mac OS X Catalina 10.15.4

Can anyone give me some guess what's going on here?
Thank you

Forms

  • Create form
  • Retrieve forms
  • Update form (patch)
  • Update form
  • Retrieve form
  • Delete form
  • Retrieve custom form messages
  • Update custom messages

Following #13

Webhooks

  • Retrieve webhook data
  • Create or update webhook
  • Delete webhook

From #13

Teams

  • Retrieve team
  • Update team

Following #13

Moving to the response API

Typeform has moved from the "old" Data API to the new Responses API. This lists the minimum coverage needed for a new release.

  • Create a branch - response
  • get_api() function
  • get_forms() function
  • get_quesion() function
  • All documentation passes CRAN checks
  • Basic unit tests
  • Update README
  • Create migration guide

Switch from Data API to Responses API

Hi @csgillespie!

Congratulations for the awesome work on this package! :)
I am Nicolas, and I just joined Typeform as a Developer Advocate, helping developers succeed using our APIs.

I have noted that your package uses the "old" Data API, instead of the new Responses API.
We should work together on a transition. Some steps are explained in our Migration Guide

And I will be delighted to help you out :)

I am very curious to hear more about use cases to use Typeform data in R.
Cheers

Error when using get_forms()

I keep getting this Error line when I use get_forms() command:

New names:

  • href -> href...6
  • href -> href...7
    Error: Can't rename columns that don't exist.
    x Column href doesn't exist.

Any ideal how to sort this problem?
thanks

question more than issue

ive been reading your information sheet from : https://cran.r-project.org/web/packages/rtypeform/rtypeform.pdf

i can see there is a section on Post Response which i find really interesting.
i have a need to migrate responses from one form to another (bulk, cant do manually).
Is this something this project can do? Currently typeform do not have an api that supports this, but it may be possible with a sequence or collection of post requests in a function

Cheers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.