We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.
Forum Discussion
Li P.
10 years agoNew member | Level 1
Can I save a JSON stream object to Dropbox file with Dropbox Post Rest API ?
Hi,
I sent a request to salesforce , then get a JSON stream. Now I want to save the stream object into a Dropbox file by sending Post request in my code. Does Dropbox have relative Post rest api ? How can I do it?
Thanks for your help!
- Greg-DBDropbox Staff
You can upload data to Dropbox using the /files_put endpoint on the Core API:
https://www.dropbox.com/developers/core/docs#files_put
That endpoint accepts both PUT and POST. You can use the HTTP endpoints, such as the above, directly, but we recommend using an official SDK if possible:
https://www.dropbox.com/developers/core
Otherwise, there are some third party libraries listed here that may be helpful:
- Li P.New member | Level 1
Hi Greg,
Thanks very much for your prompt reply. It is very helpful to me.
I tried to create an APP using 'Drop-In' Saver type. The APP just give me APP key, but no APP Secret. Before I post my stream data to the /file_put endpoint, I need to get authorized. right ?My APP is an browser client app. And I found the endpoint '/oauth2/token' (OAuth 2.0) maybe useful to me to get token (without user interactive), but where can I get APP Secret? Or which endpoint is easy to get authorized without user interactive?
Best Regards.
- Li P.New member | Level 1
By the way, After I got access token, How to use the token to post request to '/files_put' ? It seems no parameter for access token to the endpoint. Thanks.
- Greg-DBDropbox Staff
To use the Core API, you'll need to register a "Dropbox API app", not a "Drop-ins app":
https://www.dropbox.com/developers/apps/create
Drop-ins don't have app secrets, unlike Dropbox API apps.
And yes, to use the Core API, you'll need to have the user authorize the app to access their account. Then, you can make API calls using the resulting access tokens. (If you only need to connect to your own account, you just need to do this once. You can also easily get an OAuth 2 access token for your own account as shown here: https://blogs.dropbox.com/developers/2014/05/generate-an-access-token-for-your-own-account/ )
Note that getting an access token is a process that involves user intervention, but once you have it, you can store and re-use it for that account without further manual user intervention.
We recommend using an SDK or library as I mentioned before, but if you can't for whatever reason, you can sign the calls using OAuth 1 or OAuth 2. We have blog posts for each:
OAuth 1: https://blogs.dropbox.com/developers/2012/07/using-oauth-1-0-with-the-plaintext-signature-method/
OAuth 2: https://blogs.dropbox.com/developers/2013/07/using-oauth-2-0-with-the-core-api/ - Li P.New member | Level 1
Hi Greg,
Thanks for your patient !
I will use the lib "https://github.com/sintaxi/dbox", and try to use my own account (without user interactive).
In future, If user can provider dropbox account like 'username/password' , Is there any API to get access token directly without user interaction ?
Thanks. - Li P.New member | Level 1
Hi Greg,
Below is another issue:
I created a Dropbox API app, It includes APP key and APP secret now, and generated access token in my APP page. Then I use lib 'dbox' in the browser-client. Below is my JS:
var dboxclient = require('dbox'); var app = dboxclient.app({"app_key": "j4nrv1xhtjj3svq","app_secret":"<REDACTED>"}); var client = app.client("<REDACTED>"); module.exports = DBOX; function DBOX() { } DBOX.prototype.getAccount = function() { client.account(function(status, reply){ console.log(reply) }); } DBOX.prototype.Metadata = function() { // available options... var options = { file_limit : 10000, // optional //hash : ..., // optional list : true, // optional include_deleted : false, // optional //rev : 7, // optional credentials : false, locale : "en", // optional root : "sandbox" // optional }; client.metadata("started.pdf", options, function(status, reply) { console.log(reply); }); } DBOX.prototype.Putfile = function() { client.put("hello.txt", "here is some text", function (status, reply) { console.log(reply); }); }
Then I call it in my another js like this:
var dbox = new DBOX(); dbox.getAccount(); //dbox.Putfile();
It failed with error message in the browser console:
POST https://api.dropbox.com/1/account/info request.js:117 Request.endmain.js:761 Request.endmain.js:345 (anonymous function)browser.js:19 drainQueue localhost/:1 XMLHttpRequest cannot load https://api.dropbox.com/1/account/info. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:3000' is therefore not allowed access. main.js:422 Uncaught TypeError: Cannot read property 'set-cookie' of undefinedmain.js:422 (anonymous function)events.js:77 EventEmitter.emitrequest.js:61 (anonymous function)events.js:74 EventEmitter.emitresponse.js:92 Response.handlerequest.js:73 xhr.onreadystatechange
Do you any Ideas?
Thank you!
- Greg-DBDropbox Staff
That's a security feature of CORS. I'm not familiar with the dbox library you're using, but you need to make sure you don't use credentials (i.e., the withCredentials XHR field, for example, to set cookies) when making these API calls.
- Li P.New member | Level 1
Greg, thanks!
I don't familiar with dbox, and don't know how to set config before send request. So I will use the '/files_put' rest. Now The question is how I can attach the access token (generated in my app page) when sending post to '/files_put' ? It seems '/files_put' has not this parameter in Core API document.
Thanks. - Steve M.Dropbox Staff
Just set the
Authorization
header toBearer <token>
. The documentation doesn't mention this, because it's just how OAuth 2 works.BTW, I redacted the access token in your post, but just in case someone else saw it, you should make sure to disable it. Unlinking your app from the account security tab and then relinking (getting a new token) should do the trick.
- Li P.New member | Level 1
Thanks, Steve.
I will try it when I get chance. Both of you have a nice day.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,877 PostsLatest Activity: 12 months agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!