Sharepoint

The Sharepoint extensions lets you fetch files from your SharePoint account and display them into a field of your Content Type. Thus, while creating entries, you can select one or more files as an input value for the field.

This step-by-step guide explains how to create a SharePoint extension for the content types in your stack. The steps performed are as follows:

  1. Register your app in SharePoint
  2. Get the Realm of your site
  3. Deploy Lambda function
  4. Add the "SharePoint" extension to your stack
  5. Use the extension
  1. Register your app in SharePoint

    In order to use this extension, you will first need to register your app in SharePoint and generate app-specific credentials that are needed for authentication.

    To do so, perform the following steps:

    1. Log in to the SharePoint online site and navigate to the following URL: https://{sitename}.SharePoint.com/_layouts/15/appregnew.aspx.
    2. Under the App Information section, click the Generate buttons beside the Client Id and Client Secret textboxes to generate the values for both the keys. Note these values down as you will need to use them in Step 3.
    3. Provide a suitable Title for your app.
    4. Enter the App Domain (for example, www.contentstack.com, www.salesforce.com, and so on). This is the hosting URL of your app.
    5. Download the redirect.html file and upload this file as an asset into your Contentstack stack. Retrieve the download link of this file. Enter this URL in Redirect URI.
    6. Click Create.

    This registers your app and returns a success message with the created information.

  2. Get the Realm of your site

    After registering your app and generating the Client Id and Client Secret in the preceding step, you need to retrieve your app’s realm.

    Realm is a constant Globally Unique Identifier (GUID) for your site. You need to save this realm as we’ll be using it to deploy the lambda function in Step 3.

    To retrieve your app’s realm, perform the steps given below:

    1. Download Google Chrome’s Postman extension; install and launch it.
    2. In the URL field, enter https://your_site.sharepoint.com/_vti_bin/client.svc and make a GET request. Enter the param: Authorization: Bearer.
    3. In the response that you receive, you will see the Bearer realm component under Headers. Save this value.

    Next, you need to deploy your lambda function

  3. Deploy Lambda function

    To protect sensitive information (such as API Key and URL) and to avoid Cross-Origin Resource Sharing (CORS) issues, you can use lambda function for this extension.

    After retrieving the credentials in the preceding steps, deploy the code for the lambda function to AWS Lambda.

    Note: For the source code, please contact our Support team.
    To deploy the code to AWS Lambda, perform the following steps:

    1. Go to your AWS Console and navigate to AWS Lambda service.
    2. Create a Lambda function, and add an API Gateway trigger in the Configuration tab. You will get an API Gateway URL, like this, https://abcde1234.execute-api.us-east-1.amazonaws.com/default/demo-field.

      Store this URL, as you will need this while configuring the extension in Step 4.
      For additional security, you can configure an API Key for the API Gateway trigger and use this API Key when configuring your lambda function.
    3. In the Environment Variables section of AWS Lambda, enter the credentials against the variables as follows:
      • REALM_ID - e1111111-1c11-1f11-bf11-1e111111c11a
      • CLIENT_ID - 22222222-2ac2-2a2a-a2e2-22debd2fc9d2
      • CLIENT_SECRET - 33Ab33caBCAbCabCAbC/ABcABcaBca3bCabcAB/cabCA=
      • RESOURCE - 00000003-0000-0ab4-ca00-000000000000/demosite.sharepoint.com@e4444444-4f44-4g44-ef44-4g444444e44f
      • SHAREPOINT_DOMAIN - contentstackextension
      • SITE - extension

    Note: The values for the above parameters are not actual ones. Please add your app-speciifc values for these parameters.

  4. Add “SharePoint” field extension to your stack

    To add this extension to your stack, perform the following steps:

    1. Go to your stack, navigate to the “Settings” gear icon, and select Extensions.
    2. On the Extensions page, click on the + Add Extension button, and select Create new. If you have not added any extensions in the stack yet, click on the create a new one link as shown below.create-new-button.png
    3. In the Select Extension Type window, select Custom Field.select-custom-field.png
    4. On the Create New Extension page, enter values in the fields as given below:
      • Title (required): Provide a suitable title, for example “Sharepoint,” for your custom field. This title will be visible when you select the extension in the custom field in your content type.
      • Field Data Type (required): Select the data type in which the input data of the field should be saved in Contentstack. In this case, select JSON.
      • Multiple (optional): Select this checkbox if you want to enable multiple inputs for the field.
      • Hosting method (required): Select Hosted by Contentstack as the hosting method for this content type.
      • Extension Source Code (required): Specify the extension code here. To get the code, contact our Support team.


        The support team will provide you with the source code (src file). Copy the code from the index.html file located in the root folder and paste it in the Extension source code field.

      • Config Parameters: Enter the SharePoint Client Id as well as redirect URI that we retrieved in Step 1. Add the SharePoint library name. Finally, add the API Gateway URL and its API Key:
        {
            "sharepoint_domain": "demo_domain"
            "client_id": "your_client_id",
            "redirect_url": "your_app_redirect_uri",
            "site": "your_SharePoint_library_name",
            "url":"https://abcde1234.execute-api.us-east-1.amazonaws.com/development/demo-field",
            "x-api-key": "SSS111Sss1ssSSsssS11s11SS11SS"
        }
        
    5. Save the custom field.

  5. Use the extension

    Once you have added a custom field, you can use it in your content type like any other field. To add a custom field in your content type, perform the following steps:

    1. Create a content type and add the Custom field to it.

    2. Under Select Extension, select the “Sharepoint” field that you created and set the other properties. You can add other fields as per requirements.sharepoint.png
    3. Finally, click on either Save or Save and Close to save your changes.
    4. Next, create an entry for this content type, and you will see the Sharepoint field in action.SharePoint Final Demo.png

    Note: The number of items that can be selected depends on the size of the JSON that is to be stored, and currently, only 10 KB of data can be stored. This is due to limitation of the JSON data stored via Custom Field. Refer to our Custom Field Limitation doc for more detail.

Was this article helpful?

Thanks for your feedbackSmile-icon

On This Page

top-arrow