0

I've built a spfx webpart that creates a list item in a list by using the following

const client = await this.props.context.msGraphClientFactory.getClient();      
        await client         
         .api("sites/MYSITEID/lists/MYLISTID/items")
         .version("v1.0")
          .post(MYDATA, (err, res, success) => {
            if (err) {                      
              //console.error('This Error' + err);  
              return;  
            }                
            if (success)
            {
             // console.log("success");
            }           
          }) ;

It works fine in all browsers however it doesnt work in the sharepoint app. Just wondering on if anyone had any pointers on fixing this and or debugging this?

Also my Graph calls are not working within the sharepoint app i.e.

 const client =   await this.props.context.msGraphClientFactory
      .getClient();
      client.api('me')
      .version('beta')
      .get( async (error,  response: any) => {    
console.log(response);

   })
}
4
  • Are you getting any error? If Yes, please post it here. May 28 '19 at 8:58
  • thats one of the issues no error on screen - it only happens within the sharepoint app. How can I debug??
    – Lori
    May 28 '19 at 9:00
  • only thing that comes back from the me call is error has occruredTypeError: cannot read property index of underfined. basically the call was unsuccessful
    – Lori
    May 28 '19 at 9:13
  • Was looking through issues would this work? github.com/SharePoint/sp-dev-docs/issues/3665
    – Lori
    May 28 '19 at 9:56
0

This seems to have fixed the issue https://github.com/SharePoint/sp-dev-docs/issues/3665

ok, I just got confirmation that the code is enabled 100% in production. Please follow the steps below to enable rich client working with SPFx components that requires access to Web APIs: Note: you have to be Global Tenant Administrator to perform all the steps below Step 1. Visit the "Manage Permissions" Page in SharePoint Tenant Admin Step 2. Go to -> https://aad.portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredAppsPreview Step 3. Click on "SharePoint Online Client Extensibility" Web Application Principal Step 4. Click Manifest on the left menu Step 5. Copy the id from the oAuth2Permission array

"oauth2Permissions": [
{
"adminConsentDescription": "Allow the application to access SharePoint Online Client Extensibility Web Application Principal on behalf of the signed-in user.",
"adminConsentDisplayName": "Access SharePoint Online Client Extensibility Web Application Principal",
"id": "2143704b-186b-4210-b555-d03aa61823cf",
"isEnabled": true,
"lang": null,
"origin": "Application",
"type": "User",
"userConsentDescription": "Allow the application to access SharePoint Online Client Extensibility Web Application Principal on your behalf.",
"userConsentDisplayName": "Access SharePoint Online Client Extensibility Web Application Principal",
"value": "user_impersonation"
}
],

Step 6. Replace “preAuthorizedApplications” entry with the following json

"preAuthorizedApplications": [
    {
        "appId": "00000003-0000-0ff1-ce00-000000000000",
        "permissionIds": [
            "2143704b-186b-4210-b555-d03aa61823cf"
        ]
    }
],

Step 7. Hit Save.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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