Obter Token de Acesso
Obtém um token de acesso (JWT) via OAuth 2.0 Client Credentials. As credenciais api_key e api_secret devem ser enviadas no header Authorization: Basic, com o valor em base64 da string api_key:api_secret.
As credenciais são gerenciadas pelo Internet Banking da Conta Simples.
Importante:
- O token expira em 1 hora (
expires_in: 3600). - Renove o token antes da expiração para evitar interrupções.
- Use
Content-Type: application/x-www-form-urlencodedno body (apenasgrant_type=client_credentials).
curl -X POST "https://api-sandbox.contasimples.com/oauth/v1/access-token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Authorization: Basic YOUR_CREDENTIALS" \
--data-urlencode grant_type=client_credentials
import requests
import json
url = "https://api-sandbox.contasimples.com/oauth/v1/access-token"
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Basic YOUR_CREDENTIALS"
}
data = {
"grant_type": "client_credentials"
}
response = requests.post(url, headers=headers, data=data)
print(response.json())
const params = new URLSearchParams();
params.append("grant_type", "client_credentials");
const response = await fetch("https://api-sandbox.contasimples.com/oauth/v1/access-token", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Basic YOUR_CREDENTIALS"
},
body: params
});
const data = await response.json();
console.log(data);
package main
import (
"fmt"
"net/http"
"net/url"
"strings"
)
func main() {
data := url.Values{}
data.Set("grant_type", "client_credentials")
req, err := http.NewRequest("POST", "https://api-sandbox.contasimples.com/oauth/v1/access-token", strings.NewReader(data.Encode()))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Authorization", "Basic YOUR_CREDENTIALS")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println("Response Status:", resp.Status)
}
require 'net/http'
require 'json'
uri = URI('https://api-sandbox.contasimples.com/oauth/v1/access-token')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request['Content-Type'] = 'application/x-www-form-urlencoded'
request['Authorization'] = 'Basic YOUR_CREDENTIALS'
request.set_form([
["grant_type", "client_credentials"]
], 'application/x-www-form-urlencoded')
response = http.request(request)
puts response.body
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 3600
}
{
"error": "Bad Request",
"message": "The request contains invalid parameters or malformed data",
"code": 400,
"details": [
{
"field": "email",
"message": "Invalid email format"
}
]
}
{
"error": "Unauthorized",
"message": "Authentication required. Please provide a valid API token",
"code": 401
}
{
"error": "Internal Server Error",
"message": "An unexpected error occurred on the server",
"code": 500,
"requestId": "req_1234567890"
}
/oauth/v1/access-token
Username for basic authentication
Password for basic authentication
The media type of the request body
Tipo de concessão OAuth 2.0. Sempre client_credentials.
Request Preview
Response
Response will appear here after sending the request
Authentication
Basic authentication credentials. API Key e API Secret no formato api_key:api_secret, encodados em base64. Header: Authorization: Basic {base64(api_key:api_secret)}
Body
Tipo de concessão OAuth 2.0. Sempre client_credentials.
client_credentialsResponses
Token JWT para autenticação nas chamadas à API. Inclua no header Authorization: Bearer \{token\}.
Tipo do token. Sempre Bearer.
BearerTempo de vida do token em segundos. Padrão: 3600 (1 hora).
Last updated today
Built with Documentation.AI