Pnpjs: syntax error: Unexpected token < in JSON at position 0

Created on 11 Nov 2018  路  3Comments  路  Source: pnp/pnpjs

Category : Question

I am using SharePoint 2013 On-Premise. I have written following code to get web title and description:

pnp.setup({
            headers: {
                "Accept": "application/json; odata=verbose",
            }
        });

pnp.sp.web.select("Title").get()
      .then(function (data) {
           if (data.d != undefined) {
               console.log(data.d);
            }
     });

But I am getting following error:

syntax error: Unexpected token < in JSON at position 0

Are we missing something here? we did gone through this issue and tried the solution never worked
https://github.com/SharePoint/PnP-JS-Core/issues/186

documentation answered question

Most helpful comment

Hi @muraray,

Yes, you're missing one thing actually. Please check the docs article.

TL;DR:

sp.setup({
  sp: { // < this is missed
    headers: {
      "Accept": "application/json; odata=verbose",
    }
  }
});

so you end up with default application/json; odata=minimalmetadata instead.

A difference here is that PnPjs in compare to PnP-JS-Core supports not only SP REST but Microsoft Graph API for example.

All 3 comments

Hi @muraray,

Yes, you're missing one thing actually. Please check the docs article.

TL;DR:

sp.setup({
  sp: { // < this is missed
    headers: {
      "Accept": "application/json; odata=verbose",
    }
  }
});

so you end up with default application/json; odata=minimalmetadata instead.

A difference here is that PnPjs in compare to PnP-JS-Core supports not only SP REST but Microsoft Graph API for example.

Going to close this as answered and documented. If you need additional assistance, please _reopen_ the issue or open another. Thanks!

Hi @muraray,

Yes, you're missing one thing actually. Please check the docs article.

TL;DR:

sp.setup({
  sp: { // < this is missed
    headers: {
      "Accept": "application/json; odata=verbose",
    }
  }
});

so you end up with default application/json; odata=minimalmetadata instead.

A difference here is that PnPjs in compare to PnP-JS-Core supports not only SP REST but Microsoft Graph API for example.

Thanks a ton for guiding me...

Yes, i found the way back after checking the document...

another question, Is there any other way we can get the parent site absoulte url without using the SPHostUrl and SPAppWebUrl querystings? (currently i'm so dependent on these querystrings)

All my data are present in parent site. I found from the documentation that we could use the config the baseUrl during the pnp setup properties but i don't want to hardcoding strings as baseUrl properties.

Any suggestions please.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

un-dres picture un-dres  路  3Comments

DennisGaida picture DennisGaida  路  3Comments

simkessy picture simkessy  路  3Comments

drewcook picture drewcook  路  3Comments

KieranDaviesV picture KieranDaviesV  路  3Comments