LimeSurvey - multiple parameters in post

Hi all

I’ve been having a go with Rows (and also Postman) to see if I can extract data from my LimeSurvey install automatically into a spreadsheet.

The steps I need to do are:

  1. Post request to get a session key
  2. Using session key, do the fun stuff

I’ve managed to get this working in Postman, now Rows!

To get a session key, the post body I need to construct is here:
https://manual.limesurvey.org/RemoteControl_2_API
(heading JSON-RPC notes)

I’ve mastered using PAIR2JASON to create pairs of keys and values - how do I go about populating the key “params” which has 2 values? Interested to find out how you deal with keys that have an arbitrary array of values inside square brackets. As far as I can tell range2jason is for a big array of pairs?

1 Like

Hey @Grover :wave:t4: — thanks for reaching out.

With regards to the RANGE2JSON function, it doesn’t have to be a big array of pairs. You can use it with 1 key (which would be the header parameter) and 1 value too.

I couldn’t identify the final output that you’re trying to achieve — could you perhaps share the raw output of the JSON with the key “params” that has 2 values?

In case you’d like to see an example of fairly complex JSON data wrangling using PAIR2JSON & RANGE2JSON, here’s (hopefully) a good example -

1 Like

Thanks for replying so quickly :slight_smile: Here’s how it looks in Postman

{
    "method": "get_session_key",
    "params": [
        "username",
        "pass"
            ],
    "id": 1
}

I can easily use PAIR2JASON to set up “method” and “id”, how do I go about setting up “params” which has two attributes?

eg PAIR2JASON(“Method”, “get_session_key”, “id”, “1”)

1 Like

Ah! I see what you may’ve needed and thanks for sharing the raw JSON.

Here’s how you can achieve it -

If it helps, here’s the formula that I’m using on my cell F2 -
=PAIR2JSON(A1,B1,A2,SUBSTITUTE(SUBSTITUTE(RANGE2JSON(A2,B2:C2),'{"'&A2&'":',""),"}",""),A3,B3)

I’m sure there are better / alternate ways to achieve this using CONCATENATE (or maybe other similar functions) but I hope you’re able to choose what suits best for your needs :blush:

1 Like

Gotcha, so basically use string manipulation, will look into. Some one who knows regex might also come up with a standard expression

Would it be cheeky at this stage to suggest a LISTOTHEJSON function, such that:

=LISTOTHEJSON(key, value 1, value 2…value x)?

Does all that nasty square bracketing and quote mark setting behind the scenes.

And also big thanks for the help!!

1 Like

Not at all :innocent:

In fact, we also already have a suggestion for ADD_TO_JSON, RANGE2ARRAY & other similar functions as well — I suppose these would be a lot easier to build once we have custom functions open for all :wink:

In any case, should there be anything else you need help with, please do not hesitate to reach out!

1 Like

Will keep a eye out on your blog.

For what it’s worth, might be worth considering a formal LimeSurvey connector…plenty of basic users of LimeSurvey in universities particularly who want to extract surveydata to SAS, matlab etc but are not natural api users and would prefer to see the data live without batch downloading.

1 Like

You got it :muscle:t4: Added LimeSurvey to our list.

1 Like