Context.response set variable = "undefined"

I have spent far too much time trying to troubleshoot something that I think is trivial, but I am not able to retrieve the value of a json object in an HTTP GET response and thus set it as a variable.

I have tried all variants of $context.response.data.quotes[0].quote (I’m not exactly sure where the array actually sits, as I’m obviously not that familiar with json formatting, just know enough to be dangerous) and I just can’t figure out why the value comes up null. Here is the response I get:

{
    "success": {
        "total": 1
    },
    "contents": {
        "quotes": [
            {
                "quote": "A man who has no imagination has no wings.",
                "length": "42",
                "author": "Mohamad Ali",
                "tags": [
                    "imagination",
                    "inspire"
                ],
                "category": "inspire",
                "language": "en",
                "date": "2023-01-10",
                "permalink": "https://theysaidso.com/quote/mohamad-ali-a-man-who-has-no-imagination-has-no-wings",
                "id": "dl_4NxcXFZp1k_zw541sVgeF",
                "background": "https://theysaidso.com/img/qod/qod-inspire.jpg",
                "title": "Inspiring Quote of the day"
            }
        ]
    },
    "baseurl": "https://theysaidso.com",
    "copyright": {
        "year": 2025,
        "url": "https://theysaidso.com"
    }
}

Any help would be appreciated, thanks!

If that’s the exact response you’re getting, then it looks like it should be:

$context.response.data.contents.quotes[0].quote
//                    ↑
//              everything on the right of this dot is the JSON path
1 Like

:frowning:

Still getting “undefined”

Here’s the rule (there’s no API key or anything so you can see for yourself):

Something’s not quite lining up for me. When I try that API, it comes back as XML instead of JSON. Is there a parameter you were using when testing in your browser that’s not being used in your rule?

Edit: It appears that the Accept header changes the format of the response between XML and JSON. :slight_smile:

Have you tried testing without a Delay? You shouldn’t need a delay as the HTTP Action will await the result before moving onto the next action.

In my example above, I was using an expression in the middle block as I wanted to test and confirm what the raw response that SharpTools was receiving was. I just happened to use the same thing on the last block too, but a Variable source would have worked fine too.

1 Like

YES, I realized the “accept” header was the key, and I removed the delay. Thank you!

1 Like