0

I am trying to call the sagepay reporting API using R but I am getting an error. I have essentially tried to combine this guide:sagepay reporting and admin api code examples in php with this one:how to send an XML request to an API with R

My code looks like the below:

#digest
library(digest)

#RCurl
library(RCurl)

#credentials
vendor<-"vendor"
user<-"user"
pass<-"password"

#hashing password
signature<-digest(paste0("<password>",pass,"</password>"),algo="md5")

#building request
req<-paste0("<vspaccess>
<command>getTransactionList</command>
<vendor>",vendor,"</vendor>
<user>",user,"</user>
<startdate>01/10/2018 00:00:01</startdate>
<enddate>01/02/2018 00:00:01</enddate>
<txtypes><txtype>PAYMENT</txtype></txtypes>
<result>failure</result>
<signature>",signature,"</signature>
</vspaccess>")

myheader<-c(Connection="close", 
           'Content-Type'="application/xml",
           'Content-length'=nchar(req))

data<-getURL(url="https://test.sagepay.com/access/access.htm",
               postfields=req,
               httpheader=myheader,
               verbose=TRUE)

The error I am getting looks like this:

*   Trying 195.170.169.8...
* Connected to test.sagepay.com (195.170.169.8) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: C:/Users/Jack/Documents/R/win-library/3.5/RCurl/etc/ca-bundle.crt
  CApath: none
* error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
* Closing connection 0
Error in function (type, msg, asError = TRUE)  : 
  error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

I have omitted any actual passwords/usernames.

Jack
  • 19
  • 1
  • The error isn't in your XML parts (I have no idea if that's proper XML for this API, but it's not causing the SSL error). It looks like you've got the 1.95-4.11 version of `RCurl` which has a _really_ old CA Root Cert bundle which may be part of the problem. – hrbrmstr Sep 25 '18 at 14:33
  • I think thats as new as it goes:https://cran.r-project.org/web/packages/RCurl/index.html I will try with a different package that can do similar stuff like httr curl maybe, just need to figure out how to post the XML :) – Jack Sep 25 '18 at 15:27
  • `getURL` has a poorly documented `cainfo` parameter which takes a full path to a valid cert file. https://curl.haxx.se/docs/caextract.html has some you can try. – hrbrmstr Sep 25 '18 at 15:37

0 Answers0