Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.4 kB
1
Indexable
Never
<!DOCTYPE html>
<html>
<head>
    <title>Confluence Page Data Fetch</title>
</head>
<body>
    <div id="confluenceData"></div>
    <button id="fetchButton">Fetch Data</button>

    <script>
        // Replace with your Confluence URL and page ID
        const confluenceBaseUrl = 'https://your-confluence-instance.atlassian.net';
        const sourcePageId = '12345'; // Replace with your source page ID
        const targetPageId = '67890'; // Replace with your target page ID

        document.getElementById('fetchButton').addEventListener('click', fetchData);

        function fetchData() {
            const url = `${confluenceBaseUrl}/wiki/rest/api/content/${sourcePageId}?expand=body.storage`;

            fetch(url, {
                method: 'GET',
            })
            .then(response => response.json())
            .then(data => {
                const content = data.body.storage.value;
                const targetElement = document.getElementById('confluenceData');
                targetElement.innerHTML = content;

                // Optionally, you can save this content to another page.
                const updateUrl = `${confluenceBaseUrl}/wiki/rest/api/content/${targetPageId}`;
                fetch(updateUrl, {
                    method: 'PUT',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        version: {
                            number: data.version.number + 1
                        },
                        title: data.title,
                        type: data.type,
                        body: {
                            storage: {
                                value: content,
                                representation: 'storage'
                            }
                        }
                    })
                })
                .then(response => response.json())
                .then(result => {
                    console.log('Data saved to target page:', result);
                })
                .catch(error => {
                    console.error('Error updating target page:', error);
                });
            })
            .catch(error => {
                console.error('Error fetching data from source page:', error);
            });
        }
    </script>
</body>
</html>