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());
}
}
}