> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dodopayments.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Crea Chiave di Licenza

> Crea una nuova chiave di licenza o importa una esistente da un altro sistema.

<Info>
  Le chiavi di licenza create o aggiornate tramite l'API non inviano notifiche email ai clienti. Se è necessario notificare i clienti della loro chiave di licenza, devi gestirlo separatamente nella tua applicazione.
</Info>


## OpenAPI

````yaml post /license_keys
openapi: 3.1.0
info:
  title: public
  description: ''
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
  version: 1.106.2
servers:
  - url: https://test.dodopayments.com/
    description: Test Mode Server Host
  - url: https://live.dodopayments.com/
    description: Live Mode Server Host
security: []
tags:
  - name: Products
  - name: Payments
  - name: Subscriptions
  - name: Addons
  - name: Customers
  - name: Refunds
  - name: Disputes
  - name: Events
  - name: License Keys
  - name: Entitlements
  - name: Licenses
  - name: Discounts
  - name: Meters
  - name: Credit Entitlements
  - name: Credit Entitlement Balances
  - name: Outgoing Webhooks
  - name: Checkout
  - name: Webhook Events
  - name: Payment Connector Webhooks
paths:
  /license_keys:
    post:
      tags:
        - License Keys
      operationId: create_license_key
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateLicenseKeyRequest'
        required: true
      responses:
        '201':
          description: License key created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LicenseKeyResponse'
        '404':
          description: Customer or product not found
        '409':
          description: License key already exists
        '422':
          description: Validation error
        '500':
          description: Something went wrong :(
      security:
        - API_KEY: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            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);
        - lang: Python
          source: |-
            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)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/dodopayments/dodopayments-go\"\n\t\"github.com/dodopayments/dodopayments-go/option\"\n)\n\nfunc main() {\n\tclient := dodopayments.NewClient(\n\t\toption.WithBearerToken(\"My Bearer Token\"),\n\t)\n\tlicenseKey, err := client.LicenseKeys.New(context.TODO(), dodopayments.LicenseKeyNewParams{\n\t\tCustomerID: dodopayments.F(\"customer_id\"),\n\t\tKey:        dodopayments.F(\"key\"),\n\t\tProductID:  dodopayments.F(\"product_id\"),\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", licenseKey.ID)\n}\n"
        - lang: Java
          source: >-
            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);
                }
            }
        - lang: Kotlin
          source: >-
            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)
            }
        - lang: Ruby
          source: >-
            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)
        - lang: PHP
          source: |-
            <?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();
            }
        - lang: C#
          source: |-
            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);
        - lang: Rust
          source: |-
            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(())
            }
components:
  schemas:
    CreateLicenseKeyRequest:
      type: object
      required:
        - key
        - customer_id
        - product_id
      properties:
        activations_limit:
          type:
            - integer
            - 'null'
          format: int32
          description: Maximum number of activations allowed. Null means unlimited.
        customer_id:
          type: string
          description: The customer this license key belongs to.
        expires_at:
          type:
            - string
            - 'null'
          format: date-time
          description: Expiration timestamp. Null means the key never expires.
        key:
          type: string
          description: The license key string to import.
        product_id:
          type: string
          description: The product this license key is for.
    LicenseKeyResponse:
      type: object
      required:
        - id
        - business_id
        - key
        - status
        - customer_id
        - product_id
        - instances_count
        - created_at
        - source
        - brand_id
      properties:
        activations_limit:
          type:
            - integer
            - 'null'
          format: int32
          description: The maximum number of activations allowed for this license key.
          example: 5
        brand_id:
          type: string
          description: Brand id this license key belongs to
        business_id:
          type: string
          description: >-
            The unique identifier of the business associated with the license
            key.
        created_at:
          type: string
          format: date-time
          description: The timestamp indicating when the license key was created, in UTC.
          example: '2024-01-01T00:00:00.000Z'
        customer_id:
          type: string
          description: >-
            The unique identifier of the customer associated with the license
            key.
          example: cus_123
        expires_at:
          type:
            - string
            - 'null'
          format: date-time
          description: The timestamp indicating when the license key expires, in UTC.
          example: '2024-12-31T23:59:59.000Z'
        id:
          type: string
          description: The unique identifier of the license key.
          example: lic_123
        instances_count:
          type: integer
          format: int32
          description: The current number of instances activated for this license key.
        key:
          type: string
          description: The license key string.
        payment_id:
          type:
            - string
            - 'null'
          description: >-
            The unique identifier of the payment associated with the license
            key, if any.
        product_id:
          type: string
          description: >-
            The unique identifier of the product associated with the license
            key.
        source:
          $ref: '#/components/schemas/LicenseKeySource'
          description: >-
            The source of the license key - 'auto' for keys generated by
            payment/subscription flows, 'import' for merchant-imported keys.
        status:
          $ref: '#/components/schemas/LicenseKeyStatus'
          description: >-
            The current status of the license key (e.g., active, inactive,
            expired).
        subscription_id:
          type:
            - string
            - 'null'
          description: >-
            The unique identifier of the subscription associated with the
            license key, if any.
    LicenseKeySource:
      type: string
      enum:
        - auto
        - import
        - manual
    LicenseKeyStatus:
      type: string
      enum:
        - active
        - expired
        - disabled
  securitySchemes:
    API_KEY:
      type: http
      scheme: bearer

````