0

I'm trying to get itens from different subsites but in the same site (it would be nice to know the method to different sites too, if possible) and when I try to do the same way when I do in same site it just doesnt work returning: (400) Invalid request.

Is it possible?

The way I do is:

POST https://contoso.sharepoint.com/sites/masterSite/_api/$batch

{"Content-Type":"multipart/mixed; boundary=c1e13017-60ac-406f-8268-cdbc586af720; charset=utf-8","Expect":"100-continue","Host":"https://contoso.sharepoint.com"}

--c1e13017-60ac-406f-8268-cdbc586af720
Accept: application/json
Content-Type: application/http
Content-Transfer-Encoding: binary

GET https://contoso.sharepoint.com/sites/masterSite/_api/web/lists/anyList1List/items HTTP/1.1
Accept: application/json;odata=nometadata

--c1e13017-60ac-406f-8268-cdbc586af720
Accept: application/json
Content-Type: application/http
Content-Transfer-Encoding: binary

GET https://contoso.sharepoint.com/sites/masterSite/_api/web/lists/anyList2List/items HTTP/1.1
Accept: application/json;odata=nometadata

The output:

{
  "$content-type": "multipart/mixed; boundary=batchresponse_fc6eee30-36b4-4303-88af-a8498561bbea",
  "$content": "base64encodebody...==",
  "$multipart": [
    {
      "headers": {
        "Content-Type": "application/http",
        "Content-Transfer-Encoding": "binary"
      },
      "body": {
        "$content-type": "application/http; msgtype=response",
        "$content": "base64encodebody...==",
        "$applicationHttp": {
          "headers": {},
          "body": {
            "value": [
              {
                "Id": 1,
                "Title": "Item #1",
                "...": "others properties hidden for readable content..."
              },
              {
                "Id": 2,
                "Title": "Item #2",
                "...": "others properties hidden for readable content..."
              },
            ]
          },
          "statusCode": 200
        }
      }
    },
    {
      "headers": {
        "Content-Type": "application/http",
        "Content-Transfer-Encoding": "binary"
      },
      "body": {
        "$content-type": "application/http; msgtype=response",
        "$content": "base64encodebody...==",
        "$applicationHttp": {
          "headers": {},
          "body": {
            "value": [
              {
                "Id": 1,
                "Title": "Item #1",
                "...": "others properties hidden for readable content..."
              },
              {
                "Id": 2,
                "Title": "Item #2",
                "...": "others properties hidden for readable content..."
              },
            ]
          },
          "statusCode": 200
        }
      }
    }
  ]
}

But when I do:

POST https://contoso.sharepoint.com/sites/masterSite/_api/$batch

{"Content-Type":"multipart/mixed; boundary=c1e13017-60ac-406f-8268-cdbc586af720; charset=utf-8","Expect":"100-continue","Host":"https://contoso.sharepoint.com"}

--c1e13017-60ac-406f-8268-cdbc586af720
Accept: application/json
Content-Type: application/http
Content-Transfer-Encoding: binary

GET https://contoso.sharepoint.com/sites/masterSite/SubSite1/_api/web/lists/anySubSiteList1List/items HTTP/1.1
Accept: application/json;odata=nometadata

--c1e13017-60ac-406f-8268-cdbc586af720
Accept: application/json
Content-Type: application/http
Content-Transfer-Encoding: binary

GET https://contoso.sharepoint.com/sites/masterSite/SubSite2/_api/web/lists/anySubSiteList2List/items HTTP/1.1
Accept: application/json;odata=nometadata

The output ("Solicitação inválida" = "Invalid request"):

{
  "$content-type": "multipart/mixed; boundary=batchresponse_307c09a8-1bfc-4ccb-a60a-d6aa31e6a863",
  "$content": "base64==",
  "$multipart": [
    {
      "headers": {
        "Content-Type": "application/http",
        "Content-Transfer-Encoding": "binary"
      },
      "body": {
        "$content-type": "application/http; msgtype=response",
        "$content": "base64=",
        "$applicationHttp": {
          "headers": {},
          "body": {
            "error": {
              "code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
              "message": {
                "lang": "pt-BR",
                "value": "Solicitação inválida."
              }
            }
          },
          "statusCode": 400
        }
      }
    },
    {
      "headers": {
        "Content-Type": "application/http",
        "Content-Transfer-Encoding": "binary"
      },
      "body": {
        "$content-type": "application/http; msgtype=response",
        "$content": "base64=",
        "$applicationHttp": {
          "headers": {},
          "body": {
            "error": {
              "code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
              "message": {
                "lang": "pt-BR",
                "value": "Solicitação inválida."
              }
            }
          },
          "statusCode": 400
        }
      }
    }
  ]
}

Thanks a lot!

1 Answer 1

0

Can't find it in official docs for SP REST API or OData protocol, but in according to the PnP JS docs, it is not. It seems search is the only way to do it in single request.

Your Answer

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

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