No HTTP resource was found when use REST API in R
Hi all,
I'm trying to use REST API to connect TRTH in R, now I'm having problem with my code
library(httr)
uri1 <- "https://hosted.datascopeapi.reuters.com/RestApi/v1/Search/HistoricalSearch"
token1 <- paste("Token", cred[2], sep = " ")
body1 <- '{ "Request": { "Identifier": "TRI.N", "IdentifierType": "Ric", "Range": { "Start": "2015-11-17T00:00:00.000Z", "End": "2015-11-24T00:00:00.000Z" } } }'
a <- httr::GET(uri1, body = body1, add_headers(Prefer = "respond-async",Authorization = token1))
result <- httr::content(a, "parsed", "application/json")
In the above code I save my token in cred[2]
After I run my code, I get this result
$error
$error$message [1]
"No HTTP resource was found that matches the request URI 'https://hosted.datascopeapi.reuters.com/RestApi/v1/Search/HistoricalSearch'."
Looks like I have a wrong URI input, but I just copy this address from sample code.
I appreciate that if anybody can help me with this issue.
Best Answer
-
Now I solve this problem, I really appreciate your help
For the convenience for all other guys, here is the correct code .
The mistake I have is httr::POST part
I should declare content_type_json() in the header first
getIdentifier <- function(cred, Identifier, IdentifierType){
uri1 <- "https://hosted.datascopeapi.reuters.com/RestApi/v1/Search/HistoricalSearch"
part1 <- c('{"Request": {"Identifier": "')
part2 <- c('","IdentifierType": "')
part3 <- c('", "Range": {
"Start": "2015-11-17T00:00:00.000Z",
"End": "2015-11-24T00:00:00.000Z"}}}')
token1 <- paste("Token", cred[2], sep = " ")
request <- paste(part1, Identifier, part2, IdentifierType, part3, sep = "")
a <- httr::POST(uri1, body = request,
add_headers(Prefer = "respond-async",Authorization = token1),
content_type_json())
result <- httr::content(a, "parsed", "application/json")
return(result)
}0
Answers
-
-
Thank you for point this out, actually I tried both method. If I use httr:POST I will obtain a different error message
$error
$error$message
[1] "The request contains an entity body but no Content-Type header. The inferred media type 'application/octet-stream' is not supported for this resource."I appreciate your apply, hope to see your feedback soon
0 -
This error means that you have not defined Content-Type in your http request header.
Please follow the sample request from the developer guide.
The Content-Type is "application/json"
0 -
Here is the detailed information I observed, I hope it could be helpful regarding on this issue
Starting from variable "a", my output is incorrect
Here is the output of a
Response [https://hosted.datascopeapi.reuters.com/RestApi/v1/Search/HistoricalSearch]
Date: 2017-09-27 00:20
Status: 404
Content-Type: application/json; charset=utf-8
Size: 157 BBased on this description, I think the issue is related to the uri i'm using
And for the The Content-Type you just mention in previous reply, I think I set up the correct format.
For your information, here is another example I write in R, which works fine
getUserInfo <- function(cred){
part1 <- "https://hosted.datascopeapi.reuters.com/RestApi/v1/Users/Users("
part2 <- ")"
uri1 <- paste(part1, cred[1], part2, sep = "")
token1 <- paste("Token", cred[2], sep = " ")
a <- httr::GET(uri1, add_headers(Prefer = "respond-async", Authorization = token1))
result <- httr::content(a, "parsed", "application/json")
return(result)
}0 -
I just did 3 tests on the API calls:
1. POST method following the sample request from developer guide
Request:
POST https://hosted.datascopeapi.reuters.com/RestApi/v1/Search/HistoricalSearch HTTP/1.1
Prefer: respond-async
Content-Type: application/json
Authorization: Token <mytoken>
Cache-Control: no-cache
{
"Request": {
"Identifier": "US4592001014",
"IdentifierType": "Isin",
"Range": {
"Start": "2008-01-01T00:00:00.000Z",
"End": "2008-01-01T00:00:00.000Z"
}
}
}Response:
HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
@{"@odata.context":"https://hosted.datascopeapi.reuters.com/RestApi/v1/$metadata#Collection(ThomsonReuters.Dss.Api.Search.HistoricalSearchResult)","value":[{"Identifier":"IBM","IdentifierType":"Ric","Source":"","Key":"VjF8MHgzMDAwMDAwMDAwMDAwMDAwfDB4MzAwMDAwMDAwMDAwMDAwMHx8fHx8fHxJQk18","Description":"Historical Instrument","InstrumentType":"Unknown","Status":"Valid","DomainCode":"6","FirstDate":"1996-01-02T00:00:00.000Z","LastDate":"2017-09-26T00:00:00.000Z","History":[]},...<a lot of entries here>...}2. POST method with incorrect Content-Type header
Request:
POST https://hosted.datascopeapi.reuters.com/RestApi/v1/Search/HistoricalSearch HTTP/1.1
cache-control: no-cache
Prefer: respond-async
Content-Type: application/octet-stream
Authorization: Token <mytoken>
{
"Request": {
"Identifier": "US4592001014",
"IdentifierType": "Isin",
"Range": {
"Start": "2008-01-01T00:00:00.000Z",
"End": "2008-01-01T00:00:00.000Z"
}
}
}Response:
HTTP/1.1 415 Unsupported Media Type
Cache-Control: no-cache
Content-Length: 118
Content-Type: application/json; charset=utf-8
{"error":{"message":"The request entity's media type 'application/octet-stream' is not supported for this resource."}}3. GET method
Request:
GET https://hosted.datascopeapi.reuters.com/RestApi/v1/Search/HistoricalSearch HTTP/1.1
cache-control: no-cache
Prefer: respond-async
Content-Type: application/json
Authorization: Token <mytoken>Please note that HTTP GET method cannot contain body.
Response:
HTTP/1.1 404 Not Found
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
{"error":{"message":"No HTTP resource was found that matches the request URI 'https://hosted.datascopeapi.reuters.com/RestApi/v1/Search/HistoricalSearch'."}}I do not put all the detail headers here, just only related headers to troubleshoot the issue.
Hope this is more clear now.
0 -
Please refer to page 38th on the developer guide.
From the sample Request, this API call does not require Content-Type nor body.
So it is working as expected.
0 -
Thanks for your clarification. It makes sense. And I notice that the 3rd example you provide has the identical error that I have
So maybe I need to declare this Content type at the beginning of my code.
0 -
Yes you are right. Thanks for this clarification
0 -
Your reply is the key issue that help me solve this problem.
Since this issue is related to R, I post the correct solution for this issue and accept it as highlight answer.
If you want this reply to be highlight, I will cancel my accept and highlight this long reply from you
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 690 Datastream
- 1.5K DSS
- 629 Eikon COM
- 5.2K Eikon Data APIs
- 11 Electronic Trading
- 1 Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 255 ETA
- 560 WebSocket API
- 39 FX Venues
- 15 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 25 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 281 Open PermID
- 46 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 23 RDMS
- 2K Refinitiv Data Platform
- 723 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 106 UPA
- 194 TREP Infrastructure
- 229 TRKD
- 918 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 95 Workspace SDK
- 11 Element Framework
- 5 Grid
- 19 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛