在线Sharepoint-Rest API筛选器不起作用

时间:2019-02-14 14:43:43

标签: rest sharepoint office365 sharepoint-online

我正在尝试使用过滤器参数发出REST API请求。我的网址在浏览器中工作正常,但在JS请求中却没有。

https://xxxx.sharepoint.com/sites/myTestPage/_api/web/lists/getbytitle('ListDemo')/ Items?$ top = 200&$ select = State

任何能满足条件的参数,任何人都可以帮我。

下面是我用来测试和执行JS文件相同步骤的Powershell脚本:

$url = "https://xxxx.sharepoint.com/sites/myTestPage/_api/web/lists/getbytitle('ListDemo')/Items?$top=200&$select=State"
$headers = @{}      
$headers.Add("Authorization","Bearer " + $bearerCode)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
$headers.Add("accept","application/json; odata=minimalmetadata")
#$headers.Add("content-type","application/json;odata=verbose")
$headers.Add("content-type","application/json;odata=minimalmetadata")
$headers.Add("Control-Allow-Origin","https://xxxx.sharepoint.com")
$headers.Add("Origin","https://xxxx.sharepoint.com")

$response = Invoke-WebRequest -Uri $url -Method GET -Header $headers
Write-host $response.RawContent

1 个答案:

答案 0 :(得分:0)

在我的JS请求上,URL处于以下位置:$ filter = City eq'DC',但必须将字符'编码为%27,并以相同的方式对字符之前和之后所需的空格(%20)字符进行编码比较命令,在我的情况下为“例如”。

因此,要解决此问题,正确的网址必须具有以下过滤器:$ filter = City%20eg%20%27DC%27