locked
Include an array in the request body parameter in a HTTP dataset RRS feed

  • Question

  • I want to include a dynamic array as part of the request body in a http dataset.

    The final request will look like this:

    {
    "address" : "http://serviceendpoint.com",
    "path" : "/directory",
    "port" : 22,
    "fileNames" :["file1.dat", "file2.dat"],
    "userCredentials" : {
    "userName" : "me@demo.com",
    "password" : "mypass"
    },
    "fingerPrintKey" : "ssh-dss 2048 bd:e6:22:63:e1:00:88:48:3e:b2:55:4f:52:e0:53:37"
    }

    but to generate it I will specify dataset parameters like this:

    {
    "address":"@{dataset().ftpaddress}",
    "path":"@{dataset().ftppath}",
    "port":22,
    "fileNames": @{dataset().filenamelist},
    "userCredentials":{
    "userName":"@{dataset().ftpusername}",
    "password":"@{dataset().ftppassword}"
    },
    "fingerPrintKey":"@{dataset().ftpfingerprintkey}"
    }

    Now the request to the server is failing and giving a 500 error, and I have narrowed it down to a problem with the filenames parameter. Unfortunately, there doesn't seem to be any way to dump or debug the content of the request after the interpolation. So I am doing this by trial and error. I am constructing an array variable from a string.

    The initial string variable looks like this:

    "File1_@{variables('FileDateStamp')}.out", "File2_@{variables('FileDateStamp')}.out"

    To create an array from this, I am trying to use the createarray function, which needs an input like this:

    'File1_20181112.out', 'File2_20181112.out'

    So I have 2 intermediate setvariable activities which substitute the date variable, then replace the double quotes with single quotes.

    Step 1 - Remove double quotes and replace with single quotes : set variable RequiredFileListFormatted using expression 

    @replace(variables('RequiredFileListString'),'"','''')

    result:

    {    "name": "RequiredFileListFormatted",    "value": "'File1_20181112.out', 'File2_20181112.out'"}

    Step 2 - convert to an array : 

    @createArray(variables('RequiredFileListFormatted'))

    result:

    {
        "name": "RequiredFileList",
        "value": ["'File1_20181112.out', 'File2_20181112.out'"]}

    i.e. it seems to want to create an array with one item.

    My questions are:

    1. How can I create an array with the correct number of items?

    2. Even if I do so, will supplying it as a parameter in the request body just work?

    3. Is there any way to investigate the output of the request body so I can verify that the expressions are working?

    thanks



    • Edited by muiscatron Monday, December 31, 2018 3:04 PM
    Monday, December 31, 2018 3:04 PM

All replies