0

i am getting invalid error on the below error. I couldnt make out what the error was.

   url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('Mega Menu')/items?$select=Sub_x0020_Heading$filter=(Main_x0020_Heading eq " + heading + ")",

Error

{"readyState":4,"responseText":"{\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.InvalidClientQueryException\",\"message\":{\"lang\":\"en-US\",\"value\":\"The expression \\\"Sub_x0020_Heading$filter=(Main_x0020_Heading eq INFORMATION TECHNOLOGY)\\\" is not valid.\"}}}","responseJSON":{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The expression \"Sub_x0020_Heading$filter=(Main_x0020_Heading eq INFORMATION TECHNOLOGY)\" is not valid."}}},"status":400,"statusText":"error"}
  • it will be helpful if u provide the error details here. and did u tried in your browser with this rest uri. – Md. Tahmidul Abedin Mar 21 '18 at 5:05
  • Updated as advised. – Rinu Mar 21 '18 at 5:20
  • 1
    Try like this in $filter=(Main_x0020_Heading eq '" + heading + "') – little_big_thoughts Mar 21 '18 at 5:30
3

You are missing the ampersand(&) before filter operator.

Modify it as below:

url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('Mega Menu')/items?
$select=Sub_x0020_Heading&$filter=(Main_x0020_Heading eq " + heading + ")",
  • almost i got the output except one main heading field has 'CONTRACTS & LEGAL'. I think the & is making the issue. is there any way to get over it. – Rinu Mar 21 '18 at 5:36
  • 1
    Modify it as &$filter=(Main_x0020_Heading eq " + encodeURIComponent(heading) + ")", and check – Gautam Sheth Mar 21 '18 at 5:40
  • that solves the problem. if its not too much. i need to order it with a field "Sub Heading Order" can you advise how to? – Rinu Mar 21 '18 at 5:43
  • Cheers, happy to help :) , you can accept it as answer( by ticking the checkmark) so that it wont show up for us in the unanswered section and optionally upvote it ! – Gautam Sheth Mar 21 '18 at 5:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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