2

I'am trying to get calendar items and filtering by EventDate and EndDate fields using rest api. DateTime field filtering works fine on other lists but I can not filter calendar items by EventDate and EndDate. Exact same issue with this.

At powershell I'm getting this error when I try to filter by EventDate field

Invoke-RestMethod : The remote server returned an error: (400) Bad Request.

Is there anybody know how to solve this without using ListData.svc?

This works great

$restUrl="http://www.myspportal.com/sites/Dev/_api/web/lists/getbytitle('RestTestCalendar')/items?`$select=*&`$filter=Title eq 'test'"
$response=Invoke-RestMethod -Uri $restUrl -Method Get -UseDefaultCredentials -Headers @{ "Accept" = "application/json;odata=verbose" } 
$response=$response -creplace '"ID":','"ListItemID":' 
$items = $response| ConvertFrom-Json
foreach($item in $items.d.results)
{
write-host "Title `t-->" $item.Title
}

but this is not working

$restUrl="http://www.myspportal.com/sites/Dev/_api/web/lists/getbytitle('RestTestCalendar')/items?`$select=*&`$filter=Title eq 'test' or EventDate eq datetime'2018-05-09T09:00:00Z'"
$response=Invoke-RestMethod -Uri $restUrl -Method Get -UseDefaultCredentials -Headers @{ "Accept" = "application/json;odata=verbose" } 
$response=$response -creplace '"ID":','"ListItemID":' 
$items = $response| ConvertFrom-Json
foreach($item in $items.d.results)
{
write-host "Title `t-->" $item.Title
}

Getting this error

enter image description here

Also logs say this

The field 'EventDate' of type 'DateTime' cannot be used in the query filter expression
8

2 Answers 2

2

Use SharePoint Manager to verify the value for the EventDate ("Start Time") field and check its Filterable property is set to false, and this is what is causing the error message to be returned.

Create a DateTime column from scratch and named it "Testdate" and it should work:

  http://www.myspportal.com/sites/Dev/_api/web/lists/getbytitle('RestTestCalendar')/items?$select=*&$filter=Testdate eq datetime'2018-05-09T09:00:00Z'
0

Try this: (notice StartTime is used instead of EventDate)

function getEntries() {
    var call = $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_vti_bin/ListData.svc/Calendar?$select=Id,Title,StartTime,EndTime&$filter=StartTime ge datetime'2018-07-01'",
        type: "GET",
        dataType: "json",
        headers: {
            Accept: "application/json;odata=verbose"
        }
    });
    call.success(function(data, textStatus, jqXHR) {
        $("#ResultsDiv").empty();
        for (var i = 0; i < data.d.results.length; i++) {
            var item = data.d.results[i];
            $("#ResultsDiv").append(item.Title + "<br/>" + item.StartTime + "<br/><br/>");
        }
    });
    call.fail(function(jqXHR, textStatus, errorThrown) {
        alert("Error retrieving items: " + jqXHR.responseText);
    });
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.