I’ve been using the Dropbox Javascript SDK on the front-end. However, once I try to use it on the back-end in a web module, it keeps throwing errors. I was wondering if an SDK/API like this can be used on the backend on its own, or do I need to use Fetch.
Yea. I changed up my strategy a bit and I’m now using the fetch function. I seem to be having an issue here. Here’s my backend code. I know the fetch is working perfectly, and I know that I’m getting the URL string as wanted (I confirmed with Dropbox support). The main issue seems to be happening on the front-end though. I’m trying to store this returned value by doing such:
let requestURL = generateSubmission();
// i then try to set the .text property of a text field to this requestURL variable
I think I’m doing something wrong with how I call the function on the front end, because the Web Console has an error about how I’m trying to store a Promise where I should have a string.
**BACKEND CODE:**
export function generateSubmission() {
let generated;
const params = {
//private stuff
}
let headers = {
//private stuff I'd rather not show
};
let options = {
method: 'POST',
headers: headers,
body: params
};
fetch('https://api.dropboxapi.com/2/file_requests/create', options)
.then(res => {
let response = res.json();
generated = response["url"];
})
return generated;
}
@tanushyadav first, be sure to put your backed code in a .jsw file and not in a .js file.
Second, on your front en import the module like:
import {generateSubmission} from 'backend/dropbox.jsw';
generateSubmission()
.then(requestURL => {
console.log(requestURL);//or do whatever you like with this result
})