Install packages httr and jsonlite
#install.packages("httr")
#install.packages("jsonlite")
Create a GET response to call the API
jobsearch <- httr::GET("https://www.reed.co.uk/api/1.0/search?keywords=analyst&location=london&distancefromlocation=15?details=true",
httr::authenticate(
user = "561a4932-c798-443c-a06f-3848f801efb3",
password = "",
type = "basic"))
# View API GET response result
str(jobsearch)
## List of 10
## $ url : chr "https://www.reed.co.uk/api/1.0/search?keywords=analyst&location=london&distancefromlocation=15?details=true"
## $ status_code: int 200
## $ headers :List of 22
## ..$ date : chr "Sun, 01 Oct 2023 17:56:25 GMT"
## ..$ content-type : chr "application/json; charset=utf-8"
## ..$ transfer-encoding : chr "chunked"
## ..$ connection : chr "keep-alive"
## ..$ cache-control : chr "no-cache"
## ..$ pragma : chr "no-cache"
## ..$ expires : chr "-1"
## ..$ set-cookie : chr ".ASPXANONYMOUS=ICpxKd3lk8dtauE5kRAINp4TakplqsmC25Oem6OvDR6n5xmGA8WI3YaCQ0uR7t4iEVy_7tznn8efIT3HMd__c3srEQAMg-rq"| __truncated__
## ..$ x-ua-compatible : chr "IE=Edge,chrome=1"
## ..$ access-control-allow-origin : chr "*"
## ..$ access-control-allow-headers: chr "Authorization"
## ..$ access-control-allow-methods: chr "POST, GET, OPTIONS, PUT, DELETE"
## ..$ x-content-type-options : chr "nosniff"
## ..$ strict-transport-security : chr "max-age=15768000; includeSubDomains"
## ..$ x-xss-protection : chr "1; mode=block"
## ..$ content-security-policy : chr "frame-src 'self' 'unsafe-eval' 'unsafe-inline' player.vimeo.com *.vimeo.com googletagmanager.com *.googletagman"| __truncated__
## ..$ cf-cache-status : chr "DYNAMIC"
## ..$ set-cookie : chr "__cf_bm=u9mZz3eD0drV2Aw65Tiijf1sot6CL_s1n_i3jFttq.o-1696182985-0-ASr36B6JAIssIFE9PIaYvoayDF5/9uEHargyitmnA0lgiR"| __truncated__
## ..$ set-cookie : chr "__cfruid=6b68c4acea74187a70678d818648c55d54f770a6-1696182985; path=/; domain=.reed.co.uk; HttpOnly; Secure; SameSite=None"
## ..$ server : chr "cloudflare"
## ..$ cf-ray : chr "80f6950cefc40a37-ARN"
## ..$ content-encoding : chr "gzip"
## ..- attr(*, "class")= chr [1:2] "insensitive" "list"
## $ all_headers:List of 1
## ..$ :List of 3
## .. ..$ status : int 200
## .. ..$ version: chr "HTTP/1.1"
## .. ..$ headers:List of 22
## .. .. ..$ date : chr "Sun, 01 Oct 2023 17:56:25 GMT"
## .. .. ..$ content-type : chr "application/json; charset=utf-8"
## .. .. ..$ transfer-encoding : chr "chunked"
## .. .. ..$ connection : chr "keep-alive"
## .. .. ..$ cache-control : chr "no-cache"
## .. .. ..$ pragma : chr "no-cache"
## .. .. ..$ expires : chr "-1"
## .. .. ..$ set-cookie : chr ".ASPXANONYMOUS=ICpxKd3lk8dtauE5kRAINp4TakplqsmC25Oem6OvDR6n5xmGA8WI3YaCQ0uR7t4iEVy_7tznn8efIT3HMd__c3srEQAMg-rq"| __truncated__
## .. .. ..$ x-ua-compatible : chr "IE=Edge,chrome=1"
## .. .. ..$ access-control-allow-origin : chr "*"
## .. .. ..$ access-control-allow-headers: chr "Authorization"
## .. .. ..$ access-control-allow-methods: chr "POST, GET, OPTIONS, PUT, DELETE"
## .. .. ..$ x-content-type-options : chr "nosniff"
## .. .. ..$ strict-transport-security : chr "max-age=15768000; includeSubDomains"
## .. .. ..$ x-xss-protection : chr "1; mode=block"
## .. .. ..$ content-security-policy : chr "frame-src 'self' 'unsafe-eval' 'unsafe-inline' player.vimeo.com *.vimeo.com googletagmanager.com *.googletagman"| __truncated__
## .. .. ..$ cf-cache-status : chr "DYNAMIC"
## .. .. ..$ set-cookie : chr "__cf_bm=u9mZz3eD0drV2Aw65Tiijf1sot6CL_s1n_i3jFttq.o-1696182985-0-ASr36B6JAIssIFE9PIaYvoayDF5/9uEHargyitmnA0lgiR"| __truncated__
## .. .. ..$ set-cookie : chr "__cfruid=6b68c4acea74187a70678d818648c55d54f770a6-1696182985; path=/; domain=.reed.co.uk; HttpOnly; Secure; SameSite=None"
## .. .. ..$ server : chr "cloudflare"
## .. .. ..$ cf-ray : chr "80f6950cefc40a37-ARN"
## .. .. ..$ content-encoding : chr "gzip"
## .. .. ..- attr(*, "class")= chr [1:2] "insensitive" "list"
## $ cookies :'data.frame': 3 obs. of 7 variables:
## ..$ domain : chr [1:3] "#HttpOnly_www.reed.co.uk" "#HttpOnly_.reed.co.uk" "#HttpOnly_.reed.co.uk"
## ..$ flag : logi [1:3] FALSE TRUE TRUE
## ..$ path : chr [1:3] "/" "/" "/"
## ..$ secure : logi [1:3] FALSE TRUE TRUE
## ..$ expiration: POSIXct[1:3], format: "2023-10-01 23:26:25" "2023-10-01 22:26:25" ...
## ..$ name : chr [1:3] ".ASPXANONYMOUS" "__cf_bm" "__cfruid"
## ..$ value : chr [1:3] "ICpxKd3lk8dtauE5kRAINp4TakplqsmC25Oem6OvDR6n5xmGA8WI3YaCQ0uR7t4iEVy_7tznn8efIT3HMd__c3srEQAMg-rqz-ZJDcr8zU60zA-"| __truncated__ "u9mZz3eD0drV2Aw65Tiijf1sot6CL_s1n_i3jFttq.o-1696182985-0-ASr36B6JAIssIFE9PIaYvoayDF5/9uEHargyitmnA0lgiRrQy2TkFE"| __truncated__ "6b68c4acea74187a70678d818648c55d54f770a6-1696182985"
## $ content : raw [1:85457] 7b 22 72 65 ...
## $ date : POSIXct[1:1], format: "2023-10-01 17:56:25"
## $ times : Named num [1:6] 0 0.112 0.204 0.346 0.608 ...
## ..- attr(*, "names")= chr [1:6] "redirect" "namelookup" "connect" "pretransfer" ...
## $ request :List of 7
## ..$ method : chr "GET"
## ..$ url : chr "https://www.reed.co.uk/api/1.0/search?keywords=analyst&location=london&distancefromlocation=15?details=true"
## ..$ headers : Named chr "application/json, text/xml, application/xml, */*"
## .. ..- attr(*, "names")= chr "Accept"
## ..$ fields : NULL
## ..$ options :List of 4
## .. ..$ useragent: chr "libcurl/7.84.0 r-curl/5.0.0 httr/1.4.5"
## .. ..$ httpauth : num 1
## .. ..$ userpwd : chr "561a4932-c798-443c-a06f-3848f801efb3:"
## .. ..$ httpget : logi TRUE
## ..$ auth_token: NULL
## ..$ output : list()
## .. ..- attr(*, "class")= chr [1:2] "write_memory" "write_function"
## ..- attr(*, "class")= chr "request"
## $ handle :Class 'curl_handle' <externalptr>
## - attr(*, "class")= chr "response"
# View the main source of the data needed from the API - Normally content
str(jobsearch$content)
## raw [1:85457] 7b 22 72 65 ...
Convert the raw content to text (in this case, a JSON string)
jobsearchcontent <- httr::content(jobsearch, as = "text")
# View JSON String result
str(jobsearchcontent)
## chr "{\"results\":[{\"jobId\":50742153,\"employerId\":1990,\"employerName\":\"Gregory Martin International\",\"emplo"| __truncated__
Convert the JSON string to a dataframe and view data in a table
jobsearchJSON <- jsonlite::fromJSON(jobsearchcontent)
View(jobsearchJSON$results)