Accessing Subfolders with spaces via REST API

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

Accessing Subfolders with spaces via REST API

Post by seth.stenzel »

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
Posts: 4
Joined: Thu May 04, 2017 7:10 pm

Re: Accessing Subfolders with spaces via REST API

Post by tmclane »

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

Post by seth.stenzel »

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
Posts: 4
Joined: Thu May 04, 2017 7:10 pm

Re: Accessing Subfolders with spaces via REST API

Post by tmclane »

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

Post by seth.stenzel »

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
Posts: 4
Joined: Thu May 04, 2017 7:10 pm

Re: Accessing Subfolders with spaces via REST API

Post by tmclane »

Ok. Glad you found something that worked for you!
ronhill
Posts: 2
Joined: Mon Dec 17, 2018 8:32 pm

Re: Accessing Subfolders with spaces via REST API

Post by ronhill »

I know this is an older thread, but I found it when trying to access 'Contacts' folders which contain spaces using the REST API and the 'query' keyword option. I have confirmed that a folder without spaces will correctly honor the 'query' keyword, but a folder with spaces will not. Browser responds as

HTTP ERROR 404
Problem accessing /service/home/ronaldh/contacts/SD%20Employees. Reason:
no such item

It does honor the 'fmt' keyword when the folder name contains spaces.

Following is as recorded in the access log ...

Code: Select all

[30/Apr/2020:15:35:37 +0000] "GET https://localhost:7070/service/home/myaccount/contacts/Testing?query=Hill HTTP/1.0" 200 821 "-" "Mozilla/5.0" 172

[30/Apr/2020:15:36:08 +0000] "GET https://localhost:7070/service/home/myaccount/contacts/Test%20Employees?query=Hill HTTP/1.0" 404 282 "-" "Mozilla/5.0" 3

[30/Apr/2020:15:36:46 +0000] "GET https://localhost:7070/service/home/myaccount/contacts/Test%20Employees?fmt=json HTTP/1.0" 200 2047 "-" "Mozilla/5.0" 5
Version: 8.8.10_GA_3801.FOSS

Any assistance would be appreciated.
Thank you!
Damini Vashishtha
Zimbra Employee
Zimbra Employee
Posts: 32
Joined: Tue Oct 18, 2022 12:16 pm

Re: Accessing Subfolders with spaces via REST API

Post by Damini Vashishtha »

Here is an example to access subfolder having space in its name like test1 under inbox


Code: Select all

https://servername/home/username/inbox%2Ftest%201?fmt=json
Last edited by Damini Vashishtha on Fri May 05, 2023 4:26 pm, edited 2 times in total.
Post Reply