Get items of Site Pages using pnp getByTitle

%3CLINGO-SUB%20id%3D%22lingo-sub-541432%22%20slang%3D%22en-US%22%3EGet%20items%20of%20Site%20Pages%20using%20pnp%20getByTitle%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-541432%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20retrieve%20Site%20pages%20items%20by%20using%20pnp%20getByTitle%2C%20as%20shown%20below.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20let%20web%20%3D%20new%20Web%20(this.context.pageContext.web.absoluteUrl)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20web.lists.getByTitle('Site%20Pages').items.get().then(console.log)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eand%20I%20have%20established%20context%20(spfxContext%3A%20this.context%20and%20context%3A%20this.context)%20in%20the%20.ts%20File.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOn%20the%20console%20log%20I%20keep%20getting%20the%20same%20error%20every%20time%2C%20which%20is%2C%20it%20couldn%E2%80%99t%20find%20the%20list%20'Site%20Pages'.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20know%20the%20code%20works%20properly%20because%20it%20gets%20all%20the%20items%20when%20I%20tried%20it%20on%20in%20one%20of%20my%20other%20tenants.%20So%2C%20I%E2%80%99m%20guessing%20the%20problem%20lies%20somewhere%20in%20my%20tenant%20Site%20Pages%20settings.%3C%2FP%3E%3CP%3ECan%20someone%20help%20me%20with%20this%20issue%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-541432%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPnPj%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-541465%22%20slang%3D%22en-US%22%3ERe%3A%20Get%20items%20of%20Site%20Pages%20using%20pnp%20getByTitle%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-541465%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F336903%22%20target%3D%22_blank%22%3E%40amha97%3C%2FA%3E%26nbsp%3BHave%20you%20read%20this%20this%20documentation%3F%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fpnp.github.io%2Fpnpjs%2Fsp%2Fdocs%2Fitems%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fpnp.github.io%2Fpnpjs%2Fsp%2Fdocs%2Fitems%2F%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-542810%22%20slang%3D%22en-US%22%3ERe%3A%20Get%20items%20of%20Site%20Pages%20using%20pnp%20getByTitle%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-542810%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F39836%22%20target%3D%22_blank%22%3E%40Beau%20Cameron%3C%2FA%3E%26nbsp%3BYes%20I%20have%20read%20it%20and%20as%20I%20understand%20it%20this%3C%2FP%3E%3CPRE%3E%3CSPAN%20class%3D%22nx%22%3Esp%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22nx%22%3Eweb%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22nx%22%3Elists%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22nx%22%3EgetByTitle%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22s2%22%3E%22My%20List%22%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E).%3C%2FSPAN%3E%3CSPAN%20class%3D%22nx%22%3Eitems%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22nx%22%3Eget%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E().%3C%2FSPAN%3E%3CSPAN%20class%3D%22nx%22%3Ethen%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E((%3C%2FSPAN%3E%3CSPAN%20class%3D%22nx%22%3Eitems%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22kt%22%3Eany%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E%5B%5D)%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22o%22%3E%3D%26gt%3B%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22p%22%3E%7B%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22nx%22%3Econsole%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22nx%22%3Elog%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22nx%22%3Eitems%3C%2FSPAN%3E%3CSPAN%20class%3D%22p%22%3E)%3B%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22p%22%3E%7D)%3B%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3EShould%20work%20for%20%E2%80%9CSite%20Pages%E2%80%9D%20also%20and%20as%20I%20mentioned%2C%20when%20i%20tried%20the%20same%20thing%20in%20my%20other%20SharePoint%20account%20it%20did%20work%20just%20fine.%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi, 

I am trying to retrieve Site pages items by using pnp getByTitle, as shown below.

 

    let web = new Web (this.context.pageContext.web.absoluteUrl);

    web.lists.getByTitle('Site Pages').items.get().then(console.log);

 

and I have established context (spfxContext: this.context and context: this.context) in the .ts File.

 

On the console log I keep getting the same error every time, which is, it couldn’t find the list 'Site Pages'.

 

I know the code works properly because it gets all the items when I tried it on in one of my other tenants. So, I’m guessing the problem lies somewhere in my tenant Site Pages settings.

Can someone help me with this issue?

2 Replies

@amha97 Have you read this this documentation? https://pnp.github.io/pnpjs/sp/docs/items/


@Beau Cameron Yes I have read it and as I understand it this

sp.web.lists.getByTitle("My List").items.get().then((items: any[]) => {
    console.log(items);
});

Should work for “Site Pages” also and as I mentioned, when i tried the same thing in my other SharePoint account it did work just fine.