Skip to main content
POST
/
api
/
v1
/
branches
Create Branch
curl --request POST \
  --url https://api.example.com/api/v1/branches
{
  "success": true,
  "message": "<string>",
  "data": {
    "id": 123,
    "company_id": 123,
    "codigo": "<string>",
    "nombre": "<string>",
    "direccion": "<string>",
    "ubigeo": "<string>",
    "distrito": "<string>",
    "provincia": "<string>",
    "departamento": "<string>",
    "telefono": "<string>",
    "email": "<string>",
    "series_factura": [
      {}
    ],
    "series_boleta": [
      {}
    ],
    "series_nota_credito": [
      {}
    ],
    "series_nota_debito": [
      {}
    ],
    "series_guia_remision": [
      {}
    ],
    "activo": true,
    "company": {},
    "created_at": "<string>",
    "updated_at": "<string>"
  }
}
Create a new branch (sucursal) for a company.

Authentication

This endpoint requires authentication. Include your API token in the request header:
Authorization: Bearer YOUR_API_TOKEN

Request Body

company_id
integer
required
ID of the parent company. The company must exist and be active.
codigo
string
required
Branch code (max 10 characters). Must be unique within the company.
nombre
string
required
Branch name (max 255 characters)
direccion
string
required
Branch address (max 255 characters)
ubigeo
string
required
6-digit UBIGEO code for geographic location
distrito
string
required
District name (max 100 characters)
provincia
string
required
Province name (max 100 characters)
departamento
string
required
Department/region name (max 100 characters)
telefono
string
Phone number (max 20 characters)
email
string
Branch email address (max 255 characters, must be valid email format)
contacto_nombre
string
Contact person name (max 255 characters)
series_factura
array
Array of invoice series codes (e.g., [“F001”, “F002”])
series_boleta
array
Array of sales receipt series codes (e.g., [“B001”, “B002”])
series_nota_credito
array
Array of credit note series codes (e.g., [“FC01”])
series_nota_debito
array
Array of debit note series codes (e.g., [“FD01”])
series_guia_remision
array
Array of dispatch guide series codes (e.g., [“T001”])
activo
boolean
Active status. Defaults to true.

Response

success
boolean
required
Indicates if the branch was created successfully
message
string
required
Success message
data
object
required
The created branch object with company information

Example Request

cURL
curl -X POST https://api.yourdomain.com/api/v1/branches \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "company_id": 1,
    "codigo": "0001",
    "nombre": "Sucursal Principal",
    "direccion": "Av. Los Olivos 123",
    "ubigeo": "150101",
    "distrito": "San Isidro",
    "provincia": "Lima",
    "departamento": "Lima",
    "telefono": "01-1234567",
    "email": "[email protected]",
    "series_factura": ["F001", "F002"],
    "series_boleta": ["B001"],
    "series_nota_credito": ["FC01"],
    "series_nota_debito": ["FD01"],
    "series_guia_remision": ["T001"],
    "activo": true
  }'
PHP
$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.yourdomain.com/api/v1/branches', [
  'headers' => [
    'Authorization' => 'Bearer YOUR_API_TOKEN',
    'Content-Type' => 'application/json',
  ],
  'json' => [
    'company_id' => 1,
    'codigo' => '0001',
    'nombre' => 'Sucursal Principal',
    'direccion' => 'Av. Los Olivos 123',
    'ubigeo' => '150101',
    'distrito' => 'San Isidro',
    'provincia' => 'Lima',
    'departamento' => 'Lima',
    'telefono' => '01-1234567',
    'email' => '[email protected]',
    'series_factura' => ['F001', 'F002'],
    'series_boleta' => ['B001'],
    'series_nota_credito' => ['FC01'],
    'series_nota_debito' => ['FD01'],
    'series_guia_remision' => ['T001'],
    'activo' => true,
  ],
]);

echo $response->getBody();
JavaScript
const response = await fetch('https://api.yourdomain.com/api/v1/branches', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_TOKEN',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    company_id: 1,
    codigo: '0001',
    nombre: 'Sucursal Principal',
    direccion: 'Av. Los Olivos 123',
    ubigeo: '150101',
    distrito: 'San Isidro',
    provincia: 'Lima',
    departamento: 'Lima',
    telefono: '01-1234567',
    email: '[email protected]',
    series_factura: ['F001', 'F002'],
    series_boleta: ['B001'],
    series_nota_credito: ['FC01'],
    series_nota_debito: ['FD01'],
    series_guia_remision: ['T001'],
    activo: true
  })
});

const data = await response.json();
console.log(data);

Example Response

201 Created
{
  "success": true,
  "message": "Sucursal creada exitosamente",
  "data": {
    "id": 1,
    "company_id": 1,
    "codigo": "0001",
    "nombre": "Sucursal Principal",
    "direccion": "Av. Los Olivos 123",
    "ubigeo": "150101",
    "distrito": "San Isidro",
    "provincia": "Lima",
    "departamento": "Lima",
    "telefono": "01-1234567",
    "email": "[email protected]",
    "series_factura": ["F001", "F002"],
    "series_boleta": ["B001"],
    "series_nota_credito": ["FC01"],
    "series_nota_debito": ["FD01"],
    "series_guia_remision": ["T001"],
    "activo": true,
    "company": {
      "id": 1,
      "ruc": "20123456789",
      "razon_social": "EMPRESA DEMO S.A.C."
    },
    "created_at": "2024-03-05T10:30:00.000000Z",
    "updated_at": "2024-03-05T10:30:00.000000Z"
  }
}
404 Company Not Found
{
  "success": false,
  "message": "La empresa especificada no existe o está inactiva"
}
422 Validation Error
{
  "success": false,
  "message": "Errores de validación",
  "errors": {
    "codigo": [
      "El código de sucursal ya existe para esta empresa."
    ],
    "email": [
      "El email debe tener un formato válido."
    ],
    "ubigeo": [
      "El ubigeo debe tener exactamente 6 caracteres."
    ]
  }
}
500 Error
{
  "success": false,
  "message": "Error al crear sucursal: Database error"
}
Branch Code Uniqueness: The codigo field must be unique within each company. Multiple companies can have branches with the same code, but within a single company all branch codes must be unique.
The parent company must be active (activo: true) to create a branch. Attempting to create a branch for an inactive company will result in a 404 error.

Build docs developers (and LLMs) love