Skip to main content

PUT /api/menages/{id}

Modifies an existing household.

Endpoints

Two endpoints are available:

PUT /api/menages/{id}
POST /api/menages/{id}/update
note

The POST /api/menages/\{id\}/update endpoint is recommended because it avoids certain conflicts with API Platform for complex updates.

Headers

HeaderValueRequired
AuthorizationBearer {token}Yes
Content-Typeapplication/jsonYes

Request Body

Send only the fields to modify:

{
"tailleMenage": 6,
"latitude": "14.7200",
"longitude": "-17.4700",
"chefMenage": {
"telephone": "771234568",
"numeroMobileMoney": "771234568"
},
"logement": {
"nbPieces": 5,
"sourceEau": "puits"
}
}

Success Response

Code: 200 OK

{
"@context": "/api/contexts/Menage",
"@id": "/api/menages/1",
"@type": "Menage",
"id": 1,
"codeMenage": "MEN-2024-00001",
"tailleMenage": 6,
"statut": "actif",
"chefMenage": {
"@id": "/api/chef_menages/1",
"nomComplet": "Mamadou Diallo",
"telephone": "771234568"
},
"updatedAt": "2024-01-20T14:15:00+00:00"
}

Error Responses

404 Not Found

{
"@context": "/api/contexts/Error",
"@type": "hydra:Error",
"hydra:title": "An error occurred",
"hydra:description": "Item not found"
}

422 Unprocessable Entity

{
"@context": "/api/contexts/ConstraintViolationList",
"@type": "ConstraintViolationList",
"violations": [
{
"propertyPath": "tailleMenage",
"message": "This value should be positive."
}
]
}

403 Forbidden

{
"@context": "/api/contexts/Error",
"@type": "hydra:Error",
"hydra:description": "Access Denied."
}

Examples

cURL - Standard PUT

curl -X PUT https://sig.ucp-pch.org/api/menages/1 \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json" \
-d '{
"tailleMenage": 6,
"chefMenage": {
"telephone": "771234568"
}
}'

cURL - POST /update (recommended)

curl -X POST https://sig.ucp-pch.org/api/menages/1/update \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json" \
-d '{
"tailleMenage": 6,
"latitude": "14.7200",
"longitude": "-17.4700",
"chefMenage": {
"telephone": "771234568",
"age": 46
},
"logement": {
"nbPieces": 5
}
}'

JavaScript

const updateMenage = async (id, data) => {
const response = await fetch(
`https://sig.ucp-pch.org/api/menages/${id}/update`,
{
method: 'POST',
headers: {
'Authorization': `Bearer ${localStorage.getItem('token')}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}
);

if (response.status === 404) {
throw new Error('Household not found');
}

if (response.status === 422) {
const errors = await response.json();
throw new Error(errors['hydra:description']);
}

return response.json();
};

// Usage
const updated = await updateMenage(1, {
tailleMenage: 6,
chefMenage: {
telephone: '771234568'
}
});

console.log(`Modified: ${updated.codeMenage}`);

Python

import requests

def update_menage(token, menage_id, data):
response = requests.post(
f'https://sig.ucp-pch.org/api/menages/{menage_id}/update',
headers={
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
},
json=data
)

if response.status_code == 404:
raise Exception('Household not found')

if response.status_code == 422:
raise Exception(response.json()['hydra:description'])

response.raise_for_status()
return response.json()

# Usage
menage = update_menage(token, 1, {
'tailleMenage': 6,
'chefMenage': {
'telephone': '771234568'
}
})

Handling Empty Values

Empty strings are automatically converted:

Field TypeEmpty ValueResult
Decimal fields (GPS)""null
Nullable integers""null
Non-nullable integers""0
tailleMenage""Error (required > 0)

Example

{
"latitude": "",
"longitude": "",
"chefMenage": {
"age": ""
}
}

Result: latitude = null, longitude = null, age = null

Change Geographic Location

curl -X POST https://sig.ucp-pch.org/api/menages/1/update \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json" \
-d '{
"region": "/api/regions/2",
"secteur": "/api/secteurs/5",
"commune": "/api/communes/10",
"localite": "/api/localites/25"
}'

Notes

  • Use POST /api/menages/\{id\}/update for complex updates
  • Relations (region, secteur) are expressed as IRIs
  • Modifications are recorded in the audit history
  • The updatedAt field is automatically updated