I'm attempting to automate data updates of an ArcGIS Online feature service using the REST API.

So far, I've been able to successfully:

  1. Get a valid token from https://www.arcgis.com/sharing/rest/generateToken
  2. Upload a new GeoJSON file to https://www.arcgis.com/sharing/rest/content/users/{user}/items/{feature}/update, passing in the token from step #1
  3. The above does not seem to update the service, so I republish by passing my token and {overwrite:"true"} to https://www.arcgis.com/sharing/rest/content/users/{user}/publish

This is great, it meets the original goal of having an updated dataset in an automated fashion. However, any default styling I configure for the layer goes poof when I republish it. To fix this, I'm trying to use the functionality at https://services5.arcgis.com/{id}/ArcGIS/rest/admin/services/{service}/FeatureServer/0/updateDefinition to pass in the renderer and label information that I'd like to use. Whenever I pass in the same token for steps 3 & 4, it replies with:

{"error":{"code":498,"message":"Invalid token.","details":["Invalid token."]}}

When I check the info from that endpoint to make sure I don't have to go someplace else for my token, I see it is nearly the same URI that I used in step 1. Changing my token URI to the new value doesn't seem to make the token any more valid.

From http://services5.arcgis.com/{id}/ArcGIS/rest/info?f=pjson:

    "currentVersion" : 10.41, 
    "fullVersion" : "", 
    "owningSystemUrl" : "http://www.arcgis.com", 
    "owningTenant" : "{id}", 
    "authInfo" : 
        "isTokenBasedSecurity" : true, 
        "tokenServicesUrl" : "https://www.arcgis.com/sharing/generateToken"

I can visit the endpoint above in my browser and it allows me to edit it without a problem (inspecting my browser traffic shows that it does not pass a token in the post, but instead a cookie with authentication inside)

I've tried requesting a separate token specifically for this one call, and I've tried passing in a { serverURL: 'http://services5.arcgis.com/{id}/arcgis/' } parameter with that token call. Neither of those seem to work.

I feel like I'm missing something simple, but I'm running out of ideas!

  • What settings did you generate your token with? Try changing the referrer to a URL (assuming you're using requestIP)
    – KHibma
    Jan 5 '17 at 21:28
  • I'm passing username, password, client: 'requestip', f: json, and expires 30 in the first call. The app I'm using isn't a web app, so there is no referer, just my local node.js client
    – MichaelM
    Jan 5 '17 at 21:29
  • Instead of requestIP, try: 'referer': "something.com"
    – KHibma
    Jan 5 '17 at 21:33
  • That looks to have worked, thanks @KHibma ! - Can you make it into an answer so I can accept it and give you credit?
    – MichaelM
    Jan 6 '17 at 12:48

I've found requestip to be somewhat unreliable. A better practice is to request a token with a referer instead. So, in the token request, use it with the URL of your app (or a made up, unique one):

'referer': "www.something.com"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.