Connect a mailbox via OAuth 2.0
Connect a new Google or Microsoft mailbox, or reconnect an existing one, by generating an authorization link for the mailbox owner. The owner opens the link in a browser and signs in with the specified address to authorize the connection to Woodpecker. Woodpecker handles the OAuth callback and starts the connection or reconnection process.
To connect mailboxes using SMTP/IMAP credentials instead, use the bulk connection endpoint.
Request
You can repeat the request with the same account, provider, and email address to generate a new authorization link and reconnect a disconnected mailbox.
Endpoint
POST https://api.woodpecker.co/rest/v2/mailboxes/oauth2/register
Headers
x-api-key: {YOUR_API_KEY}
Content-Type: application/json
For details on how to authenticate your requests, please see the authentication guide.
Body
{
"provider": "GOOGLE",
"email": "mailbox@example.com"
}
Body schema
| Field | Type | Required | Description |
|---|---|---|---|
provider | string | Yes | Mailbox provider. Use GOOGLE or MICROSOFT, with matching capitalization |
email | string | Yes | Email address of the mailbox that will be connected to Woodpecker |
Request samples
Generate an authorization link for a Google mailbox
- cURL
- Python
- Java
- Node.js
- PHP
curl --request POST \
--url "https://api.woodpecker.co/rest/v2/mailboxes/oauth2/register" \
--header "x-api-key: {YOUR_API_KEY}" \
--header "Content-Type: application/json" \
--data '{
"provider": "GOOGLE",
"email": "mailbox@example.com"
}'
import requests
def create_mailbox_authorization_link():
url = "https://api.woodpecker.co/rest/v2/mailboxes/oauth2/register"
headers = {
"x-api-key": "{YOUR_API_KEY}",
"Content-Type": "application/json"
}
payload = {
"provider": "GOOGLE",
"email": "mailbox@example.com"
}
response = requests.post(url, headers=headers, json=payload)
if response.status_code == 200:
return response.json()
raise Exception(f"POST request failed: {response.status_code}, {response.text}")
if __name__ == "__main__":
try:
print("POST response:", create_mailbox_authorization_link())
except Exception as error:
print("Error:", error)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class WoodpeckerApiClient {
public static void main(String[] args) {
try {
String url = "https://api.woodpecker.co/rest/v2/mailboxes/oauth2/register";
String jsonData = """
{
"provider": "GOOGLE",
"email": "mailbox@example.com"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("x-api-key", "{YOUR_API_KEY}")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonData))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() != 200) {
throw new IllegalStateException("POST request failed: " + response.statusCode() + ", " + response.body());
}
System.out.println("POST response: " + response.body());
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}
const axios = require('axios');
async function createMailboxAuthorizationLink() {
const url = 'https://api.woodpecker.co/rest/v2/mailboxes/oauth2/register';
const headers = {
'x-api-key': '{YOUR_API_KEY}',
'Content-Type': 'application/json'
};
const data = {
provider: 'GOOGLE',
email: 'mailbox@example.com'
};
try {
const response = await axios.post(url, data, { headers });
console.log('POST response:', response.data);
} catch (error) {
console.error('POST request failed:', error.response ? error.response.status : error.message);
}
}
createMailboxAuthorizationLink();
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
$client = new Client([
'base_uri' => 'https://api.woodpecker.co/rest/v2/',
'headers' => [
'x-api-key' => getenv('WOODPECKER_API_KEY'),
'Content-Type' => 'application/json',
],
]);
try {
$response = $client->post('mailboxes/oauth2/register', [
'json' => [
'provider' => 'GOOGLE',
'email' => 'mailbox@example.com',
],
]);
echo $response->getStatusCode(), "\n";
echo $response->getBody(), "\n";
} catch (RequestException $e) {
echo 'Error: ', $e->getMessage(), "\n";
if ($e->hasResponse()) {
echo $e->getResponse()->getBody(), "\n";
}
}
Response
Response examples
- 200
- 401
- 422
- 500
Pass the returned link to the mailbox owner and poll with the same payload until the status is CONNECTED, AUTHORIZATION_ERROR, or CONNECTION_ERROR. Check OAuth 2.0 mailbox connection status.
{
"login_url": "https://accounts.example.com/oauth2/authorize"
}
Body schema
| Field | Type | Description |
|---|---|---|
login_url | string | Authorization URL for the mailbox |
The API key is missing or invalid. Review the authentication guide.
{
"title": "Unauthorized",
"status": 401,
"detail": "Invalid api key",
"timestamp": "2026-11-23 12:00:00"
}
Body schema
| Field | Type | Description |
|---|---|---|
title | string | A short title describing the error |
status | integer | The HTTP status code |
detail | string | A detailed message explaining the error |
timestamp | string | The timestamp when the error occurred, YYYY-MM-DD HH:MM:SS UTC |
Returned when the request body is missing or contains invalid or missing fields.
{
"type": "validation_error",
"message": "Invalid field(s)",
"code": "invalid_fields",
"request_id": "1b752aaa-b067-4145-8e22-939582dfeb2c",
"fields": [
{
"field": "provider",
"issue": "required",
"value": null
}
]
}
Body schema
| Field | Type | Description |
|---|---|---|
type | string | Error type |
message | string | Error message |
code | string | Error code |
request_id | string or null | Request identifier when available |
fields | array | Fields that failed validation |
└─ field | string | Field with a validation issue |
└─ issue | string | Detailed description of the validation issue |
└─ value | string/null | Rejected value, or null for a missing required field |
An unexpected server error occurred. Depending on the situation, the body might be empty.
{
"title": "Internal Server Error",
"status": 500,
"detail": "An unexpected error occurred",
"timestamp": "2026-11-23 12:00:00"
}
Body schema
| Field | Type | Description |
|---|---|---|
title | string | A short title describing the error |
status | integer | The HTTP status code |
detail | string or null | A detailed message explaining the error |
timestamp | string | The timestamp when the error occurred, YYYY-MM-DD HH:MM:SS UTC |