Get key and value from mappable parameters?

I’ve been playing around with building my own app to speed up work projects. One area that I’m stuck on is, can I get the key and value for an array from mappable parameters? (Similar to how when you set up a HTTP app request, you can set the value and key for headers) Currently, I can only figure out how to set the key in the mappable parameters using the name and the value is what can be entered as text on the front end. I tried searching here and Stack Overflow, but didn’t see anything. Thanks for the help as I learn!
Jacob

Hi @JE451 ,

To fully understand your question, can you please provide an example of what you have now and what your expected result is? This will make it easier for us to have a look :slight_smile:

Glenn - Callinetic

Hi @Callinetic,

I’d be glad to.
What I currently have on the backend is:

[
{
    "name": "dataItems",
    "type": "collection",
    "label": "Data Items",
    "spec": [
        {
            "name": "name",
            "type": "text",
			"label": "Name"
        },
        {
            "name": "value",
            "type": "text",
			"label":"Value"
        }
    ]
}
]

I tried both collection and array, but it didn’t seem to do what I need.
What shows up on the front end and when sending the request are the pictures below.

What I would like to do it something similar to the header part of the http request, where you can have an array of key/value pairs.

Which shows up as a key/value pair in the request.

In the end I would be able to have something like
{“myslug1”:“ID”, “myslug2”:“First Name”, “myslug3”:" Last name", “myslug4”: "…}

Hi @JE451 ,

Thank you for sharing. To achieve the same result, you must use the array type in your mappable parameters section for Data Items.

{
    "label": "Data Items",
    "name": "dataItems",
    "spec": [
        {
            "name": "key",
            "type": "text",
            "label": "Key"
        },
        {
            "name": "value",
            "type": "text",
            "label": "Value"
        }
    ],
    "type": "array"
}

Then in the communication section of your app, you can transform that array to have the key:value format by using the following syntax: "{{...}}": "{{toCollection(parameters.dataItems, 'key', 'value')}}"

For example:

"body": {
    "dataItems": {
        "{{...}}": "{{toCollection(parameters.dataItems, 'key', 'value')}}"
    }
}

I hope this solves your issue.
Glenn - Callinetic

5 Likes

Hi Glenn (@Callinetic )

Yes, that fixed it! I missed the “toCollection” syntax under the Javascript In Make help page.
Thank you!
Jacob

Hi,

How should I modify the “body” if this example is inside the “vectors” array?