Python: Properly formatting JSON parameters into a proper http request with markit on demand api
Question: I am having trouble formatting my request properly in order to use the
markitondemand InteractiveChart API. How can I properly do this?

reference: <http://dev.markitondemand.com/MODApis/>

Here is an example of a proper request:

    
    
    http://dev.markitondemand.com/MODApis/Api/v2/InteractiveChart/json?parameters=%7B%22Normalized%22%3Afalse%2C%22NumberOfDays%22%3A10%2C%22DataPeriod%22%3A%22Day%22%2C%22Elements%22%3A%5B%7B%22Symbol%22%3A%22AAPL%22%2C%22Type%22%3A%22price%22%2C%22Params%22%3A%5B%22c%22%5D%7D%5D%7D
    

Here is my code constructing a request:

    
    
    import requests
    import json        
    url2 = 'http://dev.markitondemand.com/MODApis/Api/v2/InteractiveChart/json'
    elements = [
            {
                'Symbol': 'GOOG',
                'Type': 'price',
                'Params': {'price': ['c']},
            }
        ]
    
    req_obj = {
        'Normalized': 'false',
        'NumberOfDays': 3,
        'DataPeriod': 'Day',
        'Elements': elements
    }
    
    resp = requests.get(url2, params={'parameters': json.dumps(req_obj)})
    

and here is the output when I log the resp.url :

    
    
    http://dev.markitondemand.com/MODApis/Api/v2/InteractiveChart/json?parameters=%7B%22Elements%22%3A+%5B%7B%22Type%22%3A+%22price%22%2C+%22Params%22%3A+%7B%22price%22%3A+%5B%22c%22%5D%7D%2C+%22Symbol%22%3A+%22GOOG%22%7D%5D%2C+%22NumberOfDays%22%3A+3%2C+%22DataPeriod%22%3A+%22Day%22%2C+%22Normalized%22%3A+%22false%22%7D
    

What am I doing wrong here?


Answer: Your url end point (by the looks of it) should just be:

    
    
    url2 = 'http://dev.markitondemand.com/MODApis/Api/v2/InteractiveChart
    

Then, make your request:

    
    
    resp = requests.get(url2, params=json.dumps({'parameters': req_obj}))
    

Then `requests` will properly handle the `?` and any `&` if they were
required.

