title: Create a Sharepoint anonymous link using REST api
body: <p>I have a PHP application where I retrieve the documents from Sharepoint and display into a list where users can click to see/download the file. 
  Currently I'm linking to the Sharepoint URL which is protected by login. I need to link to a link that can be accessed by anonymous users.</p>
  
  <p>I can create a share link using the Sharepoint interface and I see in the network tab (google console) that a POST request to <a href="https://myclient.sharepoint.com/sites/CustomerPortal/_api/web/Lists(@a1)/GetItemById(@2)/ShareLink?@a1=%27%7B11CD851B%2D1385%2D43DA%2DBB41%2D132AFAAA0927%7D%27&amp;@a2=%274620%27" rel="nofollow noreferrer">https://myclient.sharepoint.com/sites/CustomerPortal/_api/web/Lists(@a1)/GetItemById(@2)/ShareLink?@a1=%27%7B11CD851B%2D1385%2D43DA%2DBB41%2D132AFAAA0927%7D%27&amp;@a2=%274620%27</a> is made.
  When I try to perform the same request via Postman I get the following error:</p>
  
  <pre><code>{
      "error": {
          "code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
          "message": {
              "lang": "en-US",
              "value": "The expression \"web/Lists(@a1)/GetItemById(@2)/ShareLink\" is not valid."
          }
      }
  }
  </code></pre>
  
  <p>I tried to create an anonymous link using the endpoint: <a href="https://myclient.sharepoint.com/sites/CustomerPortal/_api/SP.Web.CreateAnonymousLink" rel="nofollow noreferrer">https://myclient.sharepoint.com/sites/CustomerPortal/_api/SP.Web.CreateAnonymousLink</a>
  with the following JSON body:</p>
  
  <pre><code>{
      "url":"http://myclient.sharepoint.com/CustomerPortal/Folder/file.pdf",
      "isEditLink":"true"
  }
  </code></pre>
  
  <p>and the response I get is:</p>
  
  <pre><code>{
      "error": {
          "code": "-1, System.InvalidOperationException",
          "message": {
              "lang": "en-US",
              "value": "Operation is not valid due to the current state of the object."
          }
      }
  }
  </code></pre>
  
  <p>How can I <strong>create a anonymous link using REST API</strong>? Is it possible? Is there any configuration that my client needs to do on Sharepoint side?</p>
  
  <p>Thank you. </p>