spfx property bag

Aniruddha Aditya 316 Reputation points
2021-01-08T11:30:23.75+00:00

Hi,

I have created a custom property bag key-value pair using PnP and now I am trying to access it as a "READER" in my spfx solution.

The first question is. Can an spfx access the value with a "Reader's" context.
The second Question is. I have been drilling for some code snippet but didn't get any for spfx.

Thanks for your continued support

Microsoft 365 and Office | SharePoint | For business | Windows
{count} votes

Accepted answer
  1. MichaelHan-MSFT 18,126 Reputation points
    2021-01-11T07:32:01.55+00:00

    Hi @Aniruddha Aditya ,

    We could access the custom property bag key-value with the rest api /_api/web/allProperties.

    55194-image.png

    So as a READER, you could fetch Key-Value pair from site property bag in SPFX. Below is my demo code snippet:

    import { SPHttpClient, SPHttpClientConfiguration, SPHttpClientResponse, ODataVersion, ISPHttpClientConfiguration } from '@microsoft/sp-http';  
        const spHttpClient: SPHttpClient = this.context.spHttpClient;  
        const currentWebUrl: string = this.context.pageContext.web.absoluteUrl;  
          
        //GET current web info  
        spHttpClient.get(`${currentWebUrl}/_api/web/allProperties`, SPHttpClient.configurations.v1).then((response: SPHttpClientResponse) => {  
          
            response.json().then((PropertyValues: any) => {  
          
                console.log(PropertyValues);  
            });  
        });  
    

    55076-image.png


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.