POST addFeatures not working correctly

3402
2
08-01-2019 02:09 PM

POST addFeatures not working correctly

posted on behalf of user: Eric Thomas. 

Hello,
I'm unable to `addFeatures` to a Feature Service Layer using POST request. The "Add Features" website HTML shows up in my Postman response, not the anticipated:

```

{   "addResults" : [     {       "objectId" : 5,        "uniqueId" : 5,        "globalId" : "11239506-93E4-4B438-93A-47F4A338A",        "success" : true     }   ] }
```
In PostMan:
- METHOD: POST
- URL: https://services1.arcgis.com/<fsl name>/ArcGIS/rest/services/<name>/FeatureServer/0/addFeatures?token=<my token>
- POST REQUEST BODY:
```
[
 {
 "attributes": {
 "eventType": "thing",
 "eventTimezone": "Pacific",
 "startTimeUTC": "2019-05-03T23:44:00Z",
 "startTimeLocal": "2019-05-03T17:44:00",
 "startDate": "2019-05-03",
 "endTimeUTC": "2019-05-03T23:44:00Z",
 "endTimeLocal": "2019-05-03T17:44:00",
 "endDate": "2019-05-03"
 },
 "geometry" : {
 "x" : "-122.412479789999991",
 "y" : "37.770630098000083"
 }
 }
]
```

- RESPONSE: The actual HTML for the Add Features website!!

Can anyone see what I'm missing? 

Thank you!

Hi Eric‌,

I did a little research and I got it working - please see my steps below.

Let's suppose I want to add this feature:

{
  "attributes" : {
    "DESCRIPTION" : "Test case",
    "COLOR" : "Red"
  }, 
  "geometry" : {
        "x" : 165000,
        "y" : 473000
  }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

You can add a feature using the ArcGIS REST Services Directory (see screen capture 1) or using Postman (see screen capture 2).

In Postman the Query Params should be:

features:{ ++"attributes"+:+{ ++++"DESCRIPTION"+:+"Test+case2", "COLOR"+:+"Green" ++},+ ++"geometry"+:+{ ++++++++"x"+:+166000, ++++++++"y"+:+474000 ++} }
rollbackOnFailure:false
f:html
token:<a_valid_token>‍‍‍‍‍‍‍‍

This will result in a successfully added feature.

Does this solve your issue?

Egge-Jan

Hello Egge-Jan Pollé‌. Thank you for the prompt reply. 

I need to submit POST requests in JSON format. I don't see the notation you provided in the documentation. Feels like i'm just missing something in the URL. 

Any other ideas? 

Hi Eric,

In the documentation you are pointing at (Add Features—ArcGIS REST API: Services Directory | ArcGIS for Developers) I did find the specification of the JSON to add a point feature.

Then I used that JSON in the ArcGIS REST Services Directory to add my test case and with the Firefox Developer Tools (F12) I did obtain the parameters of the URL to replicate the process in Postman.

Apparently, the JSON is stored in the features parameter with a lot of plus signs added to it... (It makes me think of this song, Positivity, by Prince: "Have you had your plus sign today?")

So, it was just trial and error that did get me to the URL below.

Is this useful to you? Has your question been answered? If so, do not hesitate to mark an answer as useful and or correct. (Just to help the community to find information that is either useful or correct or both....:-)

BR,

Egge-Jan

https://services.arcgis.com/T9FoPe9aYhFYrvPP/ArcGIS/rest/services/<a_feature_service>/FeatureServer/0/addFeatures?features={ ++"attributes"+:+{ ++++"DESCRIPTION"+:+"Test+case2", "COLOR"+:+"Green" ++},+ ++"geometry"+:+{ ++++++++"x"+:+166000, ++++++++"y"+:+474000 ++} }&rollbackOnFailure=false&f=html&token=<a_valid_token>

I appreciate that very much. Its just not a typical POST request. I don't want to programmatically add all those "+" 's to the body. 

Its very non-typical (like Princes awesome music!!). 

Do you or anyone else have insights on how to submit a JSON POST body that looks like the one in the documentation? 

Thanks again!

Yeah, it is a non-typical Esri solution and I would not know how many plus signs to add either... Maybe someone else can jump in to clarify?

AhA! Figured it out (with your assistance of course)!

In PostMan:
- METHOD: POST
- URL: https://services1.arcgis.com/<fsl name>/ArcGIS/rest/services/<name>/FeatureServer/0/addFeatures?
- POST PARAMS (DO NOT USE POST BODY):
  - features : { "attributes" : { "req_id" : "508389", "req_type" : "Graffiti Complaint - Public Property", "req_date" : "09\/19\/2009", "req_time" : "18:44", "address" : "11TH ST and HARRISON ST", "x_coord" : "6008925.0", "y_coord" : "2108713.8", "district" : "6", "status" : 1 }, "geometry" : { "x" : -122.41247978999991, "y" : 37.770630098000083 } }
  - rollbackOnFailure: false
  - f : json
  - token : <my token>

I'm not used to putting nested JSON within a key:value parameter in Postman. I usually put it within a POST Body.
The combination of your Parameter and this solved the issue. 



Thanks again!

This document was generated from the following discussion: POST addFeatures not working correctly

Comments

Hello,

I am unable to run addFeatures operation from the POSTMAN. I am getting the below error msg

{
    "error": {
        "code"400,
        "message""",
        "details": [
            "This operation is not supported."
        ]
    }
}
I have tried sending the feature by param, body, x-www-form-urlrencoded , all resulted in same error msg. I am also sending the other param f and token.
It will be helpful if someone can share their cURL from postman or share a screenshot from postman how they are passing the features.

I am also unable to post using json in the body. However, I am able to post if doing the same as ESRI does from the web page (urlencoded form body)

Screenshot 2023-11-20 at 12.11.37.png

Version history
Last update:
‎12-12-2021 03:48 AM
Updated by: