0

How is it possible to get token for the Sabre API in R similar to this post here for python: How do I perform oauth2 for Sabre Dev Network using python?

As far as I understand I need to use OAuth2 verification process. For R I found the httr package with this function oauth2.0_token here but I'm not able to put in the right parameters in order to get a token.

My code so far:

library(base64enc)
library(base64)

clientID <- "V1:userid:group:domain" #Example clientID
clientIDRaw <- charToRaw(clientID)
clientIDEnc <- base64encode(clientIDRaw)

password <- "12345" #Example password
passwordRaw <- charToRaw(password)
passwordEnc<- base64encode(passwordRaw)

combined <- paste(clientIDEnc, ":", passwordEnc, sep="")
combinedRaw <- charToRaw(combined)
combinedEnc <- base64encode(combinedRaw)

With the combinedEnc variable I should be able to retrieve my token?

InDubio
  • 67
  • 1
  • 9
  • What are you using as domain (should be "AA")? Do you already have a PCC registred with Sabre? Does your token work with postman? – Thomas May 09 '18 at 15:33
  • Yes i am already registered, this is just the example from their page. i don't know how to retrieve the token, that is exactly the problem (as described in the last sentence) – InDubio May 17 '18 at 07:53

2 Answers2

0

I don't know R, so I don't know what convertToRaw does exactly, but I tested the code below in the following link, and it worked: https://www.rdocumentation.org/packages/caTools/versions/1.17.1/topics/base64encode%20%26%20base64decode

user = "V1:userid:group:domain"
print(user)

userEnc = base64encode(user)
print(userEnc)

password = "password"
print(password)

passwordEnc = base64encode(password)
print(passwordEnc)

credentials = paste(userEnc, passwordEnc, sep=":")
print(credentials)

credentialsEnc = base64encode(credentials)
print(credentialsEnc)

If this is steps are working as expected, then focus on the comment from Thomas (specifically the test in Postman), or add the actual error you are getting.

Giancarlo
  • 1,446
  • 8
  • 17
  • What exactly should this help? My code gives the encoded credentials already. The question is how to retrieve the token from it. – InDubio May 17 '18 at 07:54
  • You said " I'm not able to put in the right parameters in order to get a token". The parameters are written in the documentation, so this is where it could fail. Are you getting a response? – Giancarlo May 23 '18 at 14:05
0

This is the request you are looking for as per your clarification in the comments

 curl -X POST \
  https://api.sabre.com/v2/auth/token \
  -H 'Accept: */*' \
  -H 'Authorization: Basic 
Your combinedEnc' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Postman-Token: XXX-edcb-4b2a-aa3d-XXXX' \
  -d grant_type=client_credentials
Thomas
  • 405
  • 4
  • 7