protected function fetch_dropbox_data($endpoint, $data = []) {
        $url = $this->get_api_endpoint($endpoint);
        $this->cleanopt();
        $this->resetHeader();

        if ($data === null) {
            // Some API endpoints explicitly expect a data submission of 'null'.
            $options['CURLOPT_POSTFIELDS'] = 'null';
        } else {
            $options['CURLOPT_POSTFIELDS'] = json_encode($data);
        }
        $options['CURLOPT_POST'] = 1;
        $this->setHeader('Content-Type: application/json');

        $response = $this->request($url, $options);
        $result = json_decode($response);

        $this->check_and_handle_api_errors($result);

        if ($this->has_additional_results($result)) {
            // Any API endpoint returning 'has_more' will provide a cursor, and also have a matching endpoint suffixed
            // with /continue which takes that cursor.
            if (preg_match('_/continue$_', $endpoint) === 0) {
                // Only add /continue if it is not already present.
                $endpoint .= '/continue';
            }

            // Fetch the next page of results.
            $additionaldata = $this->fetch_dropbox_data($endpoint, [
                    'cursor' => $result->cursor,
                ]);

            // Merge the list of entries.
            $result->entries = array_merge($result->entries, $additionaldata->entries);
        }

        if (isset($result->has_more)) {
            // Unset the cursor and has_more flags.
            unset($result->cursor);
            unset($result->has_more);
        }

        return $result;
    }