curl --request POST \
--url https://api-sandbox.beinfi.com/products \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"key": "<string>",
"description": "<string>",
"currency": "BRL",
"basePrice": "<string>"
}
'import requests
url = "https://api-sandbox.beinfi.com/products"
payload = {
"name": "<string>",
"key": "<string>",
"description": "<string>",
"currency": "BRL",
"basePrice": "<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({
name: '<string>',
key: '<string>',
description: '<string>',
currency: 'BRL',
basePrice: '<string>'
})
};
fetch('https://api-sandbox.beinfi.com/products', 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-sandbox.beinfi.com/products",
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([
'name' => '<string>',
'key' => '<string>',
'description' => '<string>',
'currency' => 'BRL',
'basePrice' => '<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-sandbox.beinfi.com/products"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"key\": \"<string>\",\n \"description\": \"<string>\",\n \"currency\": \"BRL\",\n \"basePrice\": \"<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-sandbox.beinfi.com/products")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"key\": \"<string>\",\n \"description\": \"<string>\",\n \"currency\": \"BRL\",\n \"basePrice\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-sandbox.beinfi.com/products")
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 \"name\": \"<string>\",\n \"key\": \"<string>\",\n \"description\": \"<string>\",\n \"currency\": \"BRL\",\n \"basePrice\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"product": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"key": "<string>",
"name": "<string>",
"type": "agent",
"description": "<string>",
"pricingModel": "subscription",
"currency": "BRL",
"status": "active",
"imageUrl": "<string>",
"requiresShipping": true,
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
},
"version": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"version": 123,
"billingCycle": "weekly",
"basePrice": "<string>",
"status": "draft",
"isDefault": true,
"publishedAt": "2023-11-07T05:31:56Z",
"commitmentAmount": "<string>",
"commitmentResets": true,
"consumptionFloor": "<string>",
"grants": [
{
"meter": "<string>",
"amount": "<string>",
"on": "cycle"
}
]
}
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>"
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>",
"resource": "<string>",
"metadata": {}
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>",
"errors": [
{
"field": "<string>",
"value": "<string>",
"constraint": "<string>",
"description": "<string>"
}
]
}Criar produto
Cria o produto junto com a versão 1 em draft. Para vender, publique essa versão com POST /products/{productID}/versions/{versionID}/publish.
Com key, a chamada é idempotente: se a chave já existe, você recebe o produto que ela identifica (com name e description atualizados para o que enviou) em vez de um erro. O preço não entra nessa atualização: se basePrice ou billingCycle diferirem da versão atual, a resposta é 422 pricing_immutable. Para mudar o preço, crie uma nova versão com POST /products/{productID}/versions. Uma requisição sem preço não mexe no preço.
curl --request POST \
--url https://api-sandbox.beinfi.com/products \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"key": "<string>",
"description": "<string>",
"currency": "BRL",
"basePrice": "<string>"
}
'import requests
url = "https://api-sandbox.beinfi.com/products"
payload = {
"name": "<string>",
"key": "<string>",
"description": "<string>",
"currency": "BRL",
"basePrice": "<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({
name: '<string>',
key: '<string>',
description: '<string>',
currency: 'BRL',
basePrice: '<string>'
})
};
fetch('https://api-sandbox.beinfi.com/products', 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-sandbox.beinfi.com/products",
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([
'name' => '<string>',
'key' => '<string>',
'description' => '<string>',
'currency' => 'BRL',
'basePrice' => '<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-sandbox.beinfi.com/products"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"key\": \"<string>\",\n \"description\": \"<string>\",\n \"currency\": \"BRL\",\n \"basePrice\": \"<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-sandbox.beinfi.com/products")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"key\": \"<string>\",\n \"description\": \"<string>\",\n \"currency\": \"BRL\",\n \"basePrice\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-sandbox.beinfi.com/products")
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 \"name\": \"<string>\",\n \"key\": \"<string>\",\n \"description\": \"<string>\",\n \"currency\": \"BRL\",\n \"basePrice\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"product": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"key": "<string>",
"name": "<string>",
"type": "agent",
"description": "<string>",
"pricingModel": "subscription",
"currency": "BRL",
"status": "active",
"imageUrl": "<string>",
"requiresShipping": true,
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
},
"version": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"version": 123,
"billingCycle": "weekly",
"basePrice": "<string>",
"status": "draft",
"isDefault": true,
"publishedAt": "2023-11-07T05:31:56Z",
"commitmentAmount": "<string>",
"commitmentResets": true,
"consumptionFloor": "<string>",
"grants": [
{
"meter": "<string>",
"amount": "<string>",
"on": "cycle"
}
]
}
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>"
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>",
"resource": "<string>",
"metadata": {}
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>",
"errors": [
{
"field": "<string>",
"value": "<string>",
"constraint": "<string>",
"description": "<string>"
}
]
}Autorizações
Chave secreta da conta: Authorization: Bearer sk_test_… ou sk_live_…. Use só no servidor.
Cabeçalhos
Chave única por operação (um UUID serve). Repetir com a mesma chave devolve a resposta original.
Corpo
subscription, one_time, usage ou prepaid.
subscription, one_time, usage, prepaid Chave estável do produto, única na sua conta. Criar duas vezes com a mesma chave devolve o mesmo produto; um preço diferente do da versão atual é recusado com 422 pricing_immutable.
item (padrão) ou agent.
agent, item Código ISO 4217 de 3 letras. Padrão: BRL.
"BRL"
weekly, monthly ou annual. Obrigatório para subscription e prepaid; não envie nos outros modelos.
weekly, monthly, annual, null Preço base da versão 1, em texto decimal ("49.90").