0

Can some one help with the codes for connecting an API using R and uploading file consisting of around 2k records into the API using R

I tried the below codes but not helping out:

apiurl <- "https://api.thomsonreuters.com/permid/match/file"
Records <- "C:\\Users\\U6028364\\Downloads\\Organization_input_template_with_examples.csv
  resp <- POST(apiurl,body=list(

                    addressFile=upload_file(Records),
                    Content-Type="multipart",


      ))

stop_for_status(resp)
get_data <- content(resp,"text")

Thanks Gautam

4
  • 1
    your question is very unclear and open ended Commented Dec 12, 2018 at 10:46
  • 1
    What issues are you specifically having? What have you tried? (Edit your question) Commented Dec 12, 2018 at 10:47
  • googling your question exactly: stackoverflow.com/questions/25733571/… does this resolve it? Commented Dec 12, 2018 at 11:15
  • No John that is not helping out.Below is the error I got when running the above code:Error: Unauthorized (HTTP 401) Commented Dec 12, 2018 at 11:48

2 Answers 2

1

Trying to explain the following with a paragraph in a comment would be painful, so take a look at:

api_url <- "https://api.thomsonreuters.com/permid/match/file"

records <- "C:\\Users\\U6028364\\Downloads\\Organization_input_template_with_examples.csv"

httr::POST(
  url = api_url,
  body = list(
    addressFile = httr::upload_file(records),
  ),
  encode = "multipart"
) -> resp

httr::stop_for_status(resp)

get_data <- content(resp, "text")

the only real change is that you need to use the encode parameter (also, you missed a " in your question code).

I don't have access to the TR API so I can't test this. However, https://docs-developers.thomsonreuters.com/1544617757924/45690/wwhelp/wwhimpl/js/html/wwhelp.htm#href=PermID%20Service/PermID%20APIs%20User%20Guide.1.27.html says this is the curl command line to do what you are trying to do:

curl -X POST https://api.thomsonreuters.com/permid/match/file 
     -H "Content-Type: multipart/form data" 
     -H "x-openmatch-numberOfMatchesPerRecord: 1" 
     -H "x-openmatch-datatype: Organization" 
     -H "X-AG-Access-Token: <token>" 
     -F [email protected]

You're missing some things if that is the case and also using an improper body, so this might work better:

httr::POST(
  url = api_url,
  httr::add_headers(
    `X-AG-Access-Token` = "YOUR_ACCESS_TOKEN_WHICH_YOU_RLY_SHLDNT_PUT_DIRECTLY_IN_R_SCRIPTS"
  )
  body = list(
    file = httr::upload_file(records)
  ),
  encode = "multipart"
) -> resp

I have no idea if the other "openmatch" headers are required or not.

Sign up to request clarification or add additional context in comments.

6 Comments

I tried with your above codes but it is giving the below error:Error in list(file = httr::upload_file(records), ) : argument 2 is empty
i originally had httr::verbose() as a parameter after httr::upload_file(records) and forgot to remove the comma. try it now with that comma removed
This is the error it is giving : Error in as.request(config) : object 'httr' not found
And I missed a : on one of the fully qualified function references (I realize the error was my typo but both the , and the missing : are basic R errors that would be good to be familiar with in terms of you being able to work with R…I'm assuming you're really new to R as a result).
Yes I am pretty new to R.I didnt quite understand on where did you missed a :
|
0

Below is what i tried to do but it is giving error as: Error in as.request(config) : object 'httr' not found

httr::POST(
  url = api_url,
  httr:add_headers(
    X-AG-Access-Token : "abcd"

  ),
  body = list(
    file = httr::upload_file(records)
  ),
  encode = "multipart"
) -> resp

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.