Saltar al contenido principal
POST
/
license_keys
JavaScript
import DodoPayments from 'dodopayments';

const client = new DodoPayments({
  bearerToken: process.env['DODO_PAYMENTS_API_KEY'], // This is the default and can be omitted
});

const licenseKey = await client.licenseKeys.create({
  customer_id: 'customer_id',
  key: 'key',
  product_id: 'product_id',
});

console.log(licenseKey.id);
import os
from dodopayments import DodoPayments

client = DodoPayments(
    bearer_token=os.environ.get("DODO_PAYMENTS_API_KEY"),  # This is the default and can be omitted
)
license_key = client.license_keys.create(
    customer_id="customer_id",
    key="key",
    product_id="product_id",
)
print(license_key.id)
package main

import (
	"context"
	"fmt"

	"github.com/dodopayments/dodopayments-go"
	"github.com/dodopayments/dodopayments-go/option"
)

func main() {
	client := dodopayments.NewClient(
		option.WithBearerToken("My Bearer Token"),
	)
	licenseKey, err := client.LicenseKeys.New(context.TODO(), dodopayments.LicenseKeyNewParams{
		CustomerID: dodopayments.F("customer_id"),
		Key:        dodopayments.F("key"),
		ProductID:  dodopayments.F("product_id"),
	})
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", licenseKey.ID)
}
package com.dodopayments.api.example;

import com.dodopayments.api.client.DodoPaymentsClient;
import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient;
import com.dodopayments.api.models.licensekeys.LicenseKey;
import com.dodopayments.api.models.licensekeys.LicenseKeyCreateParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        DodoPaymentsClient client = DodoPaymentsOkHttpClient.fromEnv();

        LicenseKeyCreateParams params = LicenseKeyCreateParams.builder()
            .customerId("customer_id")
            .key("key")
            .productId("product_id")
            .build();
        LicenseKey licenseKey = client.licenseKeys().create(params);
    }
}
package com.dodopayments.api.example

import com.dodopayments.api.client.DodoPaymentsClient
import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient
import com.dodopayments.api.models.licensekeys.LicenseKey
import com.dodopayments.api.models.licensekeys.LicenseKeyCreateParams

fun main() {
    val client: DodoPaymentsClient = DodoPaymentsOkHttpClient.fromEnv()

    val params: LicenseKeyCreateParams = LicenseKeyCreateParams.builder()
        .customerId("customer_id")
        .key("key")
        .productId("product_id")
        .build()
    val licenseKey: LicenseKey = client.licenseKeys().create(params)
}
require "dodopayments"

dodo_payments = Dodopayments::Client.new(
  bearer_token: "My Bearer Token",
  environment: "test_mode" # defaults to "live_mode"
)

license_key = dodo_payments.license_keys.create(customer_id: "customer_id", key: "key", product_id: "product_id")

puts(license_key)
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';

use Dodopayments\Client;
use Dodopayments\Core\Exceptions\APIException;

$client = new Client(
  bearerToken: getenv('DODO_PAYMENTS_API_KEY') ?: 'My Bearer Token',
  environment: 'test_mode',
);

try {
  $licenseKey = $client->licenseKeys->create(
    customerID: 'customer_id',
    key: 'key',
    productID: 'product_id',
    activationsLimit: 0,
    expiresAt: new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
  );

  var_dump($licenseKey);
} catch (APIException $e) {
  echo $e->getMessage();
}
using System;
using DodoPayments.Client;
using DodoPayments.Client.Models.LicenseKeys;

DodoPaymentsClient client = new();

LicenseKeyCreateParams parameters = new()
{
    CustomerID = "customer_id",
    Key = "key",
    ProductID = "product_id",
};

var licenseKey = await client.LicenseKeys.Create(parameters);

Console.WriteLine(licenseKey);
use dodopayments::Client;

#[tokio::main]
async fn main() -> dodopayments::Result<()> {
    let client = Client::from_env()?;
    let result = client
        .license_keys()
        .create()
        .body(dodopayments::models::LicenseKeysCreateParams {
                customer_id: Some("customer_id".to_string()),
                key: Some("key".to_string()),
                product_id: Some("product_id".to_string()),
                ..Default::default()
            })
        .await?;
    println!("{result:?}");
    Ok(())
}
curl --request POST \
  --url https://test.dodopayments.com/license_keys \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "customer_id": "<string>",
  "key": "<string>",
  "product_id": "<string>",
  "activations_limit": 123,
  "expires_at": "2023-11-07T05:31:56Z"
}
'
{
  "brand_id": "<string>",
  "business_id": "<string>",
  "created_at": "2024-01-01T00:00:00.000Z",
  "customer_id": "cus_123",
  "id": "lic_123",
  "instances_count": 123,
  "key": "<string>",
  "product_id": "<string>",
  "activations_limit": 5,
  "expires_at": "2024-12-31T23:59:59.000Z",
  "payment_id": "<string>",
  "subscription_id": "<string>"
}
Las claves de licencia creadas o actualizadas a través del API no activan notificaciones por correo electrónico a los clientes. Si necesitas notificar a los clientes sobre su clave de licencia, debes manejar eso por separado en tu aplicación.

Autorizaciones

Authorization
string
header
requerido

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Cuerpo

application/json
customer_id
string
requerido

The customer this license key belongs to.

key
string
requerido

The license key string to import.

product_id
string
requerido

The product this license key is for.

activations_limit
integer<int32> | null

Maximum number of activations allowed. Null means unlimited.

expires_at
string<date-time> | null

Expiration timestamp. Null means the key never expires.

Respuesta

License key created

brand_id
string
requerido

Brand id this license key belongs to

business_id
string
requerido

The unique identifier of the business associated with the license key.

created_at
string<date-time>
requerido

The timestamp indicating when the license key was created, in UTC.

Ejemplo:

"2024-01-01T00:00:00.000Z"

customer_id
string
requerido

The unique identifier of the customer associated with the license key.

Ejemplo:

"cus_123"

id
string
requerido

The unique identifier of the license key.

Ejemplo:

"lic_123"

instances_count
integer<int32>
requerido

The current number of instances activated for this license key.

key
string
requerido

The license key string.

product_id
string
requerido

The unique identifier of the product associated with the license key.

source
enum<string>
requerido

The source of the license key - 'auto' for keys generated by payment/subscription flows, 'import' for merchant-imported keys.

Opciones disponibles:
auto,
import,
manual
status
enum<string>
requerido

The current status of the license key (e.g., active, inactive, expired).

Opciones disponibles:
active,
expired,
disabled
activations_limit
integer<int32> | null

The maximum number of activations allowed for this license key.

Ejemplo:

5

expires_at
string<date-time> | null

The timestamp indicating when the license key expires, in UTC.

Ejemplo:

"2024-12-31T23:59:59.000Z"

payment_id
string | null

The unique identifier of the payment associated with the license key, if any.

subscription_id
string | null

The unique identifier of the subscription associated with the license key, if any.

Última modificación el 20 de abril de 2026