How to POST using addAttachment?

712
1
08-01-2019 02:05 PM

How to POST using addAttachment?

posted on behalf of user: Eric Thomas. 

Hello,

Has anyone used the REST API to POST an attachment (photo.png) to a Feature Service using `addAttachment`? The documentation seems incomplete. 

In Postman:

- Method: POST

URL: https://services1.arcgis.com/<serviceName>/ArcGIS/rest/services/<name>/FeatureServer/0/addAttachment?

- POST Params: `token` : `<myToken>, `f` : `json`

- POST Body:

    - Tried `form-data` with `key` : `attachment` and `value` : `file` and selected a .png file. DID NOT WORK

    - Tried `binary` and selected a .png file. DID NOT WORK

- Response

{
    "error": {
        "code": 400,
        "message": "Error: Feature (ID: addAttachment) not found",
        "details": [
            "Unable to retrieve feature."
        ]
    }
}

The documentation states that "...This operation is available only if the layer has advertised that it has attachments. A layer has attachments if its hasAttachments property is true."

My feature service seems to have hasAttachments set to true...

...but the error is shown when I put this url into the browser:https://services1.arcgis.com/<serviceName>/ArcGIS/rest/services/<name>/FeatureServer/0/addAttachment?

Can anyone see what I'm missing? Have any insights? 

Thank you

Good morning Eric,

Some insights:

  • You don't add an attachment to a feature service, but to a feature service feature resource instead, so you URL should contain an ID of a feature to add the attachment to.

(From the documentation:

Add an attachment using the addAttachment operation on a feature service feature resource. In this sample URL, the addAttachment operation is performed on feature ID 818654 belonging to layer 0 of the 311Incidents feature service:

https://services.myserver.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0/818654/addAttachment

... but further explanation is missing)

I don't know if you are into Python, but you might be interested in the work of Caleb Mackey‌, who is the author of restapi, a Python API for working with ArcGIS REST Services, which is actively maintained on https://github.com/Bolton-and-Menk-GIS/restapi

Please let us know your solution, when you have found it.

HTH,

Egge-Jan

Hi Egge-Jan Pollé‌, thanks for the reply...

  1. How do I get the feature ID of an Item that I JUST created so that I can use it to addAttachment?

Example:

- I use the POST method from our previous conversation to create a feature

- The response I receive is:

{ "addResults": [ { "objectId": 23, "uniqueId": 23, "globalId": "7A8A55E9-D95D-4341-ADBE-52632EA46DAB", "success": true } ] }

- Of these, ObjectId, UniqueId, GlobalId, which one is the "FeatureId" required for the addAttachments action?

This document was generated from the following discussion: How to POST using addAttachment?

Comments

Michelle Mathias‌ do you know if Eric found a way to get the three POST requests working? If there are still unanswered questions here I would recommend creating a case with Esri Support - Support will be able to take a closer look at and troubleshoot the specific workflows. 

Thanks,

Peter

Version history
Revision #:
1 of 1
Last update:
‎08-01-2019 02:05 PM
Updated by:
 
Contributors