0
votes

I'm trying to make an REST API request using the filters parameters. My url is working fine in the browser, but in the JS request no.

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

Any of the parameters conditions works, anyone could you help me please.

Below is a powershell script that I'm using to test and make the same steps of JS file:

$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
There is no filter in the url so where is the problem? You just load up to 200 items and only one field - State. This script is working for you? You don’t have to set content-type, control-allow-origin nor origin, it is useless. Authorization and accept is just fine.Lukas Nespor
Yes, I know. I have past a simple url to everyone know that anything works for me. I had tried links as $filter=City eq 'DC'&$select=City,Campaign_x0020_Type,ContentType,Country,Audience_x0020__x002d__x0020_EX_, but it don't works too. And about the origin and content-type, it is required, because I'm doing an external access. It isn't a SharePoint pluggin.Estefano Costa
I don’t see anything wrong with the filter parameter. So in browser and PowerShell the url works fine and load correct data? You mentioned that it does not work in JS, can you share how do you call it?Lukas Nespor

1 Answers

0
votes

On my JS request the url was at this: $filter=City eq 'DC', but the character ' must to be encoded to %27 and the same approach to the space (%20) character required before and after the comparison command, in my case eg.

So, to solve this problem the right url must to have the filter as:

$filter=City%20eg%20%27DC%27