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
- 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
- 688 Datastream
- 1.4K DSS
- 625 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
- 558 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
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 277 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 23 RDMS
- 1.9K Refinitiv Data Platform
- 695 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
- 92 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛