<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed><type>rich</type><version>1.0</version><provider_name>phorkie</provider_name><provider_url>https://p.cweiske.de/</provider_url><title>Atlassian access tokens and REST API endpoints </title><author_name>Christian Weiske</author_name><cache_age>86400</cache_age><width>900</width><height>900</height><html>&lt;!-- embedding all files of https://p.cweiske.de/969 --&gt;
&lt;link rel="stylesheet" href="https://p.cweiske.de/css/embed.css"/&gt;
&lt;div class="phork" id="969"&gt;
    &lt;div class="phork-file"&gt;
 &lt;div class="phork-content"&gt;
  
&lt;div class="document"&gt;


&lt;p&gt;Atlassian's cloud products have REST APIs, but accessing them with tokens is a major pain - the base URL is different depending on the token type, and confluence API v2 documentation misses the API prefix.&lt;/p&gt;
&lt;div class="section" id="scoped-vs-unscoped-tokens"&gt;
&lt;h1&gt;Scoped vs. unscoped tokens&lt;/h1&gt;
&lt;p&gt;Access tokens created via &lt;a class="reference external" href="https://id.atlassian.com/manage-profile/security/api-tokens"&gt;https://id.atlassian.com/manage-profile/security/api-tokens&lt;/a&gt; come in two flavors: scoped and unscoped.&lt;/p&gt;
&lt;p&gt;When using an unscoped token, you have to use &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;https://customername.atlassian.net/&lt;/span&gt;&lt;/tt&gt; as API domain.&lt;/p&gt;
&lt;p&gt;Scoped tokens need a different domain and path: &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;https://api.atlassian.com/ex/confluence/&amp;lt;cloudid&amp;gt;/&lt;/span&gt;&lt;/tt&gt;.
Cloud ID can be found at &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;https://customername.atlassian.net/_edge/tenant_info&lt;/span&gt;&lt;/tt&gt;.&lt;/p&gt;
&lt;p&gt;Source: &lt;a class="reference external" href="https://support.atlassian.com/confluence/kb/scoped-api-tokens-in-confluence-cloud"&gt;https://support.atlassian.com/confluence/kb/scoped-api-tokens-in-confluence-cloud&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="rest-api-v1-vs-v2"&gt;
&lt;h1&gt;REST API v1 vs. v2&lt;/h1&gt;
&lt;p&gt;Links:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Confluence Spaces REST API v1: &lt;a class="reference external" href="https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-space/"&gt;https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-space/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Confluence Spaces REST API v2: &lt;a class="reference external" href="https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-space/"&gt;https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-space/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Documentation for v1 lists the whole path: &lt;tt class="docutils literal"&gt;POST /wiki/rest/api/space&lt;/tt&gt;. Just use the base URL + the path used here, e.g. &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;https://customername.atlassian.net/wiki/rest/api/space&lt;/span&gt;&lt;/tt&gt;.&lt;/p&gt;
&lt;p&gt;Documentation for v2 misses some crucial bits, it only lists &lt;tt class="docutils literal"&gt;GET /spaces&lt;/tt&gt;. Appending that to the base URL will yield a 404.
The solution is to put &lt;tt class="docutils literal"&gt;/wiki/api/v2/&lt;/tt&gt; between the base URL and the path given in the docs: &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;https://customername.atlassian.net/wiki/api/v2/spaces&lt;/span&gt;&lt;/tt&gt;.&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;v1 path: &lt;tt class="docutils literal"&gt;/wiki/rest/api/&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;v2 path: &lt;tt class="docutils literal"&gt;/wiki/api/v2/&lt;/tt&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Passing tokens via HTTP Basic Auth is possible in REST API v1 &lt;em&gt;and&lt;/em&gt; v2.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="spaces-api-example"&gt;
&lt;h1&gt;Spaces API example&lt;/h1&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;v1 + unscoped token: &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;https://customername.atlassian.net/wiki/rest/api/space&lt;/span&gt;&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;v1 + scoped token: &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;https://api.atlassian.com/ex/confluence/&amp;lt;cloudid&amp;gt;/wiki/rest/api/space&lt;/span&gt;&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;v2 + unscoped token: &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;https://customername.atlassian.net/wiki/api/v2/spaces&lt;/span&gt;&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;v2 + scoped token: &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;https://api.atlassian.com/ex/confluence/&amp;lt;cloudid&amp;gt;/wiki/api/v2/spaces&lt;/span&gt;&lt;/tt&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;

 &lt;/div&gt;
 &lt;div class="phork-meta"&gt;
  &lt;a href="https://p.cweiske.de/969/rev-raw/aa66b403c47bc7f07f4281fe260f8a6b89d23c22/README.rst" style="float: right"&gt;view raw source&lt;/a&gt;
  &lt;a href="https://p.cweiske.de/969#README.rst"&gt;README.rst&lt;/a&gt;
 &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</html></oembed>
