Welcome to the new Box Support website. Check out all the details here on what’s changed.

Creating a shared link via API and Curl

Answered
New post

Comments

3 comments

  • Nayak

    I did try the same in Postman with the body as below and confirm that the shared link was created with the expiry date set.

    {"shared_link": {"access": "open", "unshared_at": "2020-12-12T10:53:43-08:00"}}

     

    Not sure if you are trying this in a free account as shared link expiry is only available to paid accounts.

    :The timestamp at which this shared link will expire. This field can only be set by users with paid accounts."

     

     

    0
    Comment actions Permalink
  • womble

    Thank you for you reply. I do have a paid account. Your response gave me the confidence to keep trying.

     

    It turns out I was not forming the parameters right in Guzzle and Curl. In case anybody else needs this, to get it to work in PHP, with Guzzle:

     

    $unshare_date = "2020-12-12T10:53:43-08:00";
    
    $api_url = 'https://api.box.com/2.0/files/' . $fileId;    
    $query = ['fields' => 'shared_link'];
    $json = ['shared_link' => ['access' => 'open', 'unshared_at' => $unshare_date]];
    $params = [
        'headers' => [
             'Authorization' => "Bearer {$token}",
         ], 
         'query' => $query, 
         'json' => $json
    ];
    
    $res = json_decode($client->request('PUT', $api_url, $params)->getBody()->getContents());
    
    $shared_link = $res->shared_link->url;
    $download = $res->shared_link->download_url;
    0
    Comment actions Permalink
  • kliger

     I have the same issue that you had, did you figure out how to create a curl request to do that?

    I am trying this one but it doesn't create a shared link correctly 😞

     

    curl -X PUT https://api.box.com/2.0/files/ \
         -H 'Authorization: Bearer ' \
         -H 'Content-Type: "application/json"' \
         -d '{
           "shared_link": {
             "access": "open"
           }
         }' 
    0
    Comment actions Permalink

Please sign in to leave a comment.