aoldring

Web Request Method: POST to ArcGIS Server using ESRI's REST API

Blog Post created by aoldring on Mar 14, 2016

Recently I had a project that required data collected via Nintex Mobile and stored in a SharePoint list to be pushed to an on-premise ArcGIS geodatabase for use in  mapping services. It turns out it is possible to add features to a web map's Feature Service via a Nintex Workflow's Web Request control POST method. However, the documentation and procedure for setting it up are difficult if not impossible to find, vary by ArcGIS server version, and do not pertain to Nintex's specific needs, so I thought I'd write this solution up to share and hopefully make this process easier for other developers.

 

After hours of coming up with generic unspecified 500 and 401 errors, the solution ended up being a problem of URL and post body syntax. I figured it out  working in conjunction with an ESRI developer. It is simple to implement, and works like a charm. I must also give credit to Vadim Tabakman's blog post Nintex Workflow - Talking to Esri ArcGIS UDAs for setting me off on the right track.

 

Before I outline the solution, here's a bit of initial information about the setup:

  • Solution built on SharePoint 2010 Enterprise using Nintex Workflow 2010 Standard
  • ArcGIS Server is version 10.3.1 and has REST enabled
  • POST body is in JSON

 

Solution:

 

  1. Add a Web Request control to your workflow.
  2. Set the URL to: http://<ServerName>/rest/services/<FolderName>/<FeatureServiceName>/FeatureServer/0/addFeatures?f=json
    Note: The critical component here is to include ?f=json at the end of the URL, as Arc only allows POST in JSON.
  3. Enter the username and password of the account authenticated to make POST requests
  4. Select web method "POST".
  5. Leave content type as "application/x-www-form-urlencoded", Keep alive as "No, and Allow auto redirect as "No".
  6. Enter "features=" into the Content body -- this is critical and for me turned out to be the critical missing piece preventing the POST from completion
  7. Place your JSON script into the Content body after "features=". The script must be in the following format:
    [{
                "geometry": {
                            "x": "##.######",
                            "y": "-###.######"
                },
                "attributes":
    {                        "field_name1": "WorkflowVariable",
                            "field_name2": "WorkflowVariable"
                } }]

    I suggest checking your syntax in JSON Lint prior to use. I used the Build String feature to combine my workflow variables, containing Form data, into the above syntax. You can of course have many more attribute fields than are shown here. The field names must correspond to the Feature Server's field names in ArcGIS. See the Add Features documentation on the ESRI site for more information on posting via the REST API.

 

That's it! If your post is successful, you'll see the following results returned:

 

"Response status code: 200 Response content: {"addResults":[{"objectId":####,"globalId":"{globalID}","success":true}]}"

 

Here's an example:

 

 

Hope someone else finds this saves them some time one day.

Outcomes