Setting server side object variables

Hi All,

I have two questions, both related to server side actions.

  1. How do I assign values to variables contained within a session object. In other words, in the screenshot below, what is the syntax for “name” in set session properties, for test[var1]?

23%20PM

  1. Similarly, how do I send complex objects via the API action?

For example, with this json body to be sent:

{
	"client_id": "{{client_id}}",
	"secret": "{{secret_key}}",
	"access_token": "ENTER_ACCESS_TOKEN_HERE",
	"start_date": "2017-01-01",
	"end_date": "2018-01-01",
	"options": {
		"count": 250,
		"offset": 100
	}
}

How do I format the input data value for “options”? I can successfully send to the api without the options value, but can not find the right syntax for the nested object.

45%20PM

Appreciate any help here!

–Ken

Any thoughts? The first item isn’t a blocker, but sending nested json to the api is. Hope there is a solution!

Try pls
Options[{{$index}}][count]
Options[{{$index}}][offset]

Thanks @s.alpaslan. I’m trying to call an api, and send json, not evaluate a response containing json. I’m looking for how to build nested elements in a server api POST action and send that json.

{
  "options": [
    {
      "count": "20",
      "offset": "100"
    }
  ],
  "client_id": "123",
  "secret": "test_secret",
  "access_token": "test",
  "start_date": "2019-01-01"
}

is this result correct / enought for you ?

use this {{$_POST.options}}
and field name must be an array like Options[{{$index}}][count] in repeater

or Options[0][count] / Options[0][offset]

it will work perfect …

and you can modify the server action file so you can just use {{$_POST}}

"options": {
        "url": "https://aaa.requestcatcher.com/",
        "dataType": "json",
        "data": {{$_POST}},
        "method": "POST"
      },
      "output": true

Thanks @s.alpaslan.

I’m actually triggering all this server-side in response to a webhook, so there isn’t any opportunity to build in with $_POST.

I finally realized however, that I can just edit my server api action in the editor and build the nested json I need! So, problem solved, but it would be nice at some point to be able to build these in the gui editor.

It ends up looking like this:

I was able to use the editor in order to get the “count” and “offset” elements added to the json, and this works great. I have one last piece though, that I can’t decipher.

I need to add the “account_ids” which is a list of strings. These values will come from a db query.

{
	"client_id": "{{client_id}}",
	"secret": "{{secret_key}}",
	"access_token": "ENTER_ACCESS_TOKEN_HERE",
	"start_date": "2017-01-01",
	"end_date": "2018-01-01",
	"options": {
		"count": 250,
		"offset": 100,
		"account_ids": ["223984798DJEKL", "SHLEI290500S"]
	}
}

I’m assuming I use some form of {{queryGetAccounts.account_ids}} but haven’t found anything that works in json.

Anybody know how do I reference a db query array, and maintain a proper json request?

@patrick can you help with this last piece? How to get a list into an api action input.

If {{queryGetAccounts.account_ids}} return the exact data needed then you can use it, just put it in a string like "account_ids": "{{queryGetAccounts.account_ids}}". If it is not in the correct format then perhaps one of the formatters can help, if you are missing a formatter then let us know.

Unfortunately, that returns null.

From the wappler editor, the api action (note, I had account_ids instead of account_id originally for the db query results, which was a typo):

Here’s the raw capture from webhook.site:

And here is what queryGetAccounts is returning:

Thanks for the help!

try {{queryGetAccounts.groupBy('account_id').keys()}}

Success!

"options": {
              "count": 500,
              "offset": 0,
              "account_ids": "{{queryGetAccounts.groupBy('account_id').keys()}}"
            }

Thanks Patrick…very much appreciate your time on this.