# ScriptRunner Connect Managed API for Bitbucket On-Premise
Managed API for Bitbucket On-Premise is an API Client for Bitbucket On-Premise by [Adaptavist](https://www.adaptavist.com/). You can read more about Managed APIs [here](https://docs.adaptavist.com/src/managed-apis).

This is [ScriptRunner Connect](https://scriptrunnerconnect.com) runtime specific version of the Managed API (with `sr-connect` suffix). If you want to use Managed API in any other runtime, have a look at the [runtime agnostic version](https://www.npmjs.com/package/@managed-api/bitbucket-on-premise-v1-core).

# Supported API calls
- [fetch](https://docs.adaptavist.com/src/managed-apis/managed-api-abstractions)
- Project
    - [createProject](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp148)
    - [deleteProject](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp151)
    - [getProject](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp153)
    - [getProjects](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp149)
    - [updateProject](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp152)
- Repository
    - [createRepository](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp174)
    - [deleteRepository](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp177)
    - [getRepositories](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp175)
    - [getRepository](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp179)
    - Commit
        - [getRepositoryCommits](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp222)
        - [getCommit](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp224)
    - Pull Request
        - [changeStatus](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp345)
        - [createPullRequest](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp293)
        - [declinePullRequest](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp305)
        - [deletePullRequest](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp297)
        - [getActivities](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp303)
        - [getPullRequest](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp295)
        - [getPullRequests](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp292)
        - [mergePullRequest](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp308)
        - [reopenPullRequest](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp310)
        - [updatePullRequest](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp296)
        - Comment
            - [createComment](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp325)
            - [deleteComment](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp327)
            - [getComment](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp329)
            - [getComments](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp324)
            - [updateComment](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp328)
        - Commit
            - [getCommits](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp333)
- User
    - [createUser](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp19)
    - [deleteUser](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp18)
    - [getUsers](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp17)
    - [updateCurrentUser](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp20)

# Constructing Managed API
In ScriptRunner Connect a Managed API is constructed for you, but if you need to construct it manually, here's how you can do it:
```typescript
import { BitbucketOnPremiseApi } from '@managed-api/bitbucket-on-premise-v1-sr-connect';

export default async function() {
    const api = new BitbucketOnPremiseApi('API_CONNECTION_ID');
}
```

# Contact
Feel free to drop ideas, suggestions or improvements into our [Community hub](https://loop.scriptrunnerhq.com/c/integration-forum).

# Changelog
* 2.1.0
    - Removed non-empty body from HEAD requests.

* 2.0.0
    - `Breaking change:` URL and query string parameters are now URL encoded, meaning if you encoded them explicitly before you have to remove your own encoding, otherwise they will get double encoded.
* Added Paged API `limit`, `start` parameters for the following methods with paged response:
    - `Repository.Commit.getRepositoryCommits`
    - `Repository.getRepositories`
    - `Repository.PullRequest.getPullRequests`
    - `Repository.PullRequest.getActivities`
    - `Repository.PullRequest.Comment.getComments`
    - `Repository.PullRequest.Commit.getCommits`
    - `Project.getProjects`
* Added the following `Repository.Commit` methods:
    - [getRepositoryCommits](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp222)
    - [getCommit](https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.html#idp224)

Copyright Adaptavist 2022 (c) All rights reserved