API Token vs Personal Access Token

Miguel P August 5, 2021

I have access to my company's Confluence page (using Confluence cloud). They want me to create an application that communicates with the Confluence API to post content in pages. 

I'm following this guide for getting started with the API: Getting started with Connect (atlassian.com)

Issue is I have no idea how to create an API token to communicate with our Confluence. My credentials for logging into my company's confluence aren't my Atlassian account credentials. So I can't just log into the API token page and create one. On the company's Confluence I did find something called Personal Access Tokens, but I'm not sure if they have the same functionality as an API token (not sure if they can be used to communicate with Confluence's REST API).

2 answers

0 votes
Peter Wein June 29, 2023

Answer is not valid anymore!

0 votes
marc -Collabello--Phase Locked-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 5, 2021

@Miguel PConnect (the Atlassian app framework) and the "normal" REST API are different things.  A connect app needs to be installed from the Atlassian Marketplace.

You can write a program using the REST API, and you don't need the Marketplace for this.  For auth with the REST API, you need to log into your Atlassian account and retrieve a token.  This token allows you to script the REST API with your access rights.

Another option is to use Oauth.

Peter Wein June 29, 2023

I have the same problem! And I absolutely did not understand your answer @marc -Collabello--Phase Locked- . Please explain yourself. I have created an atlassian account and I am able to create an "API Token" but how should this help me get into our company's own Jira Server???

 

There is as far as I know no connection between atlassian domain and our implementation of our company's own JIRA server. So  how can I connect with the "Personal Access Token" via rest api. I found an example for c#:

code c#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.Script.Serialization;
using Newtonsoft.Json;


//using System.Net.Http.Json;

namespace JIRA_SDK
{

public class JiraHelper
{
private static HttpClient _client = new HttpClient();
public static async Task<JiraTicketResponse> CreateTaskTicket(Uri jiraUri, string userName, string apiKey, string projectKey, string summary, string description)
{
var authData = System.Text.Encoding.UTF8.GetBytes($"{userName}:{apiKey}");
var basicAuthentication = Convert.ToBase64String(authData);
_client.BaseAddress = jiraUri;
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", basicAuthentication);
var data = new
{
fields = new
{
issuetype = new { id = 10002 /*Task*/ },
summary = summary,
project = new { key = projectKey /*Key of your project*/},
description = new
{
version = 1,
type = "doc",
content = new[] {
new {
type = "paragraph",
content = new []{
new {
type = "text",
text = description
}
}
}
}
}
}
};

var result = _client.PostAsync("/rest/api/3/issue", new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")).Result;
if (result.StatusCode == System.Net.HttpStatusCode.Created)
{
string jsonContent = result.Content.ReadAsStringAsync().Result;//<JiraTicketResponse>();
return JsonConvert.DeserializeObject<JiraTicketResponse>(jsonContent);
}
else
throw new Exception(await result.Content.ReadAsStringAsync());
}
}

public class JiraTicketResponse
{
public int Id { get; set; }
public string Key { get; set; }
public Uri Self { get; set; }
}
}

 

Code c#  finish. (is there a way to put formatted code in the answer? without reformatting every line?)

derived from this link

 

But I am getting an "unauthorized" result from my post request! Please help!

 

My starting page is like this:

image.png

Or is there any supported official library for C#? It should provide a method for token access. I don't need basic auth nor oauth...

marc -Collabello--Phase Locked-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 30, 2023

Hi @Peter Wein ,

It seems you are using Jira server software.  The answer I provided is for Confuence cloud.

That means my answer dos not work for Jira server!  But the answer works for Confluence cloud.

Like Matt likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events