# Atlassian API Endpoints - Complete Reference
**For:** AImpress Ltd Setup (Weeks 2-5)
**Date:** December 4, 2025
**Plan Version:** v3.0

---

## 📋 Overview

All endpoints used for remaining tasks:
- **Week 2:** Confluence spaces creation (4 API calls)
- **Week 3:** Automation rules, workflows (mostly UI, limited API)
- **Week 4:** Data import (CSV + manual mapping)
- **Week 5:** Training (no API)

---

## 🟦 WEEK 2: Confluence Spaces

### 2.1 Create Confluence Space

**Endpoint:** `POST /wiki/rest/api/space`

```bash
curl -s -X POST \
  "https://ai-impress.atlassian.net/wiki/rest/api/space" \
  -H "Authorization: Basic ${JIRA_AUTH}" \
  -H "Content-Type: application/json" \
  -d '{
    "key": "WIKI",
    "name": "Company Wiki",
    "description": {
      "plain": {
        "value": "Company handbook, policies, and SOPs"
      }
    },
    "type": "global"
  }'
```

**Required 4 spaces:**
1. WIKI - Company Wiki
2. PRODOCS - Product Documentation
3. MARKET - Sales Playbook
4. SUPPORT - Help Center

---

### 2.2 Get All Spaces

**Endpoint:** `GET /wiki/rest/api/space`

```bash
curl -s -X GET \
  "https://ai-impress.atlassian.net/wiki/rest/api/space" \
  -H "Authorization: Basic ${JIRA_AUTH}"
```

**Query Parameters:**
- `limit` - Number of spaces to return (default: 25, max: 250)
- `start` - Pagination start position
- `keys` - Comma-separated list of keys to fetch

---

### 2.3 Get Specific Space

**Endpoint:** `GET /wiki/rest/api/space/{space_key}`

```bash
curl -s -X GET \
  "https://ai-impress.atlassian.net/wiki/rest/api/space/WIKI" \
  -H "Authorization: Basic ${JIRA_AUTH}"
```

---

### 2.4 Create Page in Space

**Endpoint:** `POST /wiki/rest/api/pages`

```bash
curl -s -X POST \
  "https://ai-impress.atlassian.net/wiki/rest/api/pages" \
  -H "Authorization: Basic ${JIRA_AUTH}" \
  -H "Content-Type: application/json" \
  -d '{
    "spaceId": "<space_id_from_2.2>",
    "status": "current",
    "title": "Getting Started",
    "body": {
      "representation": "storage",
      "value": "<p>Welcome to AImpress</p>"
    },
    "parentId": null
  }'
```

---

### 2.5 Update Page

**Endpoint:** `PUT /wiki/rest/api/pages/{page_id}`

```bash
curl -s -X PUT \
  "https://ai-impress.atlassian.net/wiki/rest/api/pages/{page_id}" \
  -H "Authorization: Basic ${JIRA_AUTH}" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "<page_id>",
    "status": "current",
    "title": "Updated Title",
    "spaceId": "<space_id>",
    "body": {
      "representation": "storage",
      "value": "<p>Updated content</p>"
    },
    "version": {
      "number": 1
    }
  }'
```

---

### 2.6 Get Page Content

**Endpoint:** `GET /wiki/rest/api/pages/{page_id}`

```bash
curl -s -X GET \
  "https://ai-impress.atlassian.net/wiki/rest/api/pages/{page_id}?body-format=storage" \
  -H "Authorization: Basic ${JIRA_AUTH}"
```

---

### 2.7 Delete Page

**Endpoint:** `DELETE /wiki/rest/api/pages/{page_id}`

```bash
curl -s -X DELETE \
  "https://ai-impress.atlassian.net/wiki/rest/api/pages/{page_id}" \
  -H "Authorization: Basic ${JIRA_AUTH}"
```

---

### 2.8 Create Page Template

**Endpoint:** `POST /wiki/rest/api/templates`

```bash
curl -s -X POST \
  "https://ai-impress.atlassian.net/wiki/rest/api/templates" \
  -H "Authorization: Basic ${JIRA_AUTH}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Meeting Notes",
    "spaceId": "<space_id>",
    "body": {
      "representation": "storage",
      "value": "<h1>Meeting Notes</h1><p>Date: {{date}}</p><p>Attendees: </p><p>Topics: </p>"
    }
  }'
```

---

## 🔧 WEEK 3: Workflows & Automation

### 3.1 Get Project Workflows

**Endpoint:** `GET /rest/api/3/project/{project_key}/workflows`

```bash
curl -s -X GET \
  "https://ai-impress.atlassian.net/rest/api/3/project/PROD/workflows" \
  -H "Authorization: Basic ${JIRA_AUTH}"
```

---

### 3.2 Create Workflow (Team-Managed)

⚠️ **LIMITATION:** Cannot create workflows via API for team-managed projects.

**Workaround:** Use UI or Jira Automation rules

---

### 3.3 Get Issue Transitions

**Endpoint:** `GET /rest/api/3/issue/{issue_key}/transitions`

```bash
curl -s -X GET \
  "https://ai-impress.atlassian.net/rest/api/3/issue/PROD-1/transitions" \
  -H "Authorization: Basic ${JIRA_AUTH}"
```

---

### 3.4 Transition Issue

**Endpoint:** `POST /rest/api/3/issue/{issue_key}/transitions`

```bash
curl -s -X POST \
  "https://ai-impress.atlassian.net/rest/api/3/issue/PROD-1/transitions" \
  -H "Authorization: Basic ${JIRA_AUTH}" \
  -H "Content-Type: application/json" \
  -d '{
    "transition": {
      "id": "11"  # Get from transitions endpoint
    },
    "fields": {
      "customfield_10110": {
        "value": "Website"
      }
    }
  }'
```

---

### 3.5 Create Automation Rule

⚠️ **LIMITATION:** NO API - Must configure via UI

**UI Path:** Project Settings → Automation → Rules

**Examples needed:**
- Auto-assign on creation
- Auto-transition on specific field change
- Email notifications
- SLA escalation
- Lead scoring

---

### 3.6 Get Automation Rules

**Endpoint:** `GET /rest/api/3/automation/project/{project_key}/rules`

```bash
curl -s -X GET \
  "https://ai-impress.atlassian.net/rest/api/3/automation/project/PROD/rules" \
  -H "Authorization: Basic ${JIRA_AUTH}"
```

---

## 📊 WEEK 3: Dashboard Gadgets

### 3.7 Add Gadget to Dashboard

**Endpoint:** `POST /rest/api/3/dashboard/{dashboard_id}/gadget`

```bash
curl -s -X POST \
  "https://ai-impress.atlassian.net/rest/api/3/dashboard/{dashboard_id}/gadget" \
  -H "Authorization: Basic ${JIRA_AUTH}" \
  -H "Content-Type: application/json" \
  -d '{
    "moduleKey": "com.atlassian.jira.gadgets:filter-results",
    "position": {
      "column": 1,
      "row": 0
    },
    "config": [
      {
        "key": "filterId",
        "value": "{filter_id}"
      }
    ]
  }'
```

**Common Gadget Types:**
- `com.atlassian.jira.gadgets:filter-results` - Issue list
- `com.atlassian.jira.gadgets:issue-statistics` - Stats
- `com.atlassian.jira.gadgets:sprint-health` - Sprint progress
- `com.atlassian.jira.gadgets:burndown` - Burndown chart

---

### 3.8 Get Dashboard

**Endpoint:** `GET /rest/api/3/dashboard/{dashboard_id}`

```bash
curl -s -X GET \
  "https://ai-impress.atlassian.net/rest/api/3/dashboard/{dashboard_id}" \
  -H "Authorization: Basic ${JIRA_AUTH}"
```

---

### 3.9 Update Dashboard

**Endpoint:** `PUT /rest/api/3/dashboard/{dashboard_id}`

```bash
curl -s -X PUT \
  "https://ai-impress.atlassian.net/rest/api/3/dashboard/{dashboard_id}" \
  -H "Authorization: Basic ${JIRA_AUTH}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Updated Dashboard Name",
    "description": "New description"
  }'
```

---

### 3.10 Remove Gadget from Dashboard

**Endpoint:** `DELETE /rest/api/3/dashboard/{dashboard_id}/gadget/{gadget_id}`

```bash
curl -s -X DELETE \
  "https://ai-impress.atlassian.net/rest/api/3/dashboard/{dashboard_id}/gadget/{gadget_id}" \
  -H "Authorization: Basic ${JIRA_AUTH}"
```

---

## 📥 WEEK 4: Data Import (Odoo → Jira)

### 4.1 Export Contacts from Odoo

⚠️ **NOT ATLASSIAN API** - Odoo ERP

**Odoo REST API Endpoint:** `GET /api/res.partner`

```bash
curl -s -X GET \
  "https://odoo.ai-impress.com/api/res.partner?fields=name,email,phone,company_name" \
  -H "Authorization: Bearer ${ODOO_TOKEN}"
```

---

### 4.2 Create Issue (Lead) in Jira

**Endpoint:** `POST /rest/api/3/issue`

```bash
curl -s -X POST \
  "https://ai-impress.atlassian.net/rest/api/3/issue" \
  -H "Authorization: Basic ${JIRA_AUTH}" \
  -H "Content-Type: application/json" \
  -d '{
    "fields": {
      "project": {
        "key": "MARK"
      },
      "summary": "Acme Corporation",
      "description": "Lead from Odoo import",
      "issuetype": {
        "name": "Lead"
      },
      "customfield_10119": "contact@acme.com",
      "customfield_10120": "+44 20 7946 0958",
      "customfield_10118": "Acme Corp",
      "customfield_10111": {
        "value": "New"
      },
      "customfield_10110": {
        "value": "Referral"
      }
    }
  }'
```

**Field Mapping (Odoo → Jira Custom Fields):**
- `summary` ← Odoo `name`
- `customfield_10119` ← Odoo `email` (Contact Email)
- `customfield_10120` ← Odoo `phone` (Contact Phone)
- `customfield_10118` ← Odoo `company_name` (Company Name)
- `customfield_10111` ← Map Odoo tags to Lead Status
- `customfield_10110` ← Lead Source (default: "Referral")

---

### 4.3 Bulk Create Issues

**Endpoint:** `POST /rest/api/3/issue/bulk`

```bash
curl -s -X POST \
  "https://ai-impress.atlassian.net/rest/api/3/issue/bulk" \
  -H "Authorization: Basic ${JIRA_AUTH}" \
  -H "Content-Type: application/json" \
  -d '{
    "issues": [
      {
        "fields": {
          "project": {"key": "MARK"},
          "summary": "Lead 1",
          "issuetype": {"name": "Lead"},
          "customfield_10119": "lead1@example.com"
        }
      },
      {
        "fields": {
          "project": {"key": "MARK"},
          "summary": "Lead 2",
          "issuetype": {"name": "Lead"},
          "customfield_10119": "lead2@example.com"
        }
      }
    ]
  }'
```

---

### 4.4 Search Issues (Verify Import)

**Endpoint:** `GET /rest/api/3/search`

```bash
curl -s -X GET \
  'https://ai-impress.atlassian.net/rest/api/3/search?jql=project=MARK&fields=key,summary,customfield_10119&maxResults=50' \
  -H "Authorization: Basic ${JIRA_AUTH}"
```

---

### 4.5 Link Issues (Connect Lead → Opportunity → Client)

**Endpoint:** `POST /rest/api/3/issueLink`

```bash
curl -s -X POST \
  "https://ai-impress.atlassian.net/rest/api/3/issueLink" \
  -H "Authorization: Basic ${JIRA_AUTH}" \
  -H "Content-Type: application/json" \
  -d '{
    "type": {
      "name": "relates to"
    },
    "inwardIssue": {
      "key": "MARK-101"
    },
    "outwardIssue": {
      "key": "MARK-102"
    }
  }'
```

---

## 👥 ADDITIONAL: User & Permission Management

### 5.1 Get All Users

**Endpoint:** `GET /rest/api/3/users/search`

```bash
curl -s -X GET \
  "https://ai-impress.atlassian.net/rest/api/3/users/search?maxResults=50" \
  -H "Authorization: Basic ${JIRA_AUTH}"
```

---

### 5.2 Invite User to Site

**Endpoint:** `POST /rest/api/3/invite`

```bash
curl -s -X POST \
  "https://ai-impress.atlassian.net/rest/api/3/invite" \
  -H "Authorization: Basic ${JIRA_AUTH}" \
  -H "Content-Type: application/json" \
  -d '{
    "emailAddress": "newuser@ai-impress.com",
    "displayName": "New User"
  }'
```

---

### 5.3 Assign Project Role

**Endpoint:** `POST /rest/api/3/project/{project_key}/role/{role_id}/user`

⚠️ **LIMITATION:** Team-managed projects don't support programmatic role assignment. Use UI instead.

---

## 📝 Complete Endpoint Reference Table

| Task | Method | Endpoint | Status |
|------|--------|----------|--------|
| Create Confluence Space | POST | `/wiki/rest/api/space` | ✅ Full API |
| Get Spaces | GET | `/wiki/rest/api/space` | ✅ Full API |
| Create Page | POST | `/wiki/rest/api/pages` | ✅ Full API |
| Update Page | PUT | `/wiki/rest/api/pages/{id}` | ✅ Full API |
| Get Page | GET | `/wiki/rest/api/pages/{id}` | ✅ Full API |
| Delete Page | DELETE | `/wiki/rest/api/pages/{id}` | ✅ Full API |
| Create Template | POST | `/wiki/rest/api/templates` | ✅ Full API |
| Get Workflows | GET | `/rest/api/3/project/{key}/workflows` | ⚠️ Read-only |
| Transition Issue | POST | `/rest/api/3/issue/{key}/transitions` | ✅ Full API |
| Get Automations | GET | `/rest/api/3/automation/project/{key}/rules` | ⚠️ Read-only |
| Add Gadget | POST | `/rest/api/3/dashboard/{id}/gadget` | ✅ Full API |
| Get Dashboard | GET | `/rest/api/3/dashboard/{id}` | ✅ Full API |
| Update Dashboard | PUT | `/rest/api/3/dashboard/{id}` | ✅ Full API |
| Remove Gadget | DELETE | `/rest/api/3/dashboard/{id}/gadget/{id}` | ✅ Full API |
| Create Issue | POST | `/rest/api/3/issue` | ✅ Full API |
| Bulk Create | POST | `/rest/api/3/issue/bulk` | ✅ Full API |
| Search Issues | GET | `/rest/api/3/search` | ✅ Full API |
| Link Issues | POST | `/rest/api/3/issueLink` | ✅ Full API |
| Get Users | GET | `/rest/api/3/users/search` | ✅ Full API |
| Invite User | POST | `/rest/api/3/invite` | ✅ Full API |

---

## 🔐 Authentication

All endpoints use Basic Auth:

```bash
export JIRA_EMAIL="v.samoilenko@ai-impress.com"
export JIRA_TOKEN="<your_api_token>"
export JIRA_AUTH=$(echo -n "${JIRA_EMAIL}:${JIRA_TOKEN}" | base64)

# Verify auth
curl -s -X GET \
  "https://ai-impress.atlassian.net/rest/api/3/myself" \
  -H "Authorization: Basic ${JIRA_AUTH}"
```

---

## 📚 Official Documentation Links

### Jira Cloud REST API v3
- **Base:** https://developer.atlassian.com/cloud/jira/rest/v3/
- **Issues:** https://developer.atlassian.com/cloud/jira/rest/v3/api-group-issues/
- **Workflows:** https://developer.atlassian.com/cloud/jira/rest/v3/api-group-issue-workflows/
- **Dashboards:** https://developer.atlassian.com/cloud/jira/rest/v3/api-group-dashboards/
- **Filters:** https://developer.atlassian.com/cloud/jira/rest/v3/api-group-filters/
- **Fields:** https://developer.atlassian.com/cloud/jira/rest/v3/api-group-fields/

### Confluence REST API v1
- **Base:** https://developer.atlassian.com/cloud/confluence/rest/v1/
- **Spaces:** https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-space/
- **Pages:** https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-pages/
- **Content:** https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-content/

### Automation API
- **Automation Rules:** https://developer.atlassian.com/cloud/jira/rest/v3/api-group-automation/

---

## ⚠️ Known Limitations (Must Use UI)

1. **Workflows** - Cannot create/update for team-managed projects
2. **Automation Rules** - Cannot create via API
3. **Permissions** - Cannot assign roles in team-managed projects
4. **Issue Types** - Cannot create new issue types
5. **Dashboard Gadgets** - Can add, but limited configuration options
6. **SLA Policies** - Service Desk specific, UI only

---

## 🚀 Next Steps

1. **Review endpoints** in official Atlassian documentation
2. **Prioritize API automation** vs UI configuration
3. **Create scripts** for high-volume operations (bulk imports)
4. **Test** with sample data before full deployment

---

**Prepared by:** Claude Code
**Date:** December 4, 2025
**Status:** Ready for documentation review
