Select to view content in your preferred language

Invalid JSON Primitive using applyEdits

733
3
Jump to solution
09-27-2023 12:15 PM
Labels (1)
MichaelKohler
Occasional Contributor III

Trying to use applyEdits to a hosted feature service in ArcGIS Online. I went to the query endpoint for the individual layer and queried out a feature which returned the features json for a single feature.

 

 "features" : [
    {
      "attributes" : {
        "OBJECTID" : 62428, 
        "ADDID" : 63649, 
        "LONGITUDE" : "-20.39381937", 
        "LATITUDE" : "57.21860018", 
        "geoy" : 111.95, 
        "geox" : 170, 
        "ISSHELLADDRESS" : 0, 
        "SHELLID" : 0, 
        "DuplexID" : 63650, 
        "ADDRESSWITHUNIT" : "WhAt NOW MaN", 
        "ISSHFA" : 0
      }, 
      "geometry" : 
      {
        "x" : 170.00002741069, 
        "y" : 111.9500441551
      }
    }
  ]

 

 

I can take this, minus the "features" tag, and stick it in the updateFeatures for that individual feature layer and it works.

Then I put the same content in a format for the applyEdits like below, and it fails.

 

[
  {
    "id" : 0,
    "adds" : [],
    "updates": [
      {
        "geometry": {
          "x" : 170.0069, 
		  "y" : 11.9500
        },
        "attributes": {
			"OBJECTID": 62428,
			"ADDID": 63649,
			"LONGITUDE": -80.39381937,
			"LATITUDE": 27.21860018,
			"geoy": 111.95,
			"geox": 970,
			"ISSHELLADDRESS": 0,
			"SHELLID": 0,
			"DuplexID": 63650,
			"ADDRESSWITHUNIT": "It's Me I am the problem",
			"ISSHFA": 0
        } 
      } 
    ],
    "deletes": [] 
  }
]

 

 

I have tried multiple permutations with the larger format by removing the adds and deletes leaving just the updates and it's the same thing. I get back "code" : 400... Unable to apply edits. Other times it will show the Invalid JSON Primitive in "edit"

I'm sure, like most times, I'm just missing something simple here.

 

Thanks as always!

1 Solution

Accepted Solutions
pslgisAdmin
New Contributor II

I knew it was something stupid! I had run into this well over 5 years ago with our address database when I created a GIS Services.DLL for the other app devs to use.

We are moving the address app from WPF to Angular, so apparently, I had to run through the same gauntlet! I've requested them to not make them string fields in the new table.

I seem to remember you helping me out on something before and I see you on here in a lot of posts. Thank you so much for your efforts.

View solution in original post

3 Replies
jcarlson
MVP Esteemed Contributor

Hard to know for sure, but it's probably just submitting the wrong type to one of the fields. Although, that's usually a 500 code. In your example, "LATITUDE" and "LONGITUDE" are strings in the query, but floats in the update. Is that right?

Are you including a token in your update request? If the layer isn't publicly editable, you'll need one.

- Josh Carlson
Kendall County GIS
jcarlson
MVP Esteemed Contributor

Regarding tokens: that applies if you're hitting the REST endpoint using a POST request. If you're doing this from the services directory, it handles the token in the background once you log in.

- Josh Carlson
Kendall County GIS
0 Kudos
pslgisAdmin
New Contributor II

I knew it was something stupid! I had run into this well over 5 years ago with our address database when I created a GIS Services.DLL for the other app devs to use.

We are moving the address app from WPF to Angular, so apparently, I had to run through the same gauntlet! I've requested them to not make them string fields in the new table.

I seem to remember you helping me out on something before and I see you on here in a lot of posts. Thank you so much for your efforts.