0

We are trying to setup sharepoint rest api in Azure apim backend. We set up the following apim policy. It is receiving the client token, but , not able to successfully execute rest call in the sharepoint. I am not sure whether we are on the right track. Any input is greatly appreciated. Thank you.

    <send-request ignore-error="true" timeout="20" response-variable-name="bearerToken" mode="new">
        <set-url>{{authorizationServer}}</set-url>
        <set-method>POST</set-method>
        <set-header name="Content-Type" exists-action="override">
            <value>application/x-www-form-urlencoded</value>
        </set-header>
        <set-body>@{
          return "client_id={{clientId}}&scope={{scope}}&client_secret={{clientSecret}}&grant_type=client_credentials";

          // For Azure AD v1, try return statement below
          // return "client_id={{clientId}}&resource={{scope}}&client_secret={{clientSecret}}&grant_type=client_credentials";
      }</set-body>
    </send-request>
    <set-header name="Authorization" exists-action="override">
        <value>@("Bearer " + (String)((IResponse)context.Variables["bearerToken"]).Body.As<JObject>()["access_token"])</value>
    </set-header>
    <!--  Don't expose APIM subscription key to the backend. -->
    <set-header name="Ocp-Apim-Subscription-Key" exists-action="delete" />
ninja12
  • 15
  • 2

1 Answers1

0
  • Before calling backend services we need to initiate a request for which APIM provides send request where you can use that in your policy along with the C# expression.

  • Also, you can go through this document which has details about Access tokens.

  • As you have already generated token just check the app is granted through enough permissions

  • For complete details about SharePoint Rest API go through this document and this MS Q&A discussion.

SaiSakethGuduru
  • 2,218
  • 1
  • 5
  • 15