Pular para o conteúdo principal

POST /api/menages

Cria um novo agregado familiar com o seu chefe de familia e habitacao.

Endpoint​

POST /api/menages

Headers​

HeaderValorObrigatorio
AuthorizationBearer {token}Sim
Content-Typeapplication/jsonSim

Corpo da requisicao​

{
"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"
}
}

Campos do agregado familiar​

CampoTipoObrigatorioDescricao
tailleMenageintegerSimNumero de pessoas (> 0)
regionIRISimReferencia a regiao
secteurIRISimReferencia ao setor
communeIRISimReferencia ao municipio
localiteIRINaoReferencia a localidade
latitudestringNaoLatitude GPS (decimal)
longitudestringNaoLongitude GPS (decimal)
nbEnfants04integerNaoCriancas 0-4 anos
nbEnfants514integerNaoCriancas 5-14 anos
nbAdultes1564integerNaoAdultos 15-64 anos
nbPersonnes65PlusintegerNaoPessoas 65+ anos

Campos do chefe de familia​

CampoTipoObrigatorioDescricao
nomCompletstringSimNome e apelido
sexestringNao"M" ou "F"
ageintegerNaoIdade
niveauEducationstringNaoNivel de educacao
occupationPrincipalestringNaoAtividade
statutMatrimonialstringNaoSituacao familiar
telephonestringNaoNumero de telefone
numeroMobileMoneystringNaoNumero Mobile Money

Campos da habitacao​

CampoTipoObrigatorioDescricao
typeLogementstringNaoTipo de habitacao
statutOccupationstringNaoEstado de ocupacao
nbPiecesintegerNaoNumero de divisoes
materiauMurstringNaoMaterial das paredes
sourceEaustringNaoFonte de agua

Resposta de sucesso​

Codigo: 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"
}

Respostas de erro​

422 Unprocessable Entity - Erro de validacao​

{
"@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"
}

Exemplos​

cURL​

curl -X POST https://sig.example.com/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.example.com/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('Erro ao criar');
}

return response.json();
};

// Utilizacao
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(`Criado: ${newMenage.codeMenage}`);

Python​

import requests

def create_menage(token, data):
response = requests.post(
'https://sig.example.com/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()

# Utilizacao
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"Criado: {menage['codeMenage']}")

Notas​

  • O codeMenage e gerado automaticamente
  • O estado inicial e en_attente (necessita validacao)
  • Os campos GPS aceitam cadeias de caracteres (formato decimal)
  • As referencias (region, secteur, commune) utilizam IRIs
  • O chefe de familia e a habitacao sao criados automaticamente