Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

PAGE ID RELATED ERROR

samarth adhikari November 2, 2021

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

1 answer

1 accepted

1 vote
Answer accepted
Kishan Sharma
Community Champion
November 3, 2021

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.

samarth adhikari November 3, 2021

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? 

samarth adhikari November 3, 2021

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

Kishan Sharma
Community Champion
November 3, 2021

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.

samarth adhikari November 3, 2021

Thanks kishan! All errors have disappeared now after I installed jq. But getting the message 'Failed to upload file to page <page ID>'. Is it to do with my credentials? I double checked my username, password, page ID and others. jq error.PNG

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events