2

I'm trying to get some appointment data from a practice management software. I have an API key but I have no experience in the area.

I have tried to convert Curl code with little success. The api documentation is here https://github.com/redguava/cliniko-api

I am trying to convert this curl code

curl https://api.cliniko.com/v1/appointments \
  -u API_KEY: \
  -H 'Accept: application/json' \
  -H 'User-Agent: APP_VENDOR_NAME (APP_VENDOR_EMAIL)'

What I've tried: (yes this is from a curl to r converter)

require(httr)

headers = c(
  `Accept` = 'application/json',
  `User-Agent` = 'APP_VENDOR_NAME (APP_VENDOR_EMAIL)'
)

res <- httr::GET(url = 'https://api.cliniko.com/v1/appointments', 
httr::add_headers(.headers=headers), 
httr::authenticate('API_KEY', 'INSERTED MY API KEY'))

Any ideas would be greatly appreciated

Tensibai
  • 15,557
  • 1
  • 37
  • 57

1 Answers1

2

httr::authenticate takes input username and password in the form httr::authenticate(username,password).

Curl's authenticate takes argument username and password joined by by a :, i.e. username:password.

In the example from the API documentation the curl command authenticates the username:password combination API_KEY:. Looking closely, we can see that after the : is blank. From this we can determine the username field should be 'API_KEY' and the password field should be ''.

So you should change your curl command to:

require(httr)

headers = c(
  `Accept` = 'application/json',
  `User-Agent` = 'APP_VENDOR_NAME (APP_VENDOR_EMAIL)'
)

res <- httr::GET(url = 'https://api.cliniko.com/v1/appointments', 
httr::add_headers(.headers=headers), 
httr::authenticate('API_KEY', ''))

Where API_KEY is your provided API key.

  • 1
    Or quoting from the doc linked int he question "You should provide the Cliniko API Key as the basic auth username. There is no need to provide a password." – Tensibai Aug 29 '19 at 07:58
  • Thank you very much you are 100% spot on. I managed to get it working :) – Pat Slattery Aug 29 '19 at 21:04