Saturday, February 6, 2021

Postman : Add item to SharePoint from postman using SharePoint REST api

Postman : Add item to SharePoint from postman using SharePoint REST api (Can be used to add/update items in SharePoint from external application through REST api)

 Problem statement : Leverage Postman desktop or chrome extension to make SharePoint REST api calls to add/update items in SharePoint online site


There are many articles available in internet to make READ type calls from Postman . I am not going to detail out all the basic steps to configure the Postman , rather I will be focusing on the information required to make the ADD/UPDATE type of REST api calls.

Note: I am using Postman desktop application , but you can do the same through Postman Google chrome extension as well . Postman desktop client


Step-1 : Configure app permission in SharePoint Register add-in

Step-2 : Retrieve tenant ID

Step-3 : Retrieve access token 

Step-4 : Connect SharePoint REST api to perform READ operations 

For Step 1 through 4 , I suggest this article which consists of all the details 

Additional reference article 

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/authorization-and-authentication-of-sharepoint-add-ins

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-rest-endpoints


When you are confident that you are able to perform READ operations through Postman per above details , you are good to make next step to make Add/update operations , make below changes to ADD/UPDATE items in SharePoint list/libraries 


App registration 

While you register your app and provide permission level , make sure you are providing Write/Manage/FullControl types of access level , Refer to link App access level .

In my case I was trying to add a new item to SharePoint online list , I opted for below permission level , but you can provide minimum required permission as well 

<AppPermissionRequests AllowAppOnlyPolicy="true">

    <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/" Right="FullControl" />

</AppPermissionRequests>


Follow above process with new client ID and secret to record below items 

  1. Tenant ID (Bearer realm)
  2. ResourceID
  3. Client ID 
  4. Client Secret 
With all this info , as earlier make call to below REST api to retrieve access token

https://accounts.accesscontrol.windows.net/<TenantID>/tokens/OAuth/2

Copy "access_token" from the response


Next step is to try make a Write/Update type REST api call , In my case I wanted to try below REST API call to
add item to SPO list

POST https://{site_url}/_api/web/lists/GetByTitle('Test')/items Authorization: "Bearer " + accessToken Accept: "application/json;odata=verbose" Content-Type: "application/json;odata=verbose" Content-Length: {length of request body as integer} X-RequestDigest: "{form_digest_value}" { "__metadata": { "type": "SP.Data.TestListItem" }, "Title": "Test" }


As you can see we need 2 items highlighted in yellow to make this call
  1. Form digest value
  2. ListItemEntityTypeFullName - This is different for each list/Library
Retrieve "Form digest value"

We can use Postman to retrieve form digest value through below REST api call - Reference Link

https://SiteCollection/_api/contextinfo

In the header for this call you need to include

  • Accept - application/json;odata=verbose
  • Authorization - Bearer "Access token value"
Save the form digest value you receive in property " "FormDigestValue"

Retrieve "ListItemEntityTypeFullName "

Make another call as below to retrieve ListItemEntityTypeFullName 

https://SitecollectionURL/_api/web/lists/GetByTitle('ThiloshList')?$select=ListItemEntityTypeFullName

You should see a response as below , copy the value 

{
    "ListItemEntityTypeFullName""SP.Data.ThiloshListListItem"
}


Make SharePoint REST api call to add item to SharePoint Online list 


Make REST api  POST call to 

https://SiteCollectionURL/_api/web/lists/GetByTitle('ThiloshList')/items

With below parameter in header

  1. Accept - application/json;odata=nometadata
  2. Authorization - Berer [access token]
  3. X-RequestDigest - [Form digest value previously copied]
  4. Content-Type - application/json;odata=verbose

In the Body , copy below JSON 

{
  "__metadata": {
    "type""SP.Data.ThiloshListListItem"
  },
  "Title""Test"
}

This will
  1. Authenticate the application
  2. Add the "test" item into "ThiloshList" SharePoint Online list


You can use same process to make any other ADD/Update SharePoint REST api calls.






Thursday, January 16, 2020

Issue in installing "yo" (yeoman" module/package globally through npm - nodeJs


I was trying to update/reinstall "yo" module through npm commands and it was throwing below error message

Error: Cannot find module 'request'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\THINAG\yo\node_modules\duplexer2\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\THINAG\yo\node_modules\har-validator\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\THINAG\yo\node_modules\request\package.json'

npm ERR! Failed at the yo@0.0.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
verbose enoent This is related to npm not being able to find a file.





I was not able to find any solution in internet , after a bit a struggle , trial and error I was able to find a solution .

Issue was that , I had a previous version of yo installed in the same machine some time last week , even though you use below command to uninstall the yo module from npm , it was not cleaning up all the directory from the machine .

npm uninstall -g yo

Below steps fixed the issue

1)Uninstall the existing yo module

          npm uninstall -g yo

2)Make sure it is cleaned up by running 
     npm list -g --depth=0
3) Clean the folder with name "yo" or any file which belong to yomen
at  C:\Users\THINAG(This is my directory , you can change accordingly"
at C:\Users\THINAG\AppData\Roaming\npm\node_modules
4)Run below command in npm
    npm cache clean -f 
5)Try installing the module again
    npm install -g yo

while you run npm list -g --depth=0  it should not return any error .
















Tuesday, December 18, 2018

SharePoint upgrade missing feature reference issue

While I tried to migrated the SharePoint 2010 Data base to SharePoint 2016 through the database upgrade approach , I received the below missing feature error

Database [database] has reference(s) to a missing feature: Name = [PowerPivot Feature 
                  Integration for Site Collections], Id = [1a33a234-b4a4-4fc6-96c2-8bdb56388bd5

usually if you follow this blog Link, you should be able to clean up the missing feature , if not by using the feature admin tool you should be able to clean up the faulty feature at the source . But in this case neither worked . SharePoint 2010 was not showing that this feature was activated , but the upgrade was failing in SharePoint 2013/2016 .

Hence i decide to do some digging myself  in SQL and try to resolve the issue , below are the steps followed to resolve the issue




1.      Open SSMS in source (SharePoint 2010 /2013), run the below script to find the tables in DB where the missing feature is referenced

USE [Name of the DB]
GO
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%FeatureId%'
ORDER BY schema_name, table_name;

2.      Query result would provide the list of tables in SQL

table_name        schema_name   column_name
AllLists                  dbo                       tp_FeatureId
CustomActions   dbo                       FeatureId
Features              dbo                       FeatureId
FeatureTracking dbo                      FeatureId

3.      Open up each table in SQL and identify the row as per sample query

Select * from [data base name].[dbo].[tablename] where tp_featureID = ‘guid of missing feature’

Results would provide the webID of the website

4.      Open up any of the SharePoint server in the farm and execute the below query , this would list all the site and webs with the ID
5       
Get-SPWebApplication http://sharepoint.dev.symetra.com/ | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select Title, URL, ID, ParentWebID | Export-CSV C:\InfoArch.csv –NoTypeInformation

6.      Navigate to the website and clean up the component which is referred by the feature .

I In my case there was a faulty power pivot library at SharePoint 2010 , I went ahead and cleaned up the library at 2010

Thursday, December 13, 2018

Sharepoint 2016 User profile sync unable to update manager field



I was migrating a User profile from SharePoint 2010 to SharePoint 2013 and then to SharePoint 2016 . During the process of migration I did decide to leave out the sync and social DB , as we wanted the   new social features available in SharePoint 2016 and we decided not having to migrate the social and sync DB from SharePoint 2010 would be a cleaner approach .

As per the Microsoft article I did migrate the User profile DB and the MySite DB through Data base upgrade process. Everything did migrate all fine and I did opt for "Active Directory Import" to configure the new Sync in SharePoint 2016 . I was able to create a custom property to import the "Employee ID " from AD and post completion of Full sync ,I was able to see the Employee ID property in user's profile .

Strangely I noticed that the manager field was not being updated , yes it did have the old values carried over from SharePoint 2010 , but if the manager field was updated in AD , it was not being synced to SharePoint . Did restart the service and triggered full sync of user profile on few occasion , but this did not resolve the issue .

But below steps finally synced the manager field from AD to SharePoint 2016 .


  1. Clicked "Configure Synchronization Settings" in central admin of SharePoint 2016
  2. Since I had configured the "  Active Directory Import " to sync the data from AD , this option was selected .
  3. Select the "Enable External Identity Manager" 
  4. click OK
  5. Now get back to the same screen ""Configure Synchronization Settings"
  6. But this time select the right setting "Use SharePoint Active Directory Import"
  7. Click OK
  8. Trigger the "Full Sync"

This resolved the issue and manager field for all the users were updated .

Note : Manager property should not be configured with any import filed in "Manage User Property" this field has to be kept blank , only then the SharePoint 2016 would sync  the data from AD .

Previously in SharePoint 2010 , you had to map the SharePoint "manager" user property with "manager" field in "Property mapping for synchronization"

Friday, September 21, 2018

SharePoint 2010 to SharePoint 2016 MySite blog migration issue



While we were trying to migrate the User profile DB along with the Mysite from SharePoint 2010 to SharePoint 2016 by having a hop at SharePoint 2013 , we faced the below issue

It worked all fine in SharePoint 2013 , but had some issue in SharePoint 2016

Web Part Error: A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe

On closer look at the web.config and logs , I found that the entries were missing for 14.0.0.0 version in Sharepoint 2016 , fix was to add below entries in web.config file which was hosting the Mysite webapplication

<SafeControl Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebPartPages" TypeName="BlogAdminWebPart" Safe="True" SafeAgainstScript="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebPartPages" TypeName="BlogLinksWebPart" Safe="True" SafeAgainstScript="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebPartPages" TypeName="BlogMonthQuickLaunch" Safe="True" SafeAgainstScript="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebPartPages" TypeName="BlogYearArchive" Safe="True" SafeAgainstScript="True" />

Issue seems to be either the upgrade had failed in SharePoint 2013 or SharePoint 2016 , hence failed to upgrade the default webpart for blogs , or MS forgot to update their webconfig file