Mapping objects into page variable

I’ve been searching all day on the forum but without luck.
Here’s my scenario:
I make a http request to an api, the result is an object. How can i map every key with the appropriate pagevar?


the page var

{
    "error": false,
    "category": "Spooky",
    "type": "twopart",
    "setup": "Why did the ghost go to the bar?",
    "delivery": "To get sheet faced.",
    "flags": {
        "nsfw": false,
        "religious": false,
        "political": false,
        "racist": false,
        "sexist": false,
        "explicit": true
    },
    "safe": false,
    "id": 315,
    "lang": "en"
}

the response from http request


the button logic

Your response is already in PageVar JokeResponse. What would be the benefit of storing what’s already available in that PageVar into another PageVar?

Or are you saying saving HTTP request into PageVar JokeResponse doesn’t work in the first place?

Maybe im missing something obvious here.
So lets say i want to map each of the keys (“category”, “type” etc) with a text component.
How do i do that in this case when the api returns only an object?
MAP only works with lists.

Let’s have this PageVar variable1 as object with keys prop1 and prop2.

prop1 is a text property so I can directly assign it into the input of a text component, right?

You can do all usual stuff with it in formula of course.

So the “solution” I found is this:


Building the RestAPI with a free public API

Test is successfull but the API doesn’t return an array so you cannot build a schema from response

So the workaround for this is making a request via HTTP module

Set up an alert just to see what the formula spills out. The result was what expected allthough theres a warning

Create a page/app var and bind the output of the http request to the ‘Set pagevar’ module with the same formula.

Bind a text component to that pagevar and voila!

This is my workaround to this specific case. I don’t know if there’s a way to set it up via the Data tab or if there are any other formulas to MAP objects to variables. Until now all my attempts were unsuccessful mapping objects from http requests to variables.

1 Like