urlencode list universe in data/symbology/convert
Hello,
I am using the elektron platform's category=data/symbology, endpoint=convert and I am also using python3's urllib for making GET/POST request.
I can use the following GET method for converting symbols (which means my headers, auth, etc are all good):
https://api.refinitiv.com/data/symbology/beta1/convert?universe=IBM.N@RIC,MSFT.O@RIC
However when I tried to use the POST method and construct the body with a list of symbols I get 400 error. More specifically, what is the anticipated body for the following data:
data = {
"universe": [
"IBM.N",
"MSFT.O",
]
}
is it 'universe=IBM.N&universe=MSFT.O', 'universe=IBM.N,MSFT.O', 'universe%5B%5D=%5B%27IBM.N%27%2C+%27MSFT.O%27%5D' or 'universe=%5B%27IBM.N%27%2C+%27MSFT.O%27%5D'? The later two are given by urllib's urlencode method.
Thanks,
Best Answer
-
The body of the POST message should be a JSON object. when you pass the dictionary object to the library, the object gets split up and is sent as individual name/value pairs.
I used:
data = json.dumps(requestData)
and it works. Try using a debugging proxy to catch and verify the actual request that your application is sending down and crosscheck it with the capture that I have posted here.
0
Answers
-
Http Status code 400 is a Bad Request. Your request body is not a valid format.
Please remove ',' after "MSFT.O". The correct one should bedata = { "universe": [ "IBM.N", "MSFT.O" ] }
You can also try your JSON request data with APIDocs Playground before using it with your python codes.
0 -
It still does not work without the ','.
python's urlencode treat them the same as an input Dict[str, List[str]] and after encoding, I am looking for the right format of the body your API expects.
Again, I am struggling to find whether it is
(1) 'universe=IBM.N&universe=MSFT.O'
(2) 'universe=IBM.N,MSFT.O'
(3) 'universe%5B%5D=%5B%27IBM.N%27%2C+%27MSFT.O%27%5D'
(4) 'universe=%5B%27IBM.N%27%2C+%27MSFT.O%27%5D'
after the encoding? None of them seems to work for me.
0 -
This is the raw HTTP capture:
POST https://api.refinitiv.com/data/symbology/beta1/convert HTTP/1.1
Host: api.refinitiv.com
.
.
Content-Length: 31
Authorization: Bearer eyJ0eXAiOiJK****
{"universe":["MSFT.O","IBM.N"]}If you post your code snippet, we can help you tweak it.
0 -
Here is a minimal code snippet I have been using, it employs OpenerDirector from urllib because my company environment needs SSLCertificate, ProxyHandler, etc that goes beyond the functionalities of the request library.
Below, 'YOUR TOKEN STR' is the access_token from auth/oauth2, token endpoint.
from urllib.parse import urlencode
from urllib.request import build_opener, Request
opener = build_opener()
opener.addheaders = [
('Authorization', 'Bearer %s' % 'YOUR TOKEN STR'),
('Accept', 'application/json'),
('Content-Type', 'application/json')
]
# GET works for me
ans = opener.open(Request('https://api.refinitiv.com/data/symbology/beta1/convert?universe=MSFT.O,IBM.N'))
# which one of them is correct? None works for me
data = '{"universe":["MSFT.O","IBM.N"]}'
data = urlencode({"universe": ["MSFT.O", "IBM.N"]})
data = urlencode({"universe": ["MSFT.O", "IBM.N"]}, doseq=True)
# POST
ans = opener.open(Request('https://api.refinitiv.com/data/symbology/beta1/convert'), data=data.encode('utf-8'))
0 -
Thanks for the tip, it helps solving the problem, json.dumps would give a string that equals the first data I listed above:
data = '{"universe":["MSFT.O","IBM.N"]}'
The problem is with my function call of Request, my opener has the header of (Content-Type, application/json) but it is not added to the Request object. when I changed it to the following it works
req = Request('https://api.refinitiv.com/data/symbology/beta1/convert')
req.add_header('Content-Type', 'application/json')
ans = opener.open(req, data='{"universe":["MSFT.O","IBM.N"]}'.encode('utf-8'))
0
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛