Create Share Using API

  • 1
  • Problem
  • Updated 1 year ago
I'm trying to mimic the behavior of "Email with ShareFile" thru our in-house system. I'm also assuming that the end result will be a link that looks like:  https://mydomain.sharefile.com/d/2345343aef42353

I'm sending th request to:

https://" . $self->{domain} . "/sf/v3/Shares?notify=false

with this JSON (the Item Id was extracted using a /sf/v3/Items and iterating over the returned children):

{
    "ShareType":"Send",
    "Title":"Sample Send Share",
    "Items": { "Id":"fi0c6efe-d43d-8516-f394-2896bb2407aa" } ,
    "Recipients":  { "User":{ "Email":"xxxx@gmail.com" } },
    "ExpirationDate":"2015-10-31",
    "RequireLogin":true,
    "RequireUserInfo":false,
    "MaxDownloads":-1,
    "UsesStreamIDs":false
}

I don't receive any errors, but the JSON I'm getting back doesn't make sense, I was expecting a link or a bit more info:

0  HASH(0x4178728)
   'odata.count' => 0
   'odata.metadata' => 'https://mydomain.sharefile.com/sf/v3/$metadata#Shares'
   'url' => 'https://mydomain.sharefile.com/sf/v3/Shares'
   'value' => ARRAY(0x41b5010)
        empty array

Any help is appreciated.

Ron
Photo of ron vennes

ron vennes

  • 12 Posts
  • 2 Reply Likes

Posted 4 years ago

  • 1
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Software Engineer

  • 733 Posts
  • 102 Reply Likes
Hi Ron,

Looks like you may be sending the request as a GET rather than POST, which is required for creating a Share. Could you check if this is indeed the case?

Thanks!
Eli
Photo of ron vennes

ron vennes

  • 12 Posts
  • 2 Reply Likes
Doing a dump of the response, I do see it was sent as a GET.
Photo of ron vennes

ron vennes

  • 12 Posts
  • 2 Reply Likes
Changed to POST, not getting this:  {"code":"BadRequest","message":{"lang":"en-US","value":"Invalid Share: provide either a type, parent, or item list"},"reason":"BadRequest"}
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Software Engineer

  • 733 Posts
  • 102 Reply Likes
It is likely the server cannot understand the request. Double check that the header "content-type: application/json" is set on the request.

Eli
Photo of ron vennes

ron vennes

  • 12 Posts
  • 2 Reply Likes
Maybe closer... Now getting:

'{"code":"InternalServerError","message":{"lang":"en-US","value":"Object reference not set to an instance of an object."},"reason":"Unspecified"}'
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Software Engineer

  • 733 Posts
  • 102 Reply Likes
Interesting. Could you provide a dump of the request? It would be helpful if we could see the body and headers as they are going out to the server.

Thanks,
Eli
Photo of ron vennes

ron vennes

  • 12 Posts
  • 2 Reply Likes
This is just before the POST:

0  LWP::UserAgent=HASH(0x36a3258)
   'def_headers' => HTTP::Headers=HASH(0x3338080)
      '::std_case' => HASH(0x296cc20)
         'content' => 'Content'
      'authorization' => 'Bearer 3ZZUDVGjX6oSV30rnHTfgS3t6mo9H91J##LlvSruRBw9s1xpQX4SotHPWbATD5IZ0H'
      'content' => '{
                "ShareType":"Send",
                "Title":"Sample Send Share",
                "Items": { "Id":"fi0c6efe-d43d-8516-f394-2896bb2407aa" } ,
                "Recipients":  { "User":{ "Email":"xxxx@gmail.com" } },
                "ExpirationDate":"2015-10-31",
                "RequireLogin":true,
                "RequireUserInfo":false,
                "MaxDownloads":-1,
                "UsesStreamIDs":false
            }'
      'content-type' => 'application/json'
      'user-agent' => 'libwww-perl/6.05'
   'handlers' => HASH(0x296d0b8)
      'response_header' => HTTP::Config=ARRAY(0x36a3768)
         0  HASH(0x3aca968)
            'callback' => CODE(0x354b3a0)
               -> &LWP::UserAgent::__ANON__[/usr/share/perl5/LWP/UserAgent.pm:683] in /usr/share/perl5/LWP/UserAgent.pm:662-683
            'line' => '/usr/share/perl5/LWP/UserAgent.pm:684'
            'm_media_type' => 'html'
            'owner' => 'LWP::UserAgent::parse_head'
   'local_address' => undef
   'max_redirect' => 7
   'max_size' => undef
   'no_proxy' => ARRAY(0x296d580)
        empty array
   'protocols_allowed' => undef
   'protocols_forbidden' => undef
   'proxy' => HASH(0x35e4158)
        empty hash
   'requests_redirectable' => ARRAY(0x35e3df8)
      0  'GET'
      1  'HEAD'
   'show_progress' => undef
   'ssl_opts' => HASH(0x3641610)
      'verify_hostname' => 0
   'timeout' => 180
   'use_eval' => 1
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Software Engineer

  • 733 Posts
  • 102 Reply Likes
It is subtle, but the Items parameter is supposed to be an array. Change it to this:

 "Items": [{ "Id":"fi0c6efe-d43d-8516-f394-2896bb2407aa" }] 

and try again.
Photo of ron vennes

ron vennes

  • 12 Posts
  • 2 Reply Likes
I also had to put the Recipients into an array too.  Thanks for the assist, I now get a nicely formatted ahare URL.
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Software Engineer

  • 733 Posts
  • 102 Reply Likes
Awesome, glad to see it worked. Let us know if you run into any other issues.

Thanks!
Eli
Photo of ron vennes

ron vennes

  • 12 Posts
  • 2 Reply Likes
So, I emailed the link to the address specified in the JSON:

"Recipients":  [ { "User":{ "Email":"xxxx@gmail.com" } } ],

Where xxxx is replaced by the actual name.  After entering credentials at the login prompt, I get an 'Access Denied', followed by 'This link is only accessible by people to whom it was emailed.'

Thx
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Software Engineer

  • 733 Posts
  • 102 Reply Likes
Interesting. Is that email address associated with a user on your account? If so, did you login with those user's credentials?

Eli
Photo of ron vennes

ron vennes

  • 12 Posts
  • 2 Reply Likes
Yes, and I also tried:

"Recipients":  [ { "User":{ "Id":"b763d30a-c464-40f0-bd63-f70636295edb" } } ],

but get the same access denied after logging into ShareFile

ron
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Software Engineer

  • 733 Posts
  • 102 Reply Likes
Ron, I will contact directly to follow up on this one.
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Software Engineer

  • 733 Posts
  • 102 Reply Likes
Ron, 

Wanted to bring this back full circle here on the forum. The reason the link generated by the API is not working for your recipient is that it is not the recipient specific link. Basically, when you create a Share with one or more recipients, each of them actually gets their own link associated with their user credentials.

In order to access each recipient's specific link you can make the following request:

https://sub.sf-api.com/sf/v3/Shares(id)/Recipients
 
This will give you back a list of your recipients and the uri for each. The uri is in the same format, except that the guid at the end does not start with an 's', i.e, sub.sharefile.com/d-9743d53ba...

If you allow ShareFile to send the email for you (using the /sf/v3/Shares/Send request) we take care of sending each recipient the appropriate link. However, if you want to take care of emailing the links yourself the process can be cumbersome, which is why we have a simple workaround.

If you want one link that will work for all your recipients, you can modify it like this:
sub.sharefile.com/d-<share_id> ---> sub.sharefile.com/da/<share_id>
Let me know if this solves your issue or if you have any follow up questions.

Thanks!
Eli
Photo of ron vennes

ron vennes

  • 12 Posts
  • 2 Reply Likes
Eli, your the best!

I've got this working now.  I appreciate all the help. Hopefully someone else can benefit from this exchange.

Ron
Photo of Test Ontash

Test Ontash

  • 2 Posts
  • 0 Reply Likes
Thank you guys...your discussion helped me too :)
Photo of Liudmila

Liudmila

  • 1 Post
  • 0 Reply Likes
Thank you so much it helped me as well!
It doesn't seem to be working when the 'RequireUserInfo' is set to true, though?