Skip to main content
Question

Expiration dates for Shared Link through API

  • May 21, 2025
  • 1 reply
  • 23 views

Forum|alt.badge.img

Hi,

 

We are having a integration where a file is uploaded to Box and the shared link from Box is appended to our application. I need to set expiration dates for these links as zero (no expiration). Can someone please advise how this can be done using Box API? 

 

Appreciate any responses.

 

Regards,

MK

1 reply

Forum|alt.badge.img

 

string url = "https://api.box.com/2.0/files/" + file_id + "/";

HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
webrequest.Method = "PUT";
webrequest.ContentType = "application/json";
webrequest.Headers.Add("Authorization", "Bearer " + TOKEN);
webrequest.Headers.Add("As-User", user_id);

using (var streamWriter = new StreamWriter(webrequest.GetRequestStream()))
{
      string json = "{\"shared_link\": " +
                    "{\"unshared_at\": null}}";  // sets expiration to none
      streamWriter.Write(json);
      streamWriter.Flush();
      streamWriter.Close();
}

try
{
      var response = (HttpWebResponse)webrequest.GetResponse();
      using (var streamReader = new StreamReader(response.GetResponseStream()))
      {
           var result = streamReader.ReadToEnd();
           Console.WriteLine("Success: " + url);
      }
}
catch (Exception e)
{
      Console.WriteLine(e.Message);
}
}