You can manage your Confluence shares via web API by generating API Key. To do this, perform the following steps:
Go to External Share for Confluence admin panel and click on API Keys tab. This will send you to screen with all previously generated keys.
Click on Create new API key. API key creation popup will appear.
Setup your API key and copy or download it. The template has the following fields:
Key Name - provide your own name for the API key, up to 40 characters long.
Key Value - non-modifable field, shows value of the key.
Reveal - reveals key. This is NOT one time operation - you can reveal the key at any time.
Download - downloads the key to the selected location.
Get Shares - determines whether get operation is allowed for the key.
List Shares - determines whether list operation is allowed for the key.
Create Shares - determines whether create operation is allowed for the key.
Not valid before - set the start date for key validity.
Not valid after - set the invalidation date for the key.
Allowed IPs - set IPs or IP range that can use the key.
Description - description of the key. Maximum 4000 characters.
Creation Time - non-modifable field, time when the key was created.
Last Modification Time - non-modifable field, time when the key was last modified.
Last Usage Time - non-modifable field, time when the key was last used.
Usage Count - non-modifable field, counter that shows how many times the key was used.
Using the Web API with API key
With key generated, you can now make a call to Web API. First of, set Authorization and Content-Type headers in your REST client.
Code Block |
---|
Authorization: 'Bearer { KEY_VALUE }'
Content-Type: 'application/json' |
With headers set, you can now perform operations selected from among the following: GET, LIST, CREATE.
GET OPERATION
This operation allows you to retrieve a single share based on share uuid. This operation does not accept any additional options and returns JSON with Share data.
Example Call:
Code Block |
---|
GET https://confluence.external-share.com/webapi/share/{ SHARE_UUID } |
LIST OPERATION
This operation allows you to retrieve a sorted list of shares based on options passed. You need to have an access to shared issues to be able to list shares. You can pass the following options as request parameters:
sort - share field by which the list will be sorted. The default value is “id”. In general, you can sort by any Share’s field as long as it is in a snake_case instead of camelCase. For example, you can sort by Issue ID, by passing “issue_id” (instead of issueId as returned in the JSON).
sortOrder - order in which list will be sorted. Pass “asc” for ascending list; “desc” for descending list. “asc” is default.
limit - defines how many shares will be returned in a single call. Default is 100.
offset - defines how many positions from the start of the list will be ommited. Combined with limit parameter, this parameter may be helpful in performing concurrent calls. The default value is 0, which means the very first share on the list will be returned.
contents- returns all shares for content IDs range. Content IDs should be comma separated. Example: contents=234451,4847
spaceKeys - returns all shares in the selected spaces. Space IDs should be comma separated. Example: spaceKeys=SPACE1, ANOTHERSPACE
NOTE: If you are an administrator, you may ommit passing contents and/or spaces - this will result in returning all shares from all spaces you have admin rights. However, if you are not an administrator, the call will not be accepted and FORBIDDEN http status will be returned.
Example Call:
Code Block |
---|
GET https://confluence.external-share.com/webapi/share?sort=uuid&sortOrder=desc&contents=1123,412344 |
CREATE OPERATION
This operation allows you to create a new share. The operation requires passing request body with contentId as mandatory field.
You may also pass additional fields:
Parameter Name | Description | Default | ||
---|---|---|---|---|
name | Name of the link | External Share Link | ||
showComments | All existing comments will be visible on shared link. | false | ||
allowAddComment | Anyone with access to the link can add comments. | false | ||
showAttachments | All existing attachments will be visible on shared link. | false | ||
allowAddAttachment | Anyone with access to the link can add attachments. | false | ||
allowRemoveUnsupportedMacros | Unsupported macros will be removed from the Share | false | ||
showMacrosPlaceholder | Unsupported macros will be replaced with placeholders. | false | ||
allowShareChildPages | Child pages will be accessible with the same permissions as this parent link | false | ||
showLabels | All page labels will be visible on the Shared Link | false | ||
description | Description of the link. For internal purposes only. | null | ||
expiration | Expiration timestamp in epoch miliseconds. | null | ||
selectedUsersConfig | Pass this object to define list of users that can access the share. You can pass the following fields in this configuration:
| null |
Example Call:
Code Block |
---|
POST https://confluence.external-share.com/webapi/share
{
"contentId": "2556174",
"description": "This is internal description - not visible on share",
"name": "Name of the link - External Share Link if left empty",
"showComments": true,
"allowAddComment": false,
"showAttachments": true,
"selectedUsersConfig": {
"allowed": true,
"allowedNotification": false,
"list": [{"email": "expl@expl2.com"}, {"email": "expl@expl.com"}]
}
} |