1

I am using SharePoint 2013 REST API. I have multiple fields that I would like to $expand. It works when I put the following endpoint in the address bar

_api/web/lists/getbyTitle('Project')/items?$select=ChiefEngineerInfo/EMail,AssistantChief/EMail&$expand=AssistantChief/Id&$expand=ChiefEngineerInfo/Id&$filter=Project_x0020_Number eq '402-I-001'

It does not work in my code.

        var endPointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbyTitle('Project')/items?$select=ChiefEngineerInfo/EMail,AssistantChief/EMail&$expand=AssistantChief/Id&$expand=ChiefEngineerInfo/Id$filter=Project_x0020_Number eq '"+projNum+"'";

    jQuery.ajax({ 
        url: endPointUrl, 
        type: "GET", 
        headers: { "Accept": "application/json; odata=verbose" }, 
        success: function (data) {
        console.log(data);
            detailComplete(data); // Returns JSON collection of the results
        }, 
        error: function (err) { 
            console.log("Error Occured:" + JSON.stringify(err)); 
        }    
    });

I get the following error:

Error Occured:{"readyState":4,"responseText":"{\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.InvalidClientQueryException\",\"message\":{\"lang\":\"en-US\",\"value\":\"The expression \\"AssistantChief/Id,ChiefEngineerInfo/Id$filter=Project_x0020_Number eq '402-CSI-001'\\" is not valid.\"}}}","responseJSON":{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The expression \"AssistantChief/Id,ChiefEngineerInfo/Id$filter=Project_x0020_Number eq '402-I-001'\" is not valid."}}},"status":400,"statusText":"Bad Request"}

3

You have multiple $expand keyword, separate it out using comma.

$expand=AssistantChief/Id,ChiefEngineerInfo/Id

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.