How to search using the Citrix ShareFile API

故事扮演 提交于 2019-12-10 09:53:58

问题


I am using the Sharefile REST API for a project and have run into an issue. Their documentation is lacking and so far my 5 emails to the api@ address have gone unanswered. Figured I would crowdsource this one...

What I need to do is search for a file by its name and it also has to have a specific parentID. I am following their documentation as best I can, but I still get a 500 error on the response.

According to their API documentation I have to post to: https://account.sf-api.com/sf/v3/Items/AdvancedSimpleSearch with the following post:

{ 
    "Query":{ 
        "AuthID":"", 
        "ItemType":"", 
        "ParentID":"", 
        "CreatorID":"", 
        "LuceneQuery":"", 
        "SearchQuery":"", 
        "CreateStartDate":"", 
        "CreateEndDate":"", 
        "ItemNameOnly":"", 
    }, 
    "Paging":{ 
        "Key":"", 
        "PageNumber":1, 
        "PageSize":10, 
    }, 
    "Sort":{ 
        "SortBy":"", 
        "Ascending":false, 
    }, 
    "TimeoutInSeconds":10 
} 

The JSON post I am sending looks like this:

{
    "Query": {
        "AuthID": "",
        "ItemType": "",
        "ParentID": "xxxxxxxxxxxx",
        "CreatorID": "",
        "LuceneQuery": "",
        "SearchQuery": "filename ='foo.png'",
        "CreateStartDate": "4/2/2014",
        "CreateEndDate": "4/4/2014",
        "ItemNameOnly": ""
    },
    "Paging": {
        "Key": "",
        "PageNumber": 1,
        "PageSize": 10
    },
    "Sort": {
        "SortBy": "",
            "Ascending": false
        },
    "TimeoutInSeconds": 10
}

They prefilled some properties in their example post so I replicated. I did also try sending only what I needed too (instead of the blank properties) but still get a 500.

I can upload files, delete, modify, etc all fine with no issues so I am certain it is something in this JSON structure. I think it comes down to the "SearchQuery" property. There is zero examples on their documentation site, and any libraries that were made 3rd party only show a "query" parameter being passed in with no example of what that looks like...


回答1:


Try This:

    {
    "Query": {
        "AuthID": "",
        "ItemType": "",
        "ParentID": "xxxxxxxxxxxx",
        "CreatorID": "",
        "LuceneQuery": "",
        "SearchQuery": "foo.png",
        "CreateStartDate": "4/2/2014",
        "CreateEndDate": "4/4/2014",
        "ItemNameOnly": ""
    },
    "Paging": {
        "Key": "",
        "PageNumber": 1,
        "PageSize": 10
    },
    "Sort": {
        "SortBy": "",
            "Ascending": false
        },
    "TimeoutInSeconds": 10
}

In searchQuery we have to specify item name itself instead of filename='itemname'. Working for me :)




回答2:


I've been trying to wrestle with this too. I am using the HTTPS API and not the REST API, but maybe the same argument will work? My client has specified PHP so looking at Sharefile's PHP sample code sharefile.php - you will see a search function with a "$query" parameter. After a few attempts I tried supplying this argument: '{Name="Agreements"}'. I think you might be able to generalize to more complicated searches. The PHP sample code does a http_build_query to convert the above to the usual HTML parameter string.



来源:https://stackoverflow.com/questions/22846887/how-to-search-using-the-citrix-sharefile-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!