How to create a Confluence page from Forge

I’m trying to make a button that will create a page when you click it. But I am missing something basic. Here’s my code. It properly displays the macro, but when I click the button, no page is created.

Any hints would be greatly appreciated. Thank you.

import ForgeUI, { render, useState, ModalDialog, Macro, Fragment, Button } from "@forge/ui";
import { Form, Select, Option } from "@forge/react";
import api, { route } from "@forge/api";

var bodyData = `{
  "spaceId": "ForgeTest",
  "title": "Test Page",
}`;

const clickthebutton = async () => {await api.asUser().requestConfluence(route`/wiki/rest/api/page`, {
  method: 'POST',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
  body: bodyData
})};
  
  
// Boilerplate to operate the macro
const App = () => {
 return (    
	<Button
     text="Create page"
     onClick={async () => {
       await clickthebutton;
     }}
	/>    
  );
};

// Boilerplate to display the macro
export const run = render(
  <Macro
    app={<App />}
  />
);
1 Like

Note: I realized that I was using the spaceKey, rather than the spaceId. I’ve corrected that (with both “111” and 111) but it still doesn’t work.

Did you update your scope in the manifest.yml? Should look something like

permissions:
  scopes:
    - write:page:confluence
1 Like