Search code examples
javascriptcrondropboxdropbox-api

Write file to dropbox via cronjob.de


I need to run code in javascript at specific time of a day. And every time when this script is triggered i need to save a file with some information. So i figured out i'm gona use dropbox API to do that. I have created new app in my dropbox account and generated token for it.

For test MY_SCRIPT.js looks like this:

var client = new Dropbox.Client({ token: "GENERATED_TOKEN" });
client.writeFile("FILE_NAME","DATA");

I have html file on the server (which i don't have access) with a structure like this:

<!DOCTYPE html>
<html>
<head>
<script language="javascript" src="//cdnjs.cloudflare.com/ajax/libs/dropbox.js/0.10.2/dropbox.min.js"></script>
</head>
<body>
<script language="javascript" src="//PATH/MY_SCRIPT.js">    </script>
</body>
</html>

When i run this html file on my web browser it works fine (new file in dropbox app folder is being created).

But when i put this html address in new cronjob (cronjob.de) new files are not being created. Why? I assume the problem is access to the dropbox API from cronjob server. But how i can handle this?


Solution

  • The problem is that cronjob.deuses an browser / command that won't evaluate javascript. (such as curl)
    So your javascript code will never be executed.

    You should rather use an backend such as phpto run tasks of this kind.