All Apps and Add-ons

API Modular input Response Handle JSON

dsofoulis
Path Finder

Hi Everyone,

I am using the API modular input to collect data from an API. Problem is the getting the data in, correctly. Without using a response handle I can get everything in one event and I'm not able to break them into individual events. Using a response handle I'm not able to get the complete data.

SAMPLE Data looks like this:

{
    "Meta Data": {
        "1. Information": "Intraday Prices and Volumes for Digital Currency",
        "2. Digital Currency Code": "BTC",
        "3. Digital Currency Name": "Bitcoin",
        "4. Market Code": "AUD",
        "5. Market Name": "Australian Dollar",
        "6. Interval": "5min",
        "7. Last Refreshed": "2018-01-31 22:20:00",
        "8. Time Zone": "UTC"
    },
    "Time Series (Digital Currency Intraday)": {
        "2018-01-31 22:20:00": {
            "1a. price (AUD)": "12474.57250163",
            "1b. price (USD)": "10049.09321579",
            "2. volume": "1947.32278014",
            "3. market cap (USD)": "19568828.13886100"
        },
        "2018-01-31 22:15:00": {
            "1a. price (AUD)": "12477.02432481",
            "1b. price (USD)": "10051.06832152",
            "2. volume": "1946.46090562",
            "3. market cap (USD)": "19564011.54755900"
        },
        "2018-01-31 22:10:00": {
            "1a. price (AUD)": "12482.11267077",
            "1b. price (USD)": "10055.16732073",
            "2. volume": "1947.86047516",
            "3. market cap (USD)": "19586062.99517900"
        },
        "2018-01-31 22:05:00": {
            "1a. price (AUD)": "12469.69385098",
            "1b. price (USD)": "10045.16314001",
            "2. volume": "1957.84301556",
            "3. market cap (USD)": "19666852.49383900"
        },
        "2018-01-31 22:00:00": {
            "1a. price (AUD)": "12465.88588954",
            "1b. price (USD)": "10045.88292284",
            "2. volume": "1967.23063556",
            "3. market cap (USD)": "19762568.64706900"
        },
        "2018-01-31 21:55:00": {
            "1a. price (AUD)": "12449.19799086",
            "1b. price (USD)": "10032.43464665",
            "2. volume": "2016.41002232",
            "3. market cap (USD)": "20229501.76977700"
        },
        "2018-01-31 21:50:00": {
            "1a. price (AUD)": "12459.09475997",
            "1b. price (USD)": "10040.41015555",
            "2. volume": "2016.23520360",
            "3. market cap (USD)": "20243828.41419600"
        },
};

I am also using a customer response handler, see below:

class BitcoinHandle:

def __init__(self,**args):
    pass

def __call__(self, response_object,raw_response_output,response_type,req_args,endpoint):
    if response_type == "json":        
        output = json.loads(raw_response_output)
        for price in output["Meta Data"]:
            print_xml_stream(json.dumps(price)) 


    else:
        print_xml_stream(raw_response_output)

alt text

The issue that I'm having is that it's not looping through the nested JSON data, I am only getting the following data, not I'm not even getting the key value pairs, just the heading. I have no idea what I'm doing wrong. I would like to have all the data coming in and breaking correctly. Please help!

alt text

Get Updates on the Splunk Community!

Splunk Education - Fast Start Program!

Welcome to Splunk Education! Splunk training programs are designed to enable you to get started quickly and ...

Five Subtly Different Ways of Adding Manual Instrumentation in Java

You can find the code of this example on GitHub here. Please feel free to star the repository to keep in ...

New Splunk APM Enhancements Help Troubleshoot Your MySQL and NoSQL Databases Faster

Splunk Observability has two new enhancements to make it quicker and easier to troubleshoot slow or frequently ...