1

I have been trying to use the Zendesk API through Rstudio for a while now and I can't get the data into a usable format or find a logical way to use the data as it is.

I have used many ways to get the data however the one that I have had the most luck with is this query:

zendesk <- httr::GET("https://xxx.zendesk.com/api/v2/users.json", authenticate(username, password))
status_code(zendesk)
zendesk
users <- content(zendesk, "parsed")
users

And when I run users i get the data in the following output:

$users[[100]]
$users[[100]]$id
[1] 51666*****

$users[[100]]$url
[1] "https://xxx.zendesk.com/api/v2/users/51666*****.json"

$users[[100]]$name
[1] "xxxx, xxxx"

$users[[100]]$email
[1] "xxx@xxx.com"

$users[[100]]$created_at
[1] "2016-09-22T12:19:01Z"

$users[[100]]$updated_at
[1] "2017-11-27T16:08:17Z"

$users[[100]]$time_zone
[1] "London"

$users[[100]]$iana_time_zone
[1] "Europe/London"

$users[[100]]$phone
NULL

$users[[100]]$shared_phone_number
NULL

$users[[100]]$photo
NULL

$users[[100]]$locale_id
[1] 1xxxx

$users[[100]]$locale
[1] "en-gb"

$users[[100]]$organization_id
[1] 223xxxxxxx

$users[[100]]$role
[1] "end-user"

$users[[100]]$verified
[1] FALSE

$users[[100]]$external_id
NULL

$users[[100]]$tags
list()

$users[[100]]$alias
NULL

$users[[100]]$active
[1] TRUE

$users[[100]]$shared
[1] FALSE

$users[[100]]$shared_agent
[1] FALSE

$users[[100]]$last_login_at
NULL

$users[[100]]$two_factor_auth_enabled
[1] FALSE

$users[[100]]$signature
NULL

$users[[100]]$details
NULL

$users[[100]]$notes
NULL

$users[[100]]$role_type
NULL

$users[[100]]$custom_role_id
NULL

$users[[100]]$moderator
[1] FALSE

$users[[100]]$ticket_restriction
[1] "requested"

$users[[100]]$only_private_comments
[1] FALSE

$users[[100]]$restricted_agent
[1] TRUE

$users[[100]]$suspended
[1] FALSE

$users[[100]]$chat_only
[1] FALSE

$users[[100]]$default_group_id
NULL

$users[[100]]$report_csv
[1] FALSE

$users[[100]]$user_fields
$users[[100]]$user_fields$department
NULL

$users[[100]]$user_fields$description
NULL

This is only one result thats outputted, each user is displayed in this list format. Is there any way that I can get this into a data table?

Ideally I would like the data to be 'inverted' from the list above and shown as follows :

ID    URL    NAME    EMAIL    CREATED AT
A     XXX    XXX     XXX      XXX
B     XXX    XXX     XXX      XXX
C     XXX    XXX     XXX      XXX

This is the output when I run zendesk:

Response [https://xxx.zendesk.com/api/v2/users.json]
  Date: 2019-02-26 10:46
  Status: 200
  Content-Type: application/json; charset=UTF-8
  Size: 92.9 kB

Its driving me crazy, ive used Extracting data from an API using R and Extracting data from an API using R to try and help but I cant work it out.

Hope someone can help.

Thanks

Mattidge
  • 83
  • 8
  • can you provide a sample json file (dummy)? I useally go with the following in order to read in individual jsons into data.table: library(ndjson); stream_in(path = listJSON[i], cls = "dt") – Patrik_P Feb 26 '19 at 11:17
  • 1
    Thanks @Patrik_P im pulling this in through the api so I'm unsure what you mean by the dummy file? I added the code and altered it to my code to what I think is correct but it doesnt work. What does the [i] reference? Sorry I am very new to all this! – Mattidge Feb 26 '19 at 11:24
  • Ok. In order to get help, u got to provide the community with minimal reproducible example. Your problem is not very well defined, it lacks clarity. Try readiing the following https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example and restate your problem, – Patrik_P Feb 26 '19 at 11:27
  • @Patrik_P I have updated the question and hope this helps? I believe the dummy json file to be the list format I had in the originally – Mattidge Feb 26 '19 at 11:46
  • the code line `zendesk <- httr::GET("https://xxx.zendesk.com/api/v2/users.json", authenticate(username, password))` is not reproducible. You should privde the value of `zendesk`, f.i.. by creating an artificial example how it looks like. – Patrik_P Feb 26 '19 at 11:48
  • @Patrik_P I have updated what zendesk outputs for me – Mattidge Feb 26 '19 at 11:51
  • Im out, not clear to me, sorry. Hope someone else can help. – Patrik_P Feb 26 '19 at 13:06
  • Have you tried using this library? https://github.com/tcash21/zendeskR – Jimmy Long Mar 07 '19 at 15:44
  • unfortunately the library doesn't work anymore @JimmyLong – Mattidge Apr 03 '19 at 13:43

0 Answers0