I am using the shell script provided in Using the Confluence REST API to upload an attachment to one or more pages | Confluence | Atlassian Documentation to attach images to a certain confluence page. However, when I run the entire script as a whole on my terminal, I am getting this error: cat: target_page_id.txt: No such file or directory. I double checked the page id I provided and found it to be correct. What is this error due to? Please help me out
Hi @samarth adhikari Welcome to the Atlassian Community!
As mentioned in the document - have you created a text file named target_page_id.txt and added list of page IDs in it ? Looks like the file doesn't exist or it is not present at the path you mentioned in the script.
Thanks @Kishan Sharma for your response! Yes now I created a text file and added the page ID to it and it seems to be reading it. However getting these errors for the following lines:
1) Line: ATTACHMENT_TITLE=$(curl -u $USER_NAME:$USER_PASSWORD \ -X POST \ -H "X-Atlassian-Token: nocheck" -F "file=@${ATTACHMENT_FILE_NAME}" -F "comment=File attached via REST API" \ ${CONFLUENCE_BASE_URL}/rest/api/content/${PAGE_ID}/child/attachment 2>/dev/null \ | jq -r '.results[].title')
Error: jq: command not found
2) if [ ${ATTACHMENT_TITLE} = ${ATTACHMENT_FILE_NAME} ]; then
Error: [: =: unary operator expected
This is the same code given on the page so not sure how these lines are erroring out?
Also, can that same script be used to attach text to a page? I would like to attach test next to an image I upload in a page
Great that you got it working @samarth adhikari
Once you install jq, you should not see jq command related errors. You can download and install jq from https://stedolan.github.io/jq/ or else you can modify the code in your preferred coding language.
For adding text to a page you will need to first get content using GET /rest/api/content and then PUT /rest/api/content/{contentId} to update the content of the page. You can refer documentation on this link.
It looks like you're new here. Sign in or register to get started.