curl --request POST \
--url https://api.example.com/api/code-hosts/{provider}/token \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"token": "<string>",
"host": "<string>",
"artifact_id": "<string>"
}
'import requests
url = "https://api.example.com/api/code-hosts/{provider}/token"
payload = {
"token": "<string>",
"host": "<string>",
"artifact_id": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({token: '<string>', host: '<string>', artifact_id: '<string>'})
};
fetch('https://api.example.com/api/code-hosts/{provider}/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/code-hosts/{provider}/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'token' => '<string>',
'host' => '<string>',
'artifact_id' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/code-hosts/{provider}/token"
payload := strings.NewReader("{\n \"token\": \"<string>\",\n \"host\": \"<string>\",\n \"artifact_id\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/code-hosts/{provider}/token")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"token\": \"<string>\",\n \"host\": \"<string>\",\n \"artifact_id\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/code-hosts/{provider}/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"token\": \"<string>\",\n \"host\": \"<string>\",\n \"artifact_id\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"provider": "<string>",
"label": "<string>",
"connected": true,
"host": "",
"for_this_repository": false,
"can_sign_in": false,
"account": "",
"needs_reconnect": false,
"connected_at": "<string>"
}{
"error": "<string>",
"code": 500
}{
"error": "<string>",
"code": 500
}{
"error": "<string>",
"code": 500
}{
"error": "<string>",
"code": 500
}Connect with your own token
Connect by pasting a token you made at the host yourself.
Works for every host with nothing to set up first, which is why it is here beside the OAuth flow. The token is checked against the host before it is stored, and it is only ever used for your own reads.
curl --request POST \
--url https://api.example.com/api/code-hosts/{provider}/token \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"token": "<string>",
"host": "<string>",
"artifact_id": "<string>"
}
'import requests
url = "https://api.example.com/api/code-hosts/{provider}/token"
payload = {
"token": "<string>",
"host": "<string>",
"artifact_id": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({token: '<string>', host: '<string>', artifact_id: '<string>'})
};
fetch('https://api.example.com/api/code-hosts/{provider}/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/code-hosts/{provider}/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'token' => '<string>',
'host' => '<string>',
'artifact_id' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/code-hosts/{provider}/token"
payload := strings.NewReader("{\n \"token\": \"<string>\",\n \"host\": \"<string>\",\n \"artifact_id\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/code-hosts/{provider}/token")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"token\": \"<string>\",\n \"host\": \"<string>\",\n \"artifact_id\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/code-hosts/{provider}/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"token\": \"<string>\",\n \"host\": \"<string>\",\n \"artifact_id\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"provider": "<string>",
"label": "<string>",
"connected": true,
"host": "",
"for_this_repository": false,
"can_sign_in": false,
"account": "",
"needs_reconnect": false,
"connected_at": "<string>"
}{
"error": "<string>",
"code": 500
}{
"error": "<string>",
"code": 500
}{
"error": "<string>",
"code": 500
}{
"error": "<string>",
"code": 500
}Authorizations
The access token received from the authorization server in the OAuth 2.0 flow.
Path Parameters
The code host's key.
Body
A token the person made at the host themselves. Write-only.
8 - 512The host this token is for, when a tenant has more than one instance of a provider. Taken from the repository's remote.
256The repository this token is for. A repository's own token wins over one that covers the whole host; leaving it out connects the host, so one token covers every repository on it.
Response
Successful Response
One person's sign-in at one host, as a page may see it.
Was this page helpful?

