Hello Everyone,
In this blog, I am going to show you some common SharePoint operations, that can be done using the REST API provided by Microsoft.
What is Azure?
“Microsoft Azure is a cloud computing platform and infrastructure, created by Microsoft, for building, deploying and managing applications and services through a global network of Microsoft-managed and Microsoft partner hosted data centers.”
What is Azure Active Directory?
“Azure Active Directory (Azure AD) is Microsoft’s multi-tenant cloud based directory and identity management service.”
What is SharePoint Online?
Simply put, “SharePoint in the cloud”. SharePoint is often used to store, track, and manage electronic documents and assets. For example, I used it to deliver some documents from ECC to the suppliers. The suppliers would have a separate work area (SPO Site) and read access for the documents shared with them.
Let me explain the common operations involved in the AAD and SPO integration with SAP PI. I have done the integration using Advantco REST adapter. You will need a bit of XML to JSON conversion knowledge in REST receiver adapter.
COMMON SHAREPOINT ONLINE OPERATIONS:
- Create SPO Site
- Update SPO Site
- Give permissions for AAD user to SPO site
- Create folder in SPO
- Upload file into SPO site
COMMON AZURE AD OPERATIONS: (Kindly wait for my next blog)
- Create AD user
- Create AD group
- Add AD user to AD group
- Remove AD user from AD group
- Update AD User / Block AD User
Let us see one by one in detail;
SPO OPERATIONS:
1. Create SPO Site: If you need to create a new SharePoint site, follow the steps below;
- Resource URL:
https://mysapdev.sharepoint.com/sites/suppliers/_api/web/webinfos/add |
- HTTP Headers:
Header Name | Header Value |
accept | application/json; odata=verbose |
content-type | application/json; odata=verbose |
Cookie | Cookie value has to be passed |
X-RequestDigest | Digest value has to be passed |
- HTTP method : POST
- SharePoint template (Not mandatory. To be created by SharePoint expert)
- Know the supported language. Eg:1033 is for English-UK
Below is the required JSON request for creating a site.
{ 'parameters': { '__metadata': {'type': 'SP.WebInfoCreationInformation'}, 'Url': 'Supplier_ABC', 'Title': 'ABC Supplier', 'Description': 'REST created web', 'Language':1033, 'WebTemplate':'{4AD5BC8A-5C4D-46E9-F390-1876AFF81CF5}', 'UseUniquePermissions':false } } |
Note: I used the GUID of the web template as the name doesn’t work during execution.
Our actual request will be an XML but, we have an option to convert the request format from XML to JSON in the REST Receiver adapter.
Likewise, we have an option to receive the response via three ways;
- Http Response body : Actual response from the REST service.
- Template : Our own template for response XML.
- Template for Empty HTTP Response body only : Our template in case of empty response from REST service.
2. Update SPO Site: If you need to update the SPO site that you created before, follow the steps below;
- Resource URL:
https://mysapdev.sharepoint.com/sites/suppliers/%SupplierSiteName%/_api/web |
The %SupplierSiteName% is the value to be replaced by the site name that we want to update.
- HTTP Headers:
Header Name | Header Value |
X-HTTP-Method | MERGE |
content-type | application/json; odata=verbose |
Cookie | Cookie value has to be passed |
X-RequestDigest | Digest value has to be passed |
- HTTP method : POST
- " X-HTTP-Method" is used to override the POST method.
Below is the required JSON request for updating a site’s description.
{'__metadata':{'type': 'SP.Web'}, 'Description': 'Updated information'} |
3. Give permissions for AAD user to SPO site: If you need to give read/write permission for an AAD user to SPO site/SPO folders, follow the steps below;
We have used a site template which creates different site groups (For Reader/Owner etc.). If a user need “Read” permission, he has to be added in the Readers group. Giving permissions is a two-step process;
A. Get the site group ID:
- Resource URL:
The %SupplierSiteName% is the value to be replaced by the site name.
The %GroupName% is the value to be replaced by the group name.
- HTTP Headers:
content-type | application/json; odata=verbose |
Cookie | Cookie value has to be passed |
X-RequestDigest | Digest value has to be passed |
- HTTP method : GET
B. Add user to the above group:
- Resource URL:
The %SupplierSiteName% is the value to be replaced by the site name.
The %GroupID% is the value to be replaced by the GroupID which we got in the first step.
- HTTP Headers:
content-type | application/json; odata=verbose |
Cookie | Cookie value has to be passed |
X-RequestDigest | Digest value has to be passed |
- HTTP method : POST
Below is the required JSON request for adding the user to the group.
{"__metadata":{"type":"SP.User"},"LoginName":"i:0#.f|membership|Jeorge.Kaps@mysaptest.onmicrosoft.com"} |
4. Create folder in SPO: If you need to create folders inside SPO site, follow the steps below;
- Resource URL:
- HTTP Headers:
content-type | application/json; odata=verbose |
Cookie | Cookie value has to be passed |
X-RequestDigest | Digest value has to be passed |
- HTTP method : POST
Below is the required JSON request for adding the user to the group.
{'__metadata':{ 'type': 'SP.Folder' }, 'ServerRelativeUrl': '/shared documents/Test1' } |
5. Upload file into SPO site: If you need to upload files inside a folder, follow the steps below;
- Resource URL:
- HTTP Headers:
content-type | application/json; odata=verbose |
Cookie | Cookie value has to be passed |
X-RequestDigest | Digest value has to be passed |
- HTTP method : POST
NOTE: In my case, the file to be uploaded is sent from ECC as SOAP attachment. This attachment is swapped in PI using the standard module. The file name, folder name can be set dynamically. We could upload any type of file.
Kindly wait for Part-2 of this blog for the common AAD operations. Happy learning :-)
Regards,
Stenish Peter. S