Unable to get access token

  • 1
  • Question
  • Updated 1 month ago
  • (Edited)


I am trying to get access token, it's throwing above error. Can you suggest me what could be the reason?

Actually, I am trying to upload multiple file from "SAP PI/PO" (middleware) to sharefile folder by REST API call.

Please suggest me the steps like after getting token how I can able to upload the multiple files in specific folder?  


And I want to make token alive for long time. What's the way?


Appreciate your time..

Regards
Binod






Photo of Binod Thakur

Binod Thakur

  • 7 Posts
  • 0 Reply Likes

Posted 3 months ago

  • 1
Photo of Andrew Batz

Andrew Batz

  • 5 Posts
  • 0 Reply Likes
The Oauth documentation sucks (which is representative of the rest of the API docs). 
I was able to get it working using 
https://secure.sharefile.com/oauth/authorize
as the Authorize URL, and for the Access Token URL 
https://YOUR-SUBDOMAIN.YOUR-DOMAIN.com/oauth/token
for example, our domain isn't sharefile it's citrixdata, and our subdomain is our company name. Look at the url of someone signed in to sharefile to see both in one convenient place.  
and you might want to try openid as the scope
(Edited)
Photo of Binod Thakur

Binod Thakur

  • 7 Posts
  • 0 Reply Likes
Hi Andrew,

First of all thanks for your quick response.

I am new in api. As I understood from your suggestion, 1st I need to get authorization_code by providing basic credential and then by authorization_code I can get access token. Still, I am not able to get it.


 



Thanks,
Binod







Photo of Andrew Batz

Andrew Batz

  • 5 Posts
  • 0 Reply Likes
Step 1, if you haven't yet, read up/ watch the videos that explain the basics of oauth2, really understanding it is a prerequisite that's hard to work around.
Step 2, When getting your token for the first time, there is no authorization header and it might treat a malformed request as a automatic rejection. 
Step 3, your sharefile client ID and client secret must have a callback URL registered to it that it's calling back with. The one you selected when setting up the client keys is the only one it will legitimately call back to. 
Step 4, Understand what you're trying to use the API for. SFTP and WEBdav interfaces exist for sharefile that may be easier to use depending on what your use-case is. 
Step 5, understand that sharefile's api isn't here to be your friend, it's finicky and sometimes doesn't make sense. IMO it's a checkbox they're filling for some sales documentation rather than a fully thought out core to their product. 
Step 6, the domains you hit in the screenshots aren't looking right. 

call to secure.sharefile.com to get an authorization token, Then call to YOURDOMAIN.SUBDOMAIN.TLD/oauth/token (with the authorization token) to get your access token (which expires regularly and fairly quickly, when that happens have in-code or through whatever process manager you're using get a fresh access token using your authorization token). Pass the Access token with your requests to interact with the API. 
I haven't seen anybody use secure.sharefile.com as their custom domain, but IDK, it's possible. 
(Edited)
Photo of Binod Thakur

Binod Thakur

  • 7 Posts
  • 0 Reply Likes
Hi Andrew,

Thanks for your support. Now I can able to get access_token and able to make api call successfully. 
I am uploading the file with URL <b alt="" title="" name="" value="" type="" target="" rel="">POST https:</b><b alt="" title="" name="" value="" type="" target="" rel="">//account.sf-api.com/sf/v3/Items(id)/Upload2 </b><br alt="" title="" name="" value="" type="" target="" rel="">
With Postman, when I'm making 1st post call it returns Chunk URI and then on Chunk URI again i have to make one another call then only file is getting uploaded.

Is there any way to upload the file in a single POST call? Actually, I am trying to upload file from SAP PI/PO to sharefile and in SAP I can make only one call either GET/POST... 
So, how is it possible to upload file in single call only?

Need your help on this...


Thanks,
Binod
Photo of Andrew Batz

Andrew Batz

  • 5 Posts
  • 0 Reply Likes
If you find a way to single-shot it, i'd be happy to hear that. I had to build a handler that I call with the file, and it does the 2-step API calls that result in a multipart-form-upload. 

Just as a second general comment, it looks like you're embedding it in HTML, I wouldn't expose API keys to end users. 
Photo of Binod Thakur

Binod Thakur

  • 7 Posts
  • 0 Reply Likes
I wasn't embedding it in HTML, just trying to mention upload url. But after submitting the comment it formed like HTML tag.

I have automated uploading process with java code
1st step: wrote code to get access_token
2nd step: got Chunk URI after making post call on \Upload URL
3rd step: made POST call on Chunk URI with file name details.

It's working fine, file is getting uploaded in folder.

In SAP PI/PO only one call is possible, as i mentioned in above comment. So, I'm not getting any idea that how to configure same thing in PI/PO.

If uploading file will be possible in single REST call, my problem will be solved. Could you please help on this with any kind of suggestion? 


"I wouldn't expose API keys to end users."  I didn't get why you have mentioned this comment. But, I'm able to get API keys by making REST call to apps.




(Edited)
Photo of Andrew Batz

Andrew Batz

  • 5 Posts
  • 0 Reply Likes
Here's one way to get a file to code you're executing using AWS lambdas and S3.
https://www.netlify.com/blog/2016/11/17/serverless-file-uploads/
Once your code (not SAP) is in charge of the sharefile upload, you can manipulate the calls and how the data is encoded. But if you need to get it in one shot, I'd just make the straight S3 api call and handle the dual calls in the lambda that gets run any time a file shows up in it's folder. The tricky part is passing the folderID, which you could store as a header/meta variable on the file.