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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,457,219
Community Members
 
Community Events
176
Community Groups

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

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

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.

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?

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.

Devin,

 

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

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

Atlassian Community Events