Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Confluence] Integrate with Confluence by API

Posted on January 5, 2024January 29, 2024 By nim No Comments on [Confluence] Integrate with Confluence by API

Contents

Toggle
  • 1) Prepare the token for Calling API.
  • 2) Create a page trên Confluence.
  • 3) The format is used to create pages on Confluence on API
    • 3.1) Macro Code.
    • 3.2) Table

1) Prepare the token for Calling API.

2) Create a page trên Confluence.

Trên confluence chúng ta sẽ tạo nhưng bài viết thì nó được gọi là page.

Bạn có thể tìm hiểu các API ở link bên dưới:
https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-space/#api-wiki-rest-api-space-spacekey-get
https://developer.atlassian.com/cloud/confluence/rest/v2/intro/

Đầu tiên bạn tạo page tên là report.

Giờ mình sẽ cần tạo 1 page chứa code.

# Set the title to "Integration Test Results" followed by the current date and time in YYYY-MM-DD hh:mm:ss format 
TITLE="Integration Test Results $(date '+%Y-%m-%d %H:%M:%S')"

FILE_PATH='result.txt' # path to your file

# Read the content of the file into a variable 
FILE_CONTENT=$(<"$FILE_PATH")

# Escape XML special characters in file content
XML_ESCAPED_CONTENT=$(echo "$FILE_CONTENT" | sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g')

# Wrap the XML escaped content within the Confluence structured macro syntax
ESCAPED_CONTENT="<ac:structured-macro ac:name=\"code\"><ac:plain-text-body><![CDATA[$XML_ESCAPED_CONTENT]]></ac:plain-text-body></ac:structured-macro>"

# Escape for JSON
JSON_ESCAPED_CONTENT=$(echo "$ESCAPED_CONTENT" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e ':a' -e 'N' -e '$!ba' -e 's/\n/\\n/g')

# cURL command 
curl --request POST \
  --url "https://nimtechnology.atlassian.net/wiki/api/v2/pages" \
  --user "your_email:your_api_token" \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{ 
    "spaceId": "98432", 
    "status": "current", 
    "title": "'"${TITLE}"'", 
    "parentId": "589825", 
    "body": { 
      "representation": "storage", 
      "value": "'"${JSON_ESCAPED_CONTENT}"'" 
    } 
  }'

Nếu bạn run command thì trên confluence:

3) The format is used to create pages on Confluence on API

3.1) Macro Code.

Refer to links: https://community.atlassian.com/t5/Confluence-questions/Code-Macro-via-Confluence-REST-API/qaq-p/2097123

xmlContent := fmt.Sprintf(
		"<ac:structured-macro ac:name=\"code\">\n"+
			"  <ac:plain-text-body><![CDATA[\n"+
			"    %s\n"+ // you can see some space at begin of the content, you can adjust at here
			"  ]]></ac:plain-text-body>\n"+
			"</ac:structured-macro>",
		string(data),
	)

3.2) Table

để tạo table thì bạn chỉ cần tạo html đơn giản

<table>
    <tr>
        <th>Company</th>
        <th>Contact</th>
        <th>Country</th>
    </tr>
    <tr>
        <td>Alfreds Futterkiste</td>
        <td>Maria Anders</td>
        <td>Germany</td>
    </tr>
    <tr>
        <td>Centro comercial Moctezuma</td>
        <td>Francisco Chang</td>
        <td>Mexico</td>
    </tr>
    <tr>
        <td>Ernst Handel</td>
        <td>Roland Mendel</td>
        <td>Austria</td>
    </tr>
    <tr>
        <td>Island Trading</td>
        <td>Helen Bennett</td>
        <td>UK</td>
    </tr>
    <tr>
        <td>Laughing Bacchus Winecellars</td>
        <td>Yoshi Tannamuri</td>
        <td>Canada</td>
    </tr>
    <tr>
        <td>Magazzini Alimentari Riuniti</td>
        <td>Giovanni Rovelli</td>
        <td>Italy</td>
    </tr>
</table>
Coding

Post navigation

Previous Post: [Golang] In-Memory Cache or Local Cache with Golang.
Next Post: [Grafana] Design Uptime based on Status History – Visualizations on Grafana

More Related Articles

[Windows] The helpful command on Powershell Coding
[GRPC] BloomRPC aims to provide the simplest and most efficient developer Coding
[WordPress] Tăng dung lượng upload file lên wordpress. Coding
[Private NPM] Create The Private NPM Packages Bitbucket
[Zeus] Retention Project Coding
[Bootstrap] Hide and show elements by bootstrap. Coding

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Upload File] How to upload large files and download them using curl. July 23, 2025
  • [Argo Workflow] Create an access token for Argo Workflows July 14, 2025
  • [Argo Workflow] SSO Authentication for Argo Workflows. July 14, 2025
  • [AWS/EKS] Cache Docker image to accelerate EKS container deployment. July 10, 2025
  • [Laravel] Laravel Helpful June 26, 2025

Archives

  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.