Accessing Subfolders with spaces via REST API

Have a great idea for extending Zimbra? Share ideas, ask questions, contribute, and get feedback.
User avatar
seth.stenzel
Posts: 3
Joined: Sat Aug 19, 2017 8:44 pm

Accessing Subfolders with spaces via REST API

Postby seth.stenzel » Sat Aug 19, 2017 8:39 pm

Hello all,

I'm relatively new to working with the REST API back end and documentation does not seem to cover my issue. I am trying to figure out what uri I would use to access and item that has a space in it.

EXAMPLE:
I have a sub folder in my inbox call "test", and a second folder called "test 1"

I can access the inbox and get data, or the test folder with the two calls respectively:

Code: Select all

https://mymail.***.com/home/seth.stenzel/inbox?fmt=json&auth=sc&query=is:unread
https://mymail.***.com/home/seth.stenzel/inbox/test?fmt=json&auth=sc&query=is:unread


However I cannot find what syntax need to be use when a sub folder contains a space in the name. I have tried '_', '+' and "%20" and all return that the object does not exist.

EXAMPLE:

Code: Select all

https://mymail.***.com/home/seth.stenzel/inbox/test_1?fmt=json&auth=sc&query=is:unread
https://mymail.***.com/home/seth.stenzel/inbox/test+1?fmt=json&auth=sc&query=is:unread
https://mymail.***.com/home/seth.stenzel/inbox/test%201?fmt=json&auth=sc&query=is:unread


All of the above will fail.

Any assistance would be greatly appreciated. Everything else is working save for that and its going to look silly to tell my boss, "We can run stats that inbox we just can't have a sub folder with a space in the name. :lol:

Thank you all!

~Seth S.


User avatar
tmclane
Zimbra Employee
Zimbra Employee
Posts: 4
Joined: Thu May 04, 2017 7:10 pm

Re: Accessing Subfolders with spaces via REST API

Postby tmclane » Fri Aug 25, 2017 12:17 am

Hello Seth,

May I ask which version you are running your tests against?
Perhaps your shell is removing or otherwise messing with your URL before it is sent to the server.
You can see exactly what the server sees by looking in the /opt/zimbra/log/access_log.<today's date>

/opt/zimbra/log/access_log.2017-08-24

Code: Select all

192.168.56.106 - - [25/Aug/2017:00:20:45 +0000] "GET https://zcs-desktop.dev:8443/service/home/user@zcs.dev/inbox/Spaced%20Folder?fmt=json HTTP/1.1" 200 269 "-" "Jakarta Commons-HttpClient/3.1" 10


Test Scenario

    Setup account on mailbox user@zcs.dev / <password>
    Login through webclient and create a folder inside the Inbox named Spaced Folder
    Send a few emails to your own account
    Move at least one email in to Spaced Folder

Request items in Spaced Folder using curl:

Note: The double quotes are to prevent the shell (in my case bash) from mangling the URL.
The %20 encoding for a space character works in my case.

Code: Select all

curl -k -u user@zcs.dev:<password> "https://192.168.56.106:8443/home/user@zcs.dev/inbox/Spaced%20Folder?fmt=json" | python -mjson.tool

Code: Select all

{
    "m": [
        {
            "cid": "260",
            "d": 1503600676000,
            "e": [
                {
                    "a": "user@zcs.dev",
                    "d": "user",
                    "p": "user",
                    "t": "t"
                },
                {
                    "a": "user@zcs.dev",
                    "d": "user",
                    "t": "f"
                }
            ],
            "fr": "How are you doing? Are you ready for Hurricane Harvey? -travis",
            "id": "259",
            "l": "261",
            "rev": 7,
            "s": 2415,
            "su": "This is a message"
        }
    ]
}
User avatar
seth.stenzel
Posts: 3
Joined: Sat Aug 19, 2017 8:44 pm

Re: Accessing Subfolders with spaces via REST API

Postby seth.stenzel » Wed Sep 13, 2017 4:07 pm

So what I found out is that this "&query=is:unread" is the difference between success and failure for me.

My zimbra version is: Zimbra 8.6.0_GA_1200 (build 20160606111426)

So basically if I try and query unread objects inside a folder with a space in the name, it fails. If it does not have a space it works.
Now I can query the folder without the query option, and then just parse the json response, which is what I ended up doing.

Maybe someone else could try and verify the error and it could be reported as a bug.
User avatar
tmclane
Zimbra Employee
Zimbra Employee
Posts: 4
Joined: Thu May 04, 2017 7:10 pm

Re: Accessing Subfolders with spaces via REST API

Postby tmclane » Wed Sep 13, 2017 5:32 pm

Would you please check and see what Nginx sees as the URL when you make a failing request?
User avatar
seth.stenzel
Posts: 3
Joined: Sat Aug 19, 2017 8:44 pm

Re: Accessing Subfolders with spaces via REST API

Postby seth.stenzel » Wed Sep 13, 2017 8:23 pm

Unfortunately as I have a working work around I'm not going to spend further time on the matter, if it is just me and my / our env that is fine. I'm not Ops and I don't have access to the host server/s. I'm just an emp tasked with putting together an email web monitoring dashboard and needed the rest API to work :P. Manually parsing the json response on the folder for the 'u' flag of an unread email is trivial and is fine for me. Maybe if someone else has this issue later they can do as you mention and see if they get the same result.

Thank you for your responses and suggestions however I appreciate it.
User avatar
tmclane
Zimbra Employee
Zimbra Employee
Posts: 4
Joined: Thu May 04, 2017 7:10 pm

Re: Accessing Subfolders with spaces via REST API

Postby tmclane » Wed Sep 13, 2017 8:26 pm

Ok. Glad you found something that worked for you!

Return to “Developers”

Who is online

Users browsing this forum: No registered users and 4 guests