3. Create a unit
Observed — aligned with the end-user docs “Création d’un LOT dans le Patrimoine” and the createUnit mutation.
Why
A unit (UnitV2) is the rentable property. A rental folder can only reference a unit that already exists.
Prerequisites
- List unit templates (configured beforehand in the UI):
query listUnitTemplates {
unitTemplates {
data {
id
name
unitTypeId
archived
}
}
}
- (Optional) types / groups / categories:
query Lookups {
unitTypes { id name category kind active }
availableUnitGroupReferences
managementCategories { data { id name customReference } }
}
Step — Create the unit
- GraphQL
- Node.js
- curl
mutation createUnit($unit: UnitInputV2!) {
createUnit(unit: $unit) {
id
name
customReference
externalId
address {
number
street
zip
city
country
}
}
}
{
"unit": {
"name": "Example T2 apartment",
"customReference": "U000014",
"externalId": "APT-T2-EXT-001",
"unitTemplateId": "00000000-0000-4000-8000-000000000010",
"address": {
"number": "16",
"street": "Quai Henri IV",
"city": "Paris",
"zip": "75004",
"country": "FR",
"coordinates": {
"latitude": 48.848251,
"longitude": 2.363691
}
}
}
}
import { ublo } from '../ubloClient.mjs';
const { unitTemplates } = await ublo(`
query { unitTemplates { data { id name archived } } }
`);
const template = unitTemplates.data.find((t) => !t.archived);
if (!template) throw new Error('No active unitTemplate');
const { createUnit } = await ublo(
`mutation createUnit($unit: UnitInputV2!) {
createUnit(unit: $unit) { id name customReference }
}`,
{
unit: {
name: 'Example T2 apartment',
customReference: 'U000014',
externalId: 'APT-T2-EXT-001',
unitTemplateId: template.id,
address: {
number: '16',
street: 'Quai Henri IV',
city: 'Paris',
zip: '75004',
country: 'FR',
coordinates: { latitude: 48.848251, longitude: 2.363691 },
},
},
},
);
console.log(createUnit.id);
- Bearer
- Cookie session
curl -sS -X POST "$UBLO_GRAPHQL_URL" \
-H "Authorization: Bearer $UBLO_API_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"query": "mutation createUnit($unit: UnitInputV2!) { createUnit(unit: $unit) { id name customReference } }",
"variables": {
"unit": {
"name": "Example T2 apartment",
"customReference": "U000014",
"externalId": "APT-T2-EXT-001",
"unitTemplateId": "00000000-0000-4000-8000-000000000010",
"address": {
"number": "16",
"street": "Quai Henri IV",
"city": "Paris",
"zip": "75004",
"country": "FR"
}
}
}
}'
curl -sS -X POST "$UBLO_GRAPHQL_URL" \
-H 'Content-Type: application/json' \
-b cookies.txt \
-d '{
"query": "mutation createUnit($unit: UnitInputV2!) { createUnit(unit: $unit) { id name customReference } }",
"variables": {
"unit": {
"name": "Example T2 apartment",
"customReference": "U000014",
"externalId": "APT-T2-EXT-001",
"unitTemplateId": "00000000-0000-4000-8000-000000000010",
"address": {
"number": "16",
"street": "Quai Henri IV",
"city": "Paris",
"zip": "75004",
"country": "FR"
}
}
}
}'
Read
query GetUnit($id: UUID!) {
unit(id: $id) {
id
name
customReference
state
}
}
End-user docs
After create, the UI flags still-required sections with a red badge (address/location, ownership, rent…). On the API side, that maps to successive updateUnit calls — see Complete a unit.