Clean up array to remove space between items for use in API body

Hi,

The output of my array looks like this:

"item1", "item2", "item3"

But to use it in Dropbox API call it needs to be without the space (otherwise it can not decode the JSON body), like so:

"item1","item2","item3"


I use the set variable tool to remove empty strings from the array and then use the output of that to make the API call, which doesn’t work because of the space that’s being added in between each item in the array (as shown above).

Share the Dropbox module details and your full input bundle. Seems weird to need to remove spaces. It’s valid json either way as long as there is a valid json structure for Dropbox.

It might look a little strange with the red stripes, but I have no easy way to show it without hiding personal info like this. I will try my best to explain what went good and what went wrong.

Basically when I test the automation with 1 item in the array, it works like a charm.
When I try it with multiple items in the array, it doesn’t work anymore.

This is my Dropbox API setup:

This is my ‘set variable’ array output with 1 item:

The above works without issue:


But as soon as I add more items to the array, like so:

It doesn’t work anymore and the Dropbox API is giving the following error:

So I fail to understand what’s causing it to stop working if it works like a charm with one item in the array.

I’ll happily clarify anything that isn’t clear from the above images and situation.

Thanks for your time

Have you tested what does work in something like postman? What’s the api spec for multi file upload with Dropbox? Maybe your array is not correct for the paths key?

But it works when the input is like this:

"Item1", "item2"

And for some reason it doesn’t work when the input is this:

"Item1", "item2", "item3"

That really makes no sense. Make a scenario that doesn’t have the red lines with data you can share.

Input:

Dropbox module:


Dropbox error:

Doesn’t work.

Now the same situation (same dropbox module) but instead of the input having 4 items, it only has 1:

Dropbox success:

This is a case of some sort of weird gremlins in the body. Can you look in the input bundle on the make api call and see what the underlying structure actually is?

How would I best go about that? I’m not all that well-versed in any of this, but I try to make do.

Do you mean this?

[
    {
        "url": "/2/files/create_folder_batch",
        "body": "{\n    \"autorename\": false,\n    \"force_async\": false,\n    \"paths\": [\n        \"/Testing Environment/Folder/test 1\",\"/Testing Environment/Folder/test 1/a\", \"/Testing Environment/Folder/test 1/b\", \"/Testing Environment/Folder/test 1/c\", \"/Testing Environment/Folder/test 1/d\"\n    ]\n}",
        "type": "api",
        "method": "POST",
        "headers": [
            {
                "key": "Content-Type",
                "value": "application/json"
            }
        ],
        "disablePathRoot": false
    }
]

See the little icon in the upper right that has a little down arrow. You can look at output bundle. And then you want to try this all in postman to see actually what make api is supposed to do.

Yeah I hope those extra \n don’t mess it up. Try postman.

Postman seems a little bit too complicated for my skill level in all of this. What is interesting though is that the following works in comparison to the snippet of code I provided above:

[
    {
        "url": "/2/files/create_folder_batch",
        "body": "{\n    \"autorename\": false,\n    \"force_async\": false,\n    \"paths\": [\n        \"/Testing Environment/Folder/test 1\",\"/Testing Environment/Folder/test 1/b\"\n    ]\n}",
        "type": "api",
        "method": "POST",
        "headers": [
            {
                "key": "Content-Type",
                "value": "application/json"
            }
        ],
        "disablePathRoot": false
    }
]

The only real difference that I can spot is the space between the seperate items in the array that’s present in the first snippet (multiple items) and isn’t there in the second snippet (the one with 1 item that actually works).

That would be a first indeed. An api that forces no spaces in an array. It may be the escaping that’s causing issues too. Try postman. You’ll have a bit of a learning curve but it will save you lots of time when using make api call. You need to figure out what actually will work for multiple paths.

1 Like

I’ll look into postman, but for now I have figured out that the space might actually be the issue at hand here. I copied the inputs manually into the API and it returned an error. I then removed the spaces between the items manually, ran it again and it succesfully ran the entire call.

So I guess my question is is it possible to remove the space from the array and if so, how?

Replace(cleaned array dropbox,space,emptystring)

I have been playing around with Replace for a while before waking up to this comment, but funnily enough everything I try removes anything but the space that it should remove. Your suggestion removes all the spaces from the items as well, and yet still refuses to remove the space between the different items.

First I composed a string from the array:

Then I replaced the spaces with empty strings:

The output is as follows:

[
    {
        "value": "\"/TestingEnvironment/Folder/test1/a\", \"/TestingEnvironment/Folder/test1/b\", \"/TestingEnvironment/Folder/test1/c\", \"/TestingEnvironment/Folder/test1/d\""
    }
]

Even when I try to replace the ", " with emptystring it doesn’t work and returns the string as it was before I replaced it.

I think the array is still being kept as an array and the spaces are a Natural format. I’m out of ideas here.

It might be an issue on Make’s side of things, because I had a similar issue with mapping a body in the Discord API and then used the “Assemble Body” function and it worked like a charm. For some reason the Dropbox module doesn’t come with this option. I’ll keep trying to find a way to turn the array into an actual string and then remove the space.

I have worked it out using the Join() function and then using the comma as separator. Works like a charm now. Problem solved.

1 Like