---
agentTools:
  projectIndex: https://docs.mundipagg.com/llms.txt
---

# Criar cliente

Este recurso cria um objeto `customer` que representa um cliente.

<br>

[block:callout]
{
  "type": "warning",
  "body": "É importante destacar que o campo **e-mail é único**, ou seja, caso seja requisitada **a criação de um cliente com um e-mail já cadastrado**, o _endpoint_ irá atualizar os dados do `customer` anteriormente cadastrado com o email informado.",
  "title": "O e-mail do cliente é único"
}
[/block]

# OpenAPI definition

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "Mundipagg API",
    "version": "1"
  },
  "servers": [
    {
      "url": "https://api.mundipagg.com/core/v1"
    }
  ],
  "components": {
    "securitySchemes": {
      "sec0": {
        "type": "http",
        "scheme": "basic"
      }
    }
  },
  "security": [
    {
      "sec0": []
    }
  ],
  "paths": {
    "/customers": {
      "post": {
        "summary": "Criar cliente",
        "description": "Este recurso cria um objeto `customer` que representa um cliente.",
        "operationId": "criar-cliente",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "type"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Nome do cliente. Max: 64 caracteres."
                  },
                  "email": {
                    "type": "string",
                    "description": "E-mail do cliente. Max: 64 caracteres"
                  },
                  "code": {
                    "type": "string",
                    "description": "Código de referência do cliente no sistema da loja. Max: 52 caracteres"
                  },
                  "document": {
                    "type": "string",
                    "description": "CPF, CNPJ ou PASSAPORTE do cliente. Max: 16 caracteres para CPF e CNPJ e Max: 50 caracteres para PASSAPORTE"
                  },
                  "document_type": {
                    "type": "string",
                    "description": "Tipo de documento. Valores possíveis: CPF, CNPJ ou PASSPORT."
                  },
                  "type": {
                    "type": "string",
                    "description": "Tipo de cliente. Valores possíveis: **individual** (pessoa física) ou **company** (pessoa jurídica).<br>**Obrigatório**, caso o `document` seja enviado."
                  },
                  "gender": {
                    "type": "string",
                    "description": "Sexo do cliente . Valores possíveis: **male** ou **female**"
                  },
                  "address": {
                    "type": "object",
                    "description": "Endereço do cliente. [Saiba mais sobre endereços](https://docs.mundipagg.com/v1/reference#enderecos)",
                    "properties": {}
                  },
                  "phones": {
                    "type": "object",
                    "description": "Telefones do cliente. [Saiba mais sobre o telefones](https://docs.mundipagg.com/v1/reference#telefones)",
                    "properties": {
                      "home_phone": {
                        "type": "object",
                        "description": "Telefone residencial do cliente. [Saiba mais sobre o telefones](https://docs.mundipagg.com/v1/reference#telefones)",
                        "properties": {}
                      },
                      "mobile_phone": {
                        "type": "object",
                        "description": "Telefone móvel do cliente. [Saiba mais sobre o telefones](https://docs.mundipagg.com/v1/reference#telefones)",
                        "properties": {}
                      }
                    }
                  },
                  "birthdate": {
                    "type": "string",
                    "description": "Data de nascimento do cliente.",
                    "format": "date"
                  },
                  "metadata": {
                    "type": "string",
                    "description": "Objeto chave/valor utilizado para armazenar informações adicionais sobre o cliente. [Saiba mais sobre metadata](https://docs.mundipagg.com/v1/reference#metadata)"
                  }
                }
              },
              "examples": {
                "JSON": {
                  "value": {
                    "name": "Tony Stark",
                    "email": "tonystarkk@avengers.com",
                    "code": "MY_CUSTOMER_001",
                    "document": "93095135270",
                    "type": "individual",
                    "document_type": "CPF",
                    "gender": "male",
                    "address": {
                      "line_1": "375, Av. General Justo, Centro",
                      "line_2": "8º andar",
                      "zip_code": "20021130",
                      "city": "Rio de Janeiro",
                      "state": "RJ",
                      "country": "BR"
                    },
                    "birthdate": "05/03/1984",
                    "phones": {
                      "home_phone": {
                        "country_code": "55",
                        "area_code": "21",
                        "number": "000000000"
                      },
                      "mobile_phone": {
                        "country_code": "55",
                        "area_code": "21",
                        "number": "000000000"
                      }
                    },
                    "metadata": {
                      "company": "Avengers"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": "{\n    \"id\": \"cus_QA5V47r9c0Im3dzN\",\n    \"name\": \"Tony Stark\",\n    \"email\": \"tonystarkk@avengers.com\",\n    \"code\": \"MY_CUSTOMER_001\",\n    \"document\": \"93095135270\",\n    \"document_type\": \"CPF\",  \n    \"type\": \"individual\",\n    \"gender\": \"male\",\n    \"delinquent\": false,\n    \"address\": {\n        \"id\": \"addr_KewjagEfrCbY1doZ\",\n        \"line_1\": \"375, Av. General Justo, Centro\",\n        \"line_2\": \"8º andar\",\n        \"zip_code\": \"20021130\",\n        \"city\": \"Rio de Janeiro\",\n        \"state\": \"RJ\",\n        \"country\": \"BR\",\n        \"status\": \"active\",\n        \"created_at\": \"2017-09-22T15:36:46Z\",\n        \"updated_at\": \"2018-04-03T17:46:20Z\"\n    },\n    \"created_at\": \"2017-09-22T15:36:46Z\",\n    \"updated_at\": \"2018-04-03T17:46:20Z\",\n    \"birthdate\": \"1984-05-03T00:00:00Z\",\n    \"phones\": {\n        \"home_phone\": {\n            \"country_code\": \"55\",\n            \"number\": \"000000000\",\n            \"area_code\": \"21\"\n        },\n        \"mobile_phone\": {\n            \"country_code\": \"55\",\n            \"number\": \"000000000\",\n            \"area_code\": \"21\"\n        }\n    },\n    \"metadata\": {\n        \"id\": \"my_customer_id\",\n        \"company\": \"Avengers\"\n    }\n}"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "example": "cus_QA5V47r9c0Im3dzN"
                    },
                    "name": {
                      "type": "string",
                      "example": "Tony Stark"
                    },
                    "email": {
                      "type": "string",
                      "example": "tonystarkk@avengers.com"
                    },
                    "code": {
                      "type": "string",
                      "example": "MY_CUSTOMER_001"
                    },
                    "document": {
                      "type": "string",
                      "example": "93095135270"
                    },
                    "document_type": {
                      "type": "string",
                      "example": "CPF"
                    },
                    "type": {
                      "type": "string",
                      "example": "individual"
                    },
                    "gender": {
                      "type": "string",
                      "example": "male"
                    },
                    "delinquent": {
                      "type": "boolean",
                      "example": false,
                      "default": true
                    },
                    "address": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "example": "addr_KewjagEfrCbY1doZ"
                        },
                        "line_1": {
                          "type": "string",
                          "example": "375, Av. General Justo, Centro"
                        },
                        "line_2": {
                          "type": "string",
                          "example": "8º andar"
                        },
                        "zip_code": {
                          "type": "string",
                          "example": "20021130"
                        },
                        "city": {
                          "type": "string",
                          "example": "Rio de Janeiro"
                        },
                        "state": {
                          "type": "string",
                          "example": "RJ"
                        },
                        "country": {
                          "type": "string",
                          "example": "BR"
                        },
                        "status": {
                          "type": "string",
                          "example": "active"
                        },
                        "created_at": {
                          "type": "string",
                          "example": "2017-09-22T15:36:46Z"
                        },
                        "updated_at": {
                          "type": "string",
                          "example": "2018-04-03T17:46:20Z"
                        }
                      }
                    },
                    "created_at": {
                      "type": "string",
                      "example": "2017-09-22T15:36:46Z"
                    },
                    "updated_at": {
                      "type": "string",
                      "example": "2018-04-03T17:46:20Z"
                    },
                    "birthdate": {
                      "type": "string",
                      "example": "1984-05-03T00:00:00Z"
                    },
                    "phones": {
                      "type": "object",
                      "properties": {
                        "home_phone": {
                          "type": "object",
                          "properties": {
                            "country_code": {
                              "type": "string",
                              "example": "55"
                            },
                            "number": {
                              "type": "string",
                              "example": "000000000"
                            },
                            "area_code": {
                              "type": "string",
                              "example": "21"
                            }
                          }
                        },
                        "mobile_phone": {
                          "type": "object",
                          "properties": {
                            "country_code": {
                              "type": "string",
                              "example": "55"
                            },
                            "number": {
                              "type": "string",
                              "example": "000000000"
                            },
                            "area_code": {
                              "type": "string",
                              "example": "21"
                            }
                          }
                        }
                      }
                    },
                    "metadata": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "example": "my_customer_id"
                        },
                        "company": {
                          "type": "string",
                          "example": "Avengers"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": "{\n    \"message\": \"The request is invalid.\",\n    \"errors\": {\n        \"customer.name\": [\n            \"The name field is required.\"\n        ]\n    },\n    \"request\": {\n        \"email\": \"tonystarkk@avengers.com\",\n        \"code\": \"MY_CUSTOMER_001\",\n        \"document\": \"123456789\",\n        \"type\": \"individual\",\n        \"address\": {\n            \"line_1\": \"375, Av. General Justo, Centro\",\n            \"line_2\": \"8º andar\",\n            \"zip_code\": \"20021130\",\n            \"city\": \"Rio de Janeiro\",\n            \"state\": \"RJ\",\n            \"country\": \"BR\",\n        },\n        \"birthdate\": \"1984-05-03T00:00:00Z\",\n        \"phones\": {\n            \"home_phone\": {\n                \"country_code\": \"55\",\n                \"number\": \"000000000\",\n                \"area_code\": \"21\"\n            },\n            \"mobile_phone\": {\n                \"country_code\": \"55\",\n                \"number\": \"000000000\",\n                \"area_code\": \"21\"\n            }\n        },\n        \"gender\": \"male\",\n        \"metadata\": {\n            \"company\": \"Avengers\"\n        }\n    }\n}"
                  }
                }
              }
            }
          }
        },
        "deprecated": false,
        "x-readme": {
          "code-samples": [
            {
              "language": "csharp",
              "code": "using MundiAPI.PCL;\nusing MundiAPI.PCL.Models;\nusing System.Collections.Generic;\nusing System.Web.Mvc;\n\nnamespace MundipaggTest.Controllers {\n\npublic class HomeController : Controller {\n\npublic ActionResult Index() {\n\n    // Secret key fornecida pela Mundipagg\n    string basicAuthUserName = \"SUA_CHAVE_SECRETA\";\n\n    // Senha em branco. Passando apenas a secret key\n    string basicAuthPassword = \"\";\n\n    var client = new MundiAPIClient(basicAuthUserName, basicAuthPassword);\n\n    var metadata = new Dictionary<string, string>();\n    metadata.Add(\"id\", \"my_customer_id\");\n\n    var address = new CreateAddressRequest {\n        Line1 = \"375, Av. General Justo, Centro\",\n        Line2 = \"8º andar\",\n        ZipCode = \"20021130\",\n        ZipCode = \"20021130\",\n        City = \"Rio de Janeiro\",\n        State = \"RJ\",\n        Country = \"BR\"\n    };\n\n    var phones = new CreatePhonesRequest {\n        HomePhone = new CreatePhoneRequest {\n\n            AreaCode = \"21\",\n            CountryCode = \"55\",\n            Number = \"000000000\"\n        },\n        MobilePhone = new CreatePhoneRequest {\n\n            AreaCode = \"21\",\n            CountryCode = \"55\",\n            Number = \"000000000\"\n        },\n    };\n\n    var request = new CreateCustomerRequest {\n        Name = \"Tony Stark\",\n        Email = \"tonystark@avengers.com\",\n        Type = \"individual\",\n        Document = \"93095135270\",\n        Gender = \"male\",\n        Code = \"MY_CUSTOMER_001\"\n        Phones = phones,\n        Address = address,\n        Metadata = metadata\n    };\n\n    var response = client.Customers.CreateCustomer(request);\n\n    return View();\n}\n}\n}\n",
              "name": "SDK C#"
            },
            {
              "language": "php",
              "code": "//This example was built using MundiAPI-PHP SDK.\n//For more information, please refer to https://github.com/mundipagg/MundiAPI-PHP\n\n$secretKey = 'YOUR_SECRET_KEY'; //the secret key will be provided by MundiPagg.\n$basicAuthPassword = ''; //fill it with an empty string\n\n$apiClient = new \\MundiAPILib\\MundiAPIClient(\n    $secretKey,\n    $basicAuthPassword\n);\n\n$customerController = $apiClient->getCustomers();\n\n$request = new \\MundiAPILib\\Models\\CreateCustomerRequest();\n$request->name = \"sdk customer test\";\n$request->email = \"tonystark@avengers.com\";\n$request->type = \"individual\";\n$request->document = \"55342561094\";\n$request->code = \"MY_CUSTOMER_001\";\n\n$request->address = new \\MundiAPILib\\Models\\CreateAddressRequest();\n$request->address->line1 = \"375, Av. General Justo, Centro\";\n$request->address->line2 = \"8º andar\";\n$request->address->zipCode = \"20021130\";\n$request->address->city = \"Rio de Janeiro\";\n$request->address->state = \"RJ\";\n$request->address->country = \"BR\";\n$request->address->metadata = new \\MundiAPILib\\Models\\UpdateMetadataRequest();\n$request->address->metadata->id = \"my_address_id\";\n\n$request->phones = new \\MundiAPILib\\Models\\CreatePhonesRequest();\n$request->phones->homePhone = new \\MundiAPILib\\Models\\CreatePhoneRequest();\n$request->phones->homePhone->areaCode = \"21\";\n$request->phones->homePhone->countryCode = \"55\";\n$request->phones->homePhone->number = \"000000000\";\n$request->phones->mobilePhone = new \\MundiAPILib\\Models\\CreatePhoneRequest();\n$request->phones->mobilePhone->areaCode = \"21\";\n$request->phones->mobilePhone->countryCode = \"55\";\n$request->phones->mobilePhone->number = \"000000000\";\n\n$result = $customerController->createCustomer($request);\n\necho json_encode($result, JSON_PRETTY_PRINT);",
              "name": "SDK PHP"
            },
            {
              "language": "java",
              "code": "package examples.customer;\n\nimport com.mundipagg.api.MundiAPIClient;\nimport com.mundipagg.api.http.client.*;\nimport com.mundipagg.api.models.*;\nimport com.mundipagg.api.controllers.*;\n\nimport java.util.LinkedHashMap;\n\npublic class CreateCustomer {\n\t\n\tpublic static void main(String[] args) {\n\n        String basicAuthUserName = \"YOUR_SECRET_KEY\"; // The username to use with basic authentication\n        String basicAuthPassword = \"\"; // The password to use with basic authentication\n\n        MundiAPIClient client = new MundiAPIClient(basicAuthUserName, basicAuthPassword);\n\n        CustomersController customers_controller = new CustomersController();\n\n        CreateCustomerRequest request = new CreateCustomerRequest();\n        request.setName(\"sdk customer test\");\n        request.setEmail(\"tonystark@avengers.com\");\n        request.setType(\"individual\");\n        request.setDocument(\"55342561094\");\n        request.setCode(\"MY_CUSTOMER_001\");\n\n        request.setAddress(new CreateAddressRequest());\n        request.getAddress().setLine1(\"375, Av. General Justo, Centro\");\n        request.getAddress().setLine2(\"8º andar\");\n        request.getAddress().setZipCode(\"20021130\");\n        request.getAddress().setCity(\"Rio de Janeiro\");\n        request.getAddress().setState(\"RJ\");\n        request.getAddress().setCountry(\"BR\");\n        LinkedHashMap<String, String> metadata = new LinkedHashMap<String, String>();\n        metadata.put(\"id\",\"my_address_id\");\n        UpdateMetadataRequest updateMetadata = new UpdateMetadataRequest();\n        updateMetadata.setMetadata(metadata);\n        request.getAddress().setMetadata(updateMetadata.getMetadata());\n\n        request.setPhones(new CreatePhonesRequest());\n        request.getPhones().setHomePhone(new CreatePhoneRequest());\n        request.getPhones().getHomePhone().setAreaCode(\"21\");\n        request.getPhones().getHomePhone().setCountryCode(\"55\");\n        request.getPhones().getHomePhone().setNumber(\"000000000\");\n        request.getPhones().setMobilePhone(new CreatePhoneRequest());\n        request.getPhones().getMobilePhone().setAreaCode(\"21\");\n        request.getPhones().getMobilePhone().setCountryCode(\"55\");\n        request.getPhones().getMobilePhone().setNumber(\"000000000\");\n\n        customers_controller.createCustomerAsync(request, new APICallBack<GetCustomerResponse>() {\n            @Override\n            public void onSuccess(HttpContext context, GetCustomerResponse response) {\n\n                System.out.println(\"Status response: \" + context.getResponse().getStatusCode());\n                System.out.println(\"Customer create !\");\n                System.out.println(\"Status response: \" + context.getResponse().getStatusCode());\n                System.out.println(\"Customer ID: \" + response.getId());\n\n            }\n\n            @Override\n            public void onFailure(HttpContext context, Throwable error) {\n\n                System.out.println(\"Status response: \" + context.getResponse().getStatusCode());\n                System.out.println(error.getMessage());\n                error.printStackTrace();\n\n            }\n        });\n    }\n\n}",
              "name": "SDK JAVA"
            },
            {
              "language": "python",
              "code": "from mundiapi.mundiapi_client import MundiapiClient\nfrom mundiapi.models import *\nfrom mundiapi.controllers import *\nfrom mundiapi.exceptions.error_exception import *\n\nMundiapiClient.config.basic_auth_user_name = \"YOUR_SECRET_KEY:\"\ncustomers_controller = customers_controller.CustomersController()\n\nrequest = create_customer_request.CreateCustomerRequest()\nrequest.name = \"sdk customer test\"\nrequest.email = \"tonystark@avengers.com\"\n\ntry:\n    result = customers_controller.create_customer(request)\n    assert result is not None\n    print(\"Customer id: \", result.id)\n\nexcept ErrorException as ex:\n    print(ex.message)\n    print(\"Errors: \", ex.errors)\nexcept Exception as ex:\n    raise ex",
              "name": "SDK PYTHON"
            }
          ],
          "samples-languages": [
            "csharp",
            "php",
            "java",
            "python"
          ]
        }
      }
    }
  },
  "x-readme": {
    "headers": [],
    "explorer-enabled": false,
    "proxy-enabled": false
  },
  "x-readme-fauxas": true,
  "_id": "5aba89f6b169810058a71e9a:5aba89f6b169810058a71ea5"
}
```