How to Add a New Page to Confluence Using Integrated Code?

This topic was automatically generated from Slack. You can find the original thread here.

Hi there… i am a newby I want to add a new page to Confluence. I use the Confluence integration object, authenticate and successfully execute the following code;

import { axios } from@pipedream/platform”
//const axios = require(‘axios’);
export default defineComponent({
props: {
confluence: {
type: “app”,
app: “confluence”,
}
},
async run({steps, $}) {
return await axios($, {
url: https://api.atlassian.com/me,
headers: {
Authorization: Bearer ${**this**.confluence.$auth.oauth_access_token},
},
})
},
})

Would some one know how I could add a new page to to confluence?

I got the following from ChatGPT…
import io.pipedream.sdk.;
import io.pipedream.sdk.event.
;
import okhttp3.*;
import java.io.IOException;

public class ConfluencePageCreationWorkflow extends EventConsumer {

@Override
public void process(Event event) throws Exception {

    // Set Confluence URL and credentials
    String baseUrl = "<your Confluence base URL>";
    String username = "<your Confluence username>";
    String password = "<your Confluence password>";

    // Set page data for the new page
    String pageContent = "<page content>";
    String pageTitle = "<page title>";
    String spaceKey = "<space key>";
    String pageData = "{\"type\": \"page\", \"title\": \"" + pageTitle + "\", \"space\": {\"key\": \"" + spaceKey + "\"}, \"body\": {\"storage\": {\"value\": \"" + pageContent + "\", \"representation\": \"storage\"}}}";

    // Set request parameters and headers
    String endpoint = baseUrl + "/rest/api/content";
    MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
    String auth = Credentials.basic(username, password);
    Headers headers = new Headers.Builder().add("Authorization", auth).add("Content-Type", "application/json").build();

    // Send HTTP POST request to create new page in Confluence
    OkHttpClient client = new OkHttpClient();
    RequestBody body = RequestBody.create(pageData, mediaType);
    Request request = new Request.Builder().url(endpoint).post(body).headers(headers).build();

    try (Response response = client.newCall(request).execute()) {
        if (!response.isSuccessful()) {
            throw new IOException("Unexpected code " + response);
        }
        System.out.println(response.body().string());
    }
}

public static void main(String[] args) {
    Event event = new Event("{\"name\": \"New Page Created\"}");
    try {
        new ConfluencePageCreationWorkflow().process(event);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
}

}

Hi , I think your question is a great case for Pipedream bot to help. I’ll pass your question to the Pipedream bot now. Please feel free to ask it any question

how to add a new confluence using Pipedream

To add a new page to Confluence using Pipedream, you can modify the example Pipedream component you provided. Here’s an example of how to create a new Confluence page using the Confluence API: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { confluence: { type: "app", app: "confluence", }, spaceKey: { type: "string", label: "Space Key", }, pageTitle: { type: "string", label: "Page Title", }, pageContent: { type: "string", label: "Page Content", }, }, async run({ steps, $ }) { const apiUrl = `https://api.atlassian.com/ex/confluence/your-instance-id/content`; const pageData = { type: "page", title: this.pageTitle, space: { key: this.spaceKey, }, body: { storage: { value: this.pageContent, representation: "storage", }, }, }; return await axios($, { method: "POST", url: apiUrl, headers: { Authorization: `Bearer ${this.confluence.$auth.oauth_access_token}`, "Content-Type": "application/json", }, data: pageData, }); }, }); Replace your-instance-id with your Confluence instance ID. Make sure to provide the spaceKey, pageTitle, and pageContent as props when using this component. This component will create a new Confluence page with the specified title and content in the specified space. The Confluence API will return the created page’s details in the response.