Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

I need a script to automatically upload files to a page.

Michael Nicoletti June 21, 2019

I recently started generating automatic reports for my day-to-day task.  There are 7-8 reports throughout the day and I find it cumbersome to manually upload each one as needed.  The files are all dumped to the same location on a Windows reporting server which can be accessed by other systems.

Is there a Powershell script, or similar, that I can use to schedule the upload of these files into a page that has been created for me?

Please keep in mind that I have no experience using Confluence beyond creating pages.

Any/all help would be greatly appreciated.

1 answer

0 votes
Deleted user June 21, 2019

Hi Michael,

 

If you're familiar with the REST API, here is an example provided in the Confluence REST documentation:

 

curl -v -S -u admin:admin -X POST -H "X-Atlassian-Token: no-check" -F "file=@myfile.txt" -F
"comment=this is my file" "http://localhost:8080/confluence/rest/api/content/3604482/child/attachment"
| python -mjson.tool 

 Obviously, you'll need to substitute the variables in your case.

Michael Nicoletti June 21, 2019

Devin,

 

Thank you very much for your response.  I, unfortunately, am not well versed with REST API at all.

I can get by with Powershell scripting, but beyond that I am very novice in terms of programming and other forms of code.

I am guessing that this question is more involved that I originally thought?

Deleted user June 21, 2019

No worries. So I can try and help bridge the gap between the 2 a little bit, but you'll have to figure out the exact commands. I'm not a powershell user. 

Here is a link to some examples of REST: https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/

Here is a link to using curl in powershell: https://superuser.com/questions/344927/powershell-equivalent-of-curl

 

The idea is you can somehow include that REST call, which happens to be currently wrapped in bash, and call it in your powershell script. 

It basically lets you interact with Confluence via the command line with more functionality than usual. When you POST the following

http://localhost:8080/confluence/rest/api/content/3604482/child/attachment

you would substitute your Confluence URL for the localhost:8080, and that "3604482" is the content id, which also needs to be substituted.

 

So you'd have to obtain the file or location in the directory, and include that, along with the username and password you use to log into Confluence, make the REST call, which will upload the attachment for you. the last thing you need is the content id, mentioned above. You need to get that from the page you're uploading theses attachments to. If it's the same page, it won't change, if it's different pages, you'll have to figure out how to script that. You should be able to google how to get content id. 

 

Now you have to script that. So I'll leave that to you, but in the script you could go through the directory, and put the file name as a variable that changes once you've uploaded the file, and loop through the directory. If you're having trouble, try and get it to work outside of Powershell. Play with the REST and upload an attachment. Once you get that working, you'll hopefully be able to figure out how to use that in the script.

Michael Nicoletti June 21, 2019

Devin,

 

Thank you!  I will continue to read and follow the  verbiage through the links you provided.

Kim Britt July 25, 2022

I am not an admin. Is there an API upload tool that can be used by regular users? 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events