2

I wonder if it is possible to convert the following OpenFIGI API command into python:

curl -v -X POST 'https://api.openfigi.com/v1/mapping'   \
     --header 'Content-Type: text/json'             \
     --data '[{"idType":"ID_WERTPAPIER","idValue":"851399","exchCode":"US"}]'

I tried the following:

import requests
data = {["idType":"ID_WERTPAPIER","idValue":"851399","exchCode":"US"]}
r=requests.post('https://api.openfigi.com/v1/mapping', headers={"Content-Type": "text/json"},data=data)

But r gets the value "Response [400]". According to the intro page https://www.openfigi.com/api#introduction, this identifies the scenario that "The request body is not an array". I am really new to curl, any suggestion will help.

1
  • curlconverter.com will convert your command for you Commented Sep 20, 2022 at 5:47

1 Answer 1

3

First api expects array of objects, not an object with array ( that's even invalid json) so correct is this:

data = [{"idType":"ID_WERTPAPIER","idValue":"851399","exchCode":"US"}]

Second - api expects json, so use json parameter, not data

r=requests.post('https://api.openfigi.com/v1/mapping',
                headers={"Content-Type": "text/json"},
                json=data)
Sign up to request clarification or add additional context in comments.

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.