I am relatively new to the atlassian world and I am tasked with synchronizing pdf attachments (but not attachments of other types) of an issue in a certain jira project to a page on confluence. I only found means to do this manually (e.g.: see here), which is not what I am looking for.
Any help pointing me in the right direction to solve this is highly apprechiated.
You can write a script that downloads and uploads the desired attachments via the REST API of Jira/Confluence.
Get PDF attachments for specific issue:
GET {jiraBaseUrl}/rest/api/2/issue/{issueIdOrKey}
//returns:
{
...
"key": "EX-1",
"fields": {
...
"attachment": [
{
...
"mimeType": "image/jpeg",
"content": "http://www.example.com/jira/attachments/10000",
...
}
]
}
}
Where "fields > attachment > mimeType" in the result should be checked for application/pdf and "fields > attachment > content" is the URL to download the attachment. Source: Jira REST API
Upload the attachment to Confluence
POST {confluenceBaseUrl}/rest/api/content/{pageId}/child/attachment
//e.g.:
curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=#myfile.txt" -F "comment=This is my File" http://myhost/rest/api/content/123/child/attachment
Check the documentation for a complete curl example: Confluence REST API
With these two REST resources you should be able to automate your task. For authentication you can start with a simple basic authentication header.
Related
We are integrating our product with MS OneDrive. Our users will connect their MS accounts and choose a folder that they want us to pull files from. Our system only supports certain file types so we have to get the mimetype information AND the file ID after making a request. But we can't find a request that brings back both pieces of information so we can determine if we should pull a file or not.
This is close, but it doesn't give us the mimetype information.
https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/drive_recent?view=odsp-graph-online
Anyone have any ideas?
The get method lets you retrieve all kinds of information about a file: https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_get?view=odsp-graph-online
It returns a driveItem object, that has a file property. And that file property has a mimeType property. See here https://learn.microsoft.com/en-us/onedrive/developer/rest-api/resources/driveitem?view=odsp-graph-online and here https://learn.microsoft.com/en-us/onedrive/developer/rest-api/resources/file?view=odsp-graph-online.
Unfortunately that means, that you will need more than one request to get the information you want.
If filtering by filename suffix is good enough for you, you can query OneDrive like this:
POST /search/query
Content-Type: application/json
{
"requests": [
{
"entityTypes": [
"driveItem"
],
"query": {
"queryString": "filetype:docx OR filetype:doc"
}
}
]
}
Documentation: https://learn.microsoft.com/en-us/graph/search-concept-files#example-5-use-filters-in-search-queries
What is the REST API call to anonymously upload to a publicly shared folder on OneDrive?
I have tried sharing a folder both thru the OneDrive Web UI creating a link attributed with: "Anyone with this link can edit this item", and using the REST API:
POST https://graph.microsoft.com/v1.0/drives/{driveId}/items/{sharedFolderId}/createLink
Content-type: application/json
{
"type": "edit",
"scope": "anonymous"
}
In both cases, I can read from the shared folder without logging on by
GET https://api.onedrive.com/v1.0/shares/{shareId}/items/{sharedFolderId}
I can also read the permission itself using
GET https://api.onedrive.com/v1.0/shares/{shareId}/items/{sharedFolderId}/permissions
=>
{
"#odata.context":"https://api.onedrive.com/v1.0/$metadata#shares('{shareId}')/items('{sharedFolderId')/permissions",
"value":
[
{
"id":"{permissionId}",
"link":
{
"application":
{
"displayName":"{my own app}",
"id":"{short app id}"
},
"type":"edit",
"webUrl":"https://1drv.ms/u/{shareId}"
},
"roles":["write"],
"shareId":"{shareId}",
"expirationDateTime":"0001-01-01T00:00:00Z",
"hasPassword":false
}
]
}
However trying to upload a file or create a subfolder, i.e.
PUT https://api.onedrive.com/v1.0/shares/{shareId}/driveItem:/{filename}:/content
Content-type: text/plain
some text goes here
or
POST https://api.onedrive.com/v1.0/shares/{shareId}/items/{sharedFolderId}/children
Content-type: application/json
{
"name": "TestFolder",
"folder": { }
}
both fail as unauthorized calls - but isn't the whole point of an "edit" link with "anonymous" scope that "anyone with this link can edit this item"?
I have tried various combinations of https://graph.microsoft.com/v1.0 instead of https://api.onedrive.com/v1.0 and /drives/{driveId} instead of /shares/{shareId} as well as /shares/{shareToken}, where shareToken is the "u!"-encoding of the webUrl from the link in the permission.
So far without being able to figure out the right REST API call. I hope someone is able to help :-)
You can download my TestOneDrive Visual Studio test project to reproduce the issues. It also contains initialization code to create and share the folder.
Due to no guys from Product Group following this and no official docs announced this, so I suggest you to submit an feature request first on UserVocie or vote up an existing one close to your issue.
I am trying to "clone" a message from a user's mailbox to create a copy in a different mailbox. I could successfully use "create message" API by "cloning" a messages's parts into new message including attachments. However, considering 4MB limitation on REST payload, messages that are with larger than 4MB are rejected. So, wondering if there is a way to include attachment by attachment id or contentId instead of downloading and uploading as the attachment is already available on the server.
According to your description, I assume you want to add attachment to a message.
Based on my test, we can use this API to implement it.
'POST /users/{id | userPrincipalName}/messages/{id}/attachments'
The request body is a JSON representation of Attachment object like this:
{
"contentType": "string",
"id": "string (identifier)", // attachment id
"isInline": true,
"lastModifiedDateTime": "String (timestamp)",
"name": "string",
"size": 1024
}
For more detail, we can refer to this document.
Just in case you have not found the answer.
Using the Microsoft Graph API, you can attach files up to 150 MB to an Outlook message or event item. Depending on the file size, choose one of two ways to attach the file:
If the file size is under 3 MB, do a single POST on the attachments navigation property of the Outlook item; see how to do this for a message or for an event. The successful POST response includes the ID of the file attachment.
If the file size is between 3MB and 150MB, create an upload session, and iteratively use PUT to upload ranges of bytes of the file until you have uploaded the entire file. A header in the final successful PUT response includes a URL with the attachment ID.
Please refer to this article for more details:
https://learn.microsoft.com/en-us/graph/outlook-large-attachments?tabs=http
I'm migrating a number of projects from one JIRA instance to another using JSON importer. Although the importer can assign issues to existing sprints, the sprints themselves must already exist -- a limitation of the current version of JIRA Importer.
We've been creating sprints by hand 'till now, but some of our projects have a large number of them, which make the manual process both tedious and error-prone.
It does not appear like JIRA REST API can create new sprints either -- although people talk about the greenhopper/1.0/sprint/create endpoint, it does not exist.
Is there, perhaps, some other way to create sprints programmatically? I have no problems with obtaining the full list of them from the source JIRA instance, it is creating them in the target instance, that does not seem possible...
Any hope? Can I INSERT new records into the AO_60DB71_SPRINT-table with a SQL-client? Thanks!
This can be done using the JIRA Agile API. See JIRA Agile REST API Reference
So, for example using curl:
## Request JIRA Sprint POST Create
curl -X "POST" "https://jira.foobar.com/rest/agile/1.0/sprint" \
-H 'Content-Type: application/json' \
-u 'myusername:mypassword' \
-d $'{
"startDate": "2018-04-23T00:00:00.000+01:00",
"name": "Cool Sprint",
"endDate": "2018-05-03T13:00:00.000+01:00",
"originBoardId": 1072
}'
The response of which would be:
{
"id": 1130,
"self": "https://jira.foobar.com/rest/agile/1.0/sprint/1130",
"state": "future",
"name": ""Cool Sprint",
"startDate": "2018-04-23T01:00:00.000+02:00",
"endDate": "2018-05-03T14:00:00.000+02:00",
"originBoardId": 1072
}
I'm trying to use the jira-ruby Gem to interface with a remote JIRA server with 5.x REST API.
Accessing data on the server works well, but it seems I can not create a new JIRA issue remotely. The Gem's documentation is minimal, and there are no examples provided.
Can somebody provide a working example on:
how to create a remote JIRA Issue with ruby-jira
how to attach a file to an existing Issue
To create new JIRA Issue use:
CODE:
issue = client.Issue.build
issue.save({"fields"=>{"summary"=>"blarg from in example.rb","project"=>{"id"=>"10001"},"issuetype"=>{"id"=>"3"}}})
issue.fetch
pp issue
Or
You can try REST APIs to create JIRA Issue.
Using IDs
The first example creates an issue by specifying the project ID and issue type ID.
Request
curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json" http://localhost:8090/rest/api/2/issue/
Data
Here's the JSON:
{
"fields": {
"project":
{
"id": "10110"
},
"summary": "No REST for the Wicked.",
"description": "Creating of an issue using ids for projects and issue types using the REST API",
"issuetype": {
"id": "1"
}
}
}
Response
The response provides the issue ID, issue key, and the URL to the issue (which can then be used to GET additional data, PUT updates, etc).
{
"id":"39001",
"key":"TEST-102",
"self":"http://localhost:8090/rest/api/2/issue/TEST-102"
}
Using Project Key and Field Names
Alternatively, you can create an issue by specifying the project key and field names.
Request
curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json" http://localhost:8090/rest/api/2/issue/
Data
{
"fields": {
"project":
{
"key": "TEST"
},
"summary": "REST ye merry gentlemen.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
}
}
}
Response
{
"id":"39000",
"key":"TEST-101",
"self":"http://localhost:8090/rest/api/2/issue/TEST-101"
}
Source: https://developer.atlassian.com/display/JIRADEV/JIRA+REST+APIs