OpenFIGI / api-examples

Examples of programs that interact with the OpenFIGI services via their APIs.
Apache License 2.0
137 stars 50 forks source link

"Request body must be a valid JSON array" returned #6

Closed mikegreen closed 6 years ago

mikegreen commented 6 years ago

What am I missing here? Sending this: .\curl -X POST 'https://api.openfigi.com/v1/mapping' -k -H 'Content-Type: text/json' -H 'api_key_here' --data '[{"idType":"ID_WERTPAPIER","idValue":"851399","exchCode":"US"}]'

And getting back: Request body must be a valid JSON array.

jayflo commented 6 years ago

I am not sure, this works for me:

$ curl -X POST 'https://api.openfigi.com/v1/mapping' -k -H 'Content-Type: text/json' -H 'api_key_here' --data '[{"idType":"ID_WERTPAPIER","idValue":"851399","exchCode":"US"}]'
[{"data":[{"figi":"BBG000BLNNH6","name":"INTL BUSINESS MACHINES CORP","ticker":"IBM","exchCode":"US","compositeFIGI":"BBG000BLNNH6","uniqueID":"EQ0010080100001000","securityType":"Common Stock","marketSector":"Equity","shareClassFIGI":"BBG001S5S399","uniqueIDFutOpt":null,"securityType2":"Common Stock","securityDescription":"IBM"}]}]

I just copied your command (except for the leading .\)

jayflo commented 6 years ago

Also note that your api key should be included as

--header 'X-OPENFIGI-APIKEY: ...'

Also make sure the command is has no new lines, or if it does, use \ at the end of all lines but the last like so:

curl -v -X POST 'https://api.openfigi.com/v1/mapping' \
     --header 'Content-Type: text/json' \
     --header 'X-OPENFIGI-APIKEY: abcdefghijklmnopqrstuvwxyz' \
     --data '[{"idType":"ID_WERTPAPIER","idValue":"851399"}]'
mikegreen commented 6 years ago

Weird. It runs as I pasted it on another machine but not this one... Must be the build of curl for windows. Runs fine on OSX and a Ubuntu box. thanks...