im having trouble updating a feature layer of mine using react, in the website documentation: Documentation
it says to do some simple things, a simple post request with attributes attached, yet nothing worked, when im trying to send a post request all i get is just a preview of the page, like the request is not post, maybe im doing something wrong, here is the code:
const updateFeature = async (objectId: number, newMuniValue: string): Promise<void> => {
const layerUrl = 'feature layer url goes here';
const updateParams = {
f: 'json',
features: JSON.stringify([{
attributes: {
OBJECTID: objectId,
Muni: newMuniValue
}
}]),
token: token
};
const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams(updateParams)
};
try {
const response = await fetch(layerUrl, requestOptions);
const data = await response.json();
console.log('Update response:', data);
if (data.updateResults && data.updateResults[0].success) {
alert('Update successful');
} else {
alert('Update failed');
}
} catch (error) {
console.error('Error updating feature:', error);
alert('Error updating feature');
}
};
then im using it in a button, the token is valid
can you help with construct the post request to be valid and working? perhaps they changed something in their way of updating a rest api ArcGIS feature layer and im not aware.