question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sp-pnp-js batch requests failing with 400: Bad Request

See original GitHub issue

Hi,

I am building an Angular 5 application using sp-rest-proxy for local development. I am getting a 400 bad Request when trying to do a batch request using sp-pnp-js.

SharePoint Version : SharePoint Online sp-rest-proxy : latest sp-pnp-js: 3.0.4

const batch = pnp.sp.createBatch();
    array.forEach(element => {
      web.lists.getByTitle('ListName').items(element.Id).inBatch(batch).get()
        .then(data => console.log(data))
        .catch(error => console.log(error));
    });
    batch.execute().then(() => {
      console.log('All is well');
    });

Error:

Error: Error making HttpClient request in queryable: [400] Bad Request
    at new ProcessHttpClientResponseException (exceptions.js:24)
    at eval (core.js:33)
    at ZoneDelegate.invoke (zone.js:388)
    at Object.onInvoke (core.js:4745)
    at ZoneDelegate.invoke (zone.js:387)
    at Zone.run (zone.js:138)
    at eval (zone.js:858)
    at ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:4736)
    at ZoneDelegate.invokeTask (zone.js:420)

Please let me know if you need any additional information. Thank you for your great work!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Feb 28, 2018

Changing the baseSiteUrl did the trick @koltyakov . I always used just the localhost:8080 and it worked well for single requests. I assumed that since we already specify the sharepoint site url when starting the proxy, all subsequent requests will be based off of that url. Thank you for the great work.

0reactions
koltyakovcommented, Feb 28, 2018

Oh, ok. Just wanted to be sure that batches are not misused.

environment.baseSiteUrl = 'http://localhost:8080/sites/goalsdev/2018' // local development

Would be correct for sure.

Proxy resolves / as siteUrl from settings in ordinary requests. But in multipart bodies we should be more strict. And I always recommend using same paths structure.

That’s why this import { loadPageContext } from 'sp-rest-proxy/dist/utils/env'; helper was created. The helper experts that WebpackDevServer is targeted it’s proxy to sp-proxy as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error-Handling - PnP/PnPjs
All errors resulting from executed web requests will be returned as an HttpRequestError object which extends the base Error . In addition to...
Read more >
Updating sharepoint list items with batch pnp, in bad request
But the items are never updated, and all I get is. Error: Error making HttpClient request in queryable: [400] Bad Request. Image of...
Read more >
Send an HTTP Requet to SharePoint 400 Bad Request Error
Solved: I am trying to follow the example at the following link to build a flow for PowerApps to clear a person field...
Read more >
SharePoint Online: Perform Bulk Operations (Add/Update ...
The PnP Batch operations are accelerated and relatively reduce ... Here, instead of sending each request directly to the SharePoint Online ...
Read more >
SharePoint Online – Markus Moeller's SharePoint Blog
npm install @pnp/sp --save. And inside the base web part class PnPJS needs to be initialized with the SharePoint context: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found