TaskMonkey Handbuch

Dropbox

Dateien in Dropbox ablegen, lesen, suchen.

Dropbox ist eine klassische „Datei-Ablage für Automatisierungen": PDFs, Reports, Uploads von Benutzern landen dort, teilbar und durchsuchbar.

Verbinden

/manage/o-auth-connections → Provider Dropbox. Die API braucht nur einen Scope:

Scope Für
files.content.write Dateien hochladen und ändern
files.content.read Dateien lesen
files.metadata.read Metadaten lesen, ohne Inhalt
sharing.write Sharing-Links erzeugen

Beispiel: Datei hochladen

// apis.php
'dropbox' => [
    'base_url' => 'https://api.dropboxapi.com/2/',
],

'dropbox_content' => [
    'base_url' => 'https://content.dropboxapi.com/2/',
],

Tool:

'tools' => [
    'uploadToDropbox' => [
        'description' => 'Lokale Datei in Dropbox ablegen.',
        'parameters' => [
            'type' => 'object',
            'properties' => [
                'path' => ['type' => 'string', 'description' => 'Zielpfad in Dropbox, z. B. /Reports/2026-04.pdf'],
                'content' => ['type' => 'string', 'description' => 'Datei-Inhalt oder Base64 bei Binary'],
            ],
            'required' => ['path', 'content'],
        ],
        'handler' => function (array $results, array $args, array $ctx): array {
            $res = $ctx->http->post(
                'https://content.dropboxapi.com/2/files/upload',
                [
                    'headers' => [
                        'Content-Type' => 'application/octet-stream',
                        'Dropbox-API-Arg' => json_encode([
                            'path' => $args['path'],
                            'mode' => 'overwrite',
                            'mute' => true,
                        ]),
                    ],
                    'body' => $args['content'],
                ],
                ['api' => 'dropbox_content']
            );

            return [
                'path' => $res['path_display'],
                'size' => $res['size'],
            ];
        },
    ],
];

Sharing-Link erzeugen

'tools' => [
    'shareDropboxFile' => [
        'description' => 'Öffentlichen Link zu einer Dropbox-Datei erzeugen.',
        'parameters' => [
            'type' => 'object',
            'properties' => ['path' => ['type' => 'string']],
            'required' => ['path'],
        ],
        'api' => 'dropbox',
        'method' => 'POST',
        'path' => 'sharing/create_shared_link_with_settings',
        'body' => ['path' => '{path}'],
        'mapping' => ['url' => 'url'],
    ],
];

Das Modell kann jetzt auf Nutzer-Anfrage hin einen Datei-Pfad in einen teilbaren Link verwandeln.

Dateien auflisten

'listDropboxFolder' => [
    'description' => 'Inhalt eines Dropbox-Ordners auflisten.',
    'parameters' => [
        'type' => 'object',
        'properties' => [
            'path' => ['type' => 'string', 'description' => 'Ordnerpfad, leer für Root'],
        ],
        'required' => ['path'],
    ],
    'api' => 'dropbox',
    'method' => 'POST',
    'path' => 'files/list_folder',
    'body' => ['path' => '{path}', 'recursive' => false],
    'mapping' => [
        'entries' => [
            'name' => 'name',
            'path' => 'path_display',
            'size' => 'size',
            'type' => '.tag',
        ],
    ],
];

Muster: „Datei generieren und dort ablegen"

'monthlyReport' => [
    'handler' => function (array $results, array $args, array $ctx): array {
        $csv = buildReport();

        $upload = $ctx->runTool('uploadToDropbox', [
            'path' => '/Reports/' . date('Y-m') . '.csv',
            'content' => $csv,
        ]);

        $share = $ctx->runTool('shareDropboxFile', [
            'path' => $upload['path'],
        ]);

        return [
            'file' => $upload['path'],
            'shareUrl' => $share['url'],
        ];
    },
];

Das Modell bekommt das kompakte Ergebnis — Datei-Pfad + teilbaren Link — und kann dem Benutzer direkt antworten.

Rate-Limits

Dropbox ist großzügig (individuell, aber praktisch immer ausreichend). Bei hohen Volumina Scheduled Tasks auf Bursts achten — nicht 1000 Uploads in einer Schleife, sondern gestaffelt.

Debug

tm test-tool uploadToDropbox path=/test.txt content=hello
tm logs                       # bei 401/403
Zuletzt aktualisiert: 2026-04-19