POST /api/menages
Crée un nouveau ménage avec son chef de ménage et son logement.
Endpoint
POST /api/menages
Headers
| Header | Valeur | Requis |
|---|---|---|
| Authorization | Bearer {token} | Oui |
| Content-Type | application/json | Oui |
Corps de la requête
{
"tailleMenage": 5,
"region": "/api/regions/1",
"secteur": "/api/secteurs/1",
"commune": "/api/communes/1",
"localite": "/api/localites/1",
"latitude": "14.7167",
"longitude": "-17.4677",
"altitude": "12.5",
"precisionGps": "5.0",
"nbEnfants04": 1,
"nbEnfants514": 2,
"nbAdultes1564": 2,
"nbPersonnes65Plus": 0,
"nbHandicapes": 0,
"nbActifsOccupes": 2,
"chefMenage": {
"nomComplet": "Mamadou Diallo",
"sexe": "M",
"age": 45,
"niveauEducation": "secondaire",
"occupationPrincipale": "commerce",
"statutMatrimonial": "marie",
"telephone": "771234567",
"numeroMobileMoney": "771234567"
},
"logement": {
"typeLogement": "maison",
"statutOccupation": "proprietaire",
"nbPieces": 4,
"materiauMur": "ciment",
"materiauToit": "tole",
"materiauSol": "ciment",
"sourceEau": "robinet",
"typeToilette": "wc_chasse",
"sourceEclairage": "electricite",
"combustibleCuisine": "gaz"
}
}
Champs du ménage
| Champ | Type | Requis | Description |
|---|---|---|---|
| tailleMenage | integer | Oui | Nombre de personnes (> 0) |
| region | IRI | Oui | Référence à la région |
| secteur | IRI | Oui | Référence au secteur |
| commune | IRI | Oui | Référence à la commune |
| localite | IRI | Non | Référence à la localité |
| latitude | string | Non | Latitude GPS (decimal) |
| longitude | string | Non | Longitude GPS (decimal) |
| nbEnfants04 | integer | Non | Enfants 0-4 ans |
| nbEnfants514 | integer | Non | Enfants 5-14 ans |
| nbAdultes1564 | integer | Non | Adultes 15-64 ans |
| nbPersonnes65Plus | integer | Non | Personnes 65+ ans |
Champs du chef de ménage
| Champ | Type | Requis | Description |
|---|---|---|---|
| nomComplet | string | Oui | Nom et prénom |
| sexe | string | Non | "M" ou "F" |
| age | integer | Non | Âge |
| niveauEducation | string | Non | Niveau d'études |
| occupationPrincipale | string | Non | Activité |
| statutMatrimonial | string | Non | Situation familiale |
| telephone | string | Non | Numéro de téléphone |
| numeroMobileMoney | string | Non | Numéro Mobile Money |
Champs du logement
| Champ | Type | Requis | Description |
|---|---|---|---|
| typeLogement | string | Non | Type de logement |
| statutOccupation | string | Non | Statut d'occupation |
| nbPieces | integer | Non | Nombre de pièces |
| materiauMur | string | Non | Matériau des murs |
| sourceEau | string | Non | Source d'eau |
Réponse succès
Code: 201 Created
{
"@context": "/api/contexts/Menage",
"@id": "/api/menages/123",
"@type": "Menage",
"id": 123,
"codeMenage": "MEN-2024-00123",
"tailleMenage": 5,
"statut": "en_attente",
"chefMenage": {
"@id": "/api/chef_menages/123",
"nomComplet": "Mamadou Diallo"
},
"createdAt": "2024-01-15T10:30:00+00:00"
}
Réponses erreur
422 Unprocessable Entity - Erreur de validation
{
"@context": "/api/contexts/ConstraintViolationList",
"@type": "ConstraintViolationList",
"hydra:title": "An error occurred",
"hydra:description": "tailleMenage: This value should be positive.",
"violations": [
{
"propertyPath": "tailleMenage",
"message": "This value should be positive."
},
{
"propertyPath": "chefMenage.nomComplet",
"message": "This value should not be blank."
}
]
}
400 Bad Request
{
"@context": "/api/contexts/Error",
"@type": "hydra:Error",
"hydra:title": "An error occurred",
"hydra:description": "Syntax error"
}
Exemples
cURL
curl -X POST https://sig.ucp-pch.org/api/menages \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json" \
-d '{
"tailleMenage": 5,
"region": "/api/regions/1",
"secteur": "/api/secteurs/1",
"commune": "/api/communes/1",
"chefMenage": {
"nomComplet": "Mamadou Diallo",
"sexe": "M",
"age": 45,
"telephone": "771234567"
},
"logement": {
"typeLogement": "maison",
"nbPieces": 4
}
}'
JavaScript
const createMenage = async (data) => {
const response = await fetch('https://sig.ucp-pch.org/api/menages', {
method: 'POST',
headers: {
'Authorization': `Bearer ${localStorage.getItem('token')}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
if (response.status === 422) {
const errors = await response.json();
throw new Error(errors['hydra:description']);
}
if (!response.ok) {
throw new Error('Erreur lors de la création');
}
return response.json();
};
// Utilisation
const newMenage = await createMenage({
tailleMenage: 5,
region: '/api/regions/1',
secteur: '/api/secteurs/1',
commune: '/api/communes/1',
chefMenage: {
nomComplet: 'Mamadou Diallo',
sexe: 'M',
telephone: '771234567'
},
logement: {
typeLogement: 'maison',
nbPieces: 4
}
});
console.log(`Créé: ${newMenage.codeMenage}`);
Python
import requests
def create_menage(token, data):
response = requests.post(
'https://sig.ucp-pch.org/api/menages',
headers={
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
},
json=data
)
if response.status_code == 422:
errors = response.json()
raise Exception(errors['hydra:description'])
response.raise_for_status()
return response.json()
# Utilisation
menage = create_menage(token, {
'tailleMenage': 5,
'region': '/api/regions/1',
'secteur': '/api/secteurs/1',
'commune': '/api/communes/1',
'chefMenage': {
'nomComplet': 'Mamadou Diallo',
'sexe': 'M'
},
'logement': {
'typeLogement': 'maison'
}
})
print(f"Créé: {menage['codeMenage']}")
Notes
- Le
codeMenageest généré automatiquement - Le statut initial est
en_attente(nécessite validation) - Les champs GPS acceptent des chaînes (format decimal)
- Les références (region, secteur, commune) utilisent des IRI
- Le chef de ménage et le logement sont créés automatiquement