Forums

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

Upload attachment with REST API using R package httr

ryan dickerson
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 10, 2018

I have been able to use the httr package to download the attachments from a specific confluence page with the following code

 

library(httr)
library(tidyverse)
library(glue)

req <-
GET(url = conf.url,
      accept_json(),
      authenticate(conf.user, conf.pass),
      config = config(ssl_verifypeer = FALSE))

out <- content(req)


links <- sapply(out[[1]], function(x) x$`_links`$download)
titles <- sapply(out[[1]], function(x) x$title)
# Fix links
links <- glue('{prefix}{links}&download=TRUE')

# Download all links into specific folder
map2(links, titles,
      ~download.file(.x, glue('{out.folder}\\{.y}')
                     , quiet = T))

I tried to upload an attachment with the following code

 

POST(url = url
     , authenticate(conf.user, conf.pass)
     , config = config(ssl_verifypeer = FALSE)
     , body = upload_file(glue('{folder}\\test.txt'))
     ) 

But it doesn't work. Here's what I get back

Response [redacted url with company name]
  Date: 2018-07-10 21:16
  Status: 415
  Content-Type: text/html;charset=utf-8
  Size: 1.14 kB

 Has anyone used the httr package, or R in general to upload attachments to Confluence pages?

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events