500 Internal Server Error running Confluence Content Update API

Hello Everyone,

I’m positive I must be doing something wrong but I can’t see it. I’m trying to post a table of results to the page I’m executing my forge app from. However, I’m getting this response:

INFO   12:52:02.800 1882038fca9b3b77 {
 text: [Function: text],
 json: [Function: json],
 arrayBuffer: [Function: arrayBuffer],
 headers: Headers {
  '[Symbol(map)]': [Object: null prototype] {
   server: [ 'openresty/1.15.8.2' ],
   'cache-control': [ 'no-cache, no-store, must-revalidate' ],
   'content-type': [ 'application/json' ],
   'content-encoding': [ 'gzip' ],
   'strict-transport-security': [ 'max-age=315360000; includeSubDomains; preload' ],
   date: [ 'Wed, 31 Mar 2021 12:52:02 GMT' ],
   'x-request-id': [ '0ad93e2368e428cd' ],
   expires: [ 'Thu, 01 Jan 1970 00:00:00 GMT' ],
   'x-xss-protection': [ '1; mode=block' ],
   'transfer-encoding': [ 'chunked' ],
   'x-envoy-upstream-service-time': [ '48' ],
   'x-content-type-options': [ 'nosniff' ],
   connection: [ 'close' ],
   'atl-confluence-via': [ 'h:confluence-prod-us-3-2.prod.atl-paas.net' ],
   'x-trace-id': [ '0ad93e2368e428cd' ],
   'x-failure-category': [ 'FAILURE_ORIGIN' ],
   'x-frame-options': [ 'SameOrigin' ],
   'expect-ct': [
    'report-uri="https://web-security-reports.services.atlassian.com/expect-ct-report/global-proxy", enforce, max-age=86400'
   ]
  }
 },
 ok: false,
 status: 500,
 statusText: 'Internal Server Error'
}

This is the function I’m running:

async function publishMatches(bodyData) {
    const response = await api.asUser().requestConfluence("/wiki/rest/api/content/" + productContext.contentId.toString(), {
      method: "PUT",
      headers: {
        "Accept": "application/json",
        "Content-Type": "application/json"
      },
      body: bodyData
    });
    if (response.ok == true) {
      setState(STATE.SUCCESS);
    } else {
      setState(STATE.FAILURE);
    }
    return response;
  }

And, this is what the bodyData looks like:

{
   "version": {
    "number": "2"
   },
   "title": "Another Test Page",
   "id": "425590785",
   "type": "page",
   "body": {
    "storage": {
     "value": "<ac:adf-extension><ac:adf-node type="extension"><ac:adf-attribute key="extension-type">com.atlassian.ecosystem</ac:adf-attribute><ac:adf-attribute key="extension-key">d779c7b8-da8d-4121-83f6-25e8dc2ebcf8/6609dffc-eddc-4ca7-98c8-1db3567c0d3c/static/confluence-crawler-app</ac:adf-attribute><ac:adf-attribute key="parameters"><ac:adf-parameter key="local-id">de306e10-3855-497d-8e74-264278fe0381</ac:adf-parameter><ac:adf-parameter key="extension-id">ari:cloud:ecosystem::extension/d779c7b8-da8d-4121-83f6-25e8dc2ebcf8/6609dffc-eddc-4ca7-98c8-1db3567c0d3c/static/confluence-crawler-app</ac:adf-parameter><ac:adf-parameter key="extension-title">Confluence Crawler (Development)</ac:adf-parameter></ac:adf-attribute><ac:adf-attribute key="text">Confluence Crawler (Development)</ac:adf-attribute><ac:adf-attribute key="layout">default</ac:adf-attribute></ac:adf-node><ac:adf-fallback><ac:adf-node type="extension"><ac:adf-attribute key="extension-type">com.atlassian.ecosystem</ac:adf-attribute><ac:adf-attribute key="extension-key">d779c7b8-da8d-4121-83f6-25e8dc2ebcf8/6609dffc-eddc-4ca7-98c8-1db3567c0d3c/static/confluence-crawler-app</ac:adf-attribute><ac:adf-attribute key="parameters"><ac:adf-parameter key="local-id">de306e10-3855-497d-8e74-264278fe0381</ac:adf-parameter><ac:adf-parameter key="extension-id">ari:cloud:ecosystem::extension/d779c7b8-da8d-4121-83f6-25e8dc2ebcf8/6609dffc-eddc-4ca7-98c8-1db3567c0d3c/static/confluence-crawler-app</ac:adf-parameter><ac:adf-parameter key="extension-title">Confluence Crawler (Development)</ac:adf-parameter></ac:adf-attribute><ac:adf-attribute key="text">Confluence Crawler (Development)</ac:adf-attribute><ac:adf-attribute key="layout">default</ac:adf-attribute></ac:adf-node></ac:adf-fallback></ac:adf-extension><table><tr><td>Matched String</td><td>URL</td></tr><tr><td>Test</td><td>/spaces/ROOT/overview</td></tr><tr><td>Something</td><td>/spaces/ROOT/pages/323813377/Test+Page</td></tr></table>",
     "representation": "storage"
    }
   }
  }

At this point I’m really out of ideas as far as what exactly is going wrong, or what I need to do to fix this. If anyone has any ideas it would be greatly appreciated!

Thanks!

Hi @JimmySeddon,

Just a wild guess as that’s the only thing that stood out to me. In your body you have:

"version": {
    "number": "2"
}

But I’m pretty sure the version number needs to be a number and not a string. So, can you try:

"version": {
    "number": 2
}

Excited to hear if this fixes it for you. :slight_smile:

Cheers,
Sven

EDIT: same thing for the ID I believe

Hi @sven.schatter!

I appreciate the response. I made sure both the version and the id were integer values instead of strings, but unfortunately that didn’t seem to make a difference.

Thanks for trying!
-Jimmy

1 Like

Was worth a shot! We also have a forge app that makes page edits. I just looked up the code we use to build the request body and here it is:

const buildRequestJsonBody = (page, modifiedPageContent) => {
	const requestBody = {
		'type': page.content.type,
		'version': {
			'number': page.content.version.number + 1
		},
		'title': page.content.title,
		'body': {
			'editor': {
				'value': JSON.stringify(modifiedPageContent),
				'representation': 'atlas_doc_format'
			}
		}
	};

	return JSON.stringify(requestBody);
};

...

requestConfluence(url, {
	method: 'PUT',
	body: buildRequestJsonBody(page, updatedPageContent)
});

What I’m noticing is that we’re JSON.stringifying the body. It looks like you’re not doing that. Maybe that’s the issue?

Cheers,
Sven

2 Likes

Hey @sven.schatter!

Thank you very much for posting that example. I noticed that it differs from what is listed in the Forge example of the API documentation. I modified my function that builds the requestBody, to match more closely to your example, and that did it!

I’ve got the results publishing so everything is working the way I want.

I really appreciate all of your help with this. Have a great rest of the week!
-Jimmy

2 Likes