Select to view content in your preferred language

addAttachment with attachment from URL?

1606
2
08-05-2021 01:33 PM
by Anonymous User
Not applicable

Hello,

I am trying to us the ArcGIS Rest API to add an attachment to a service. Attachments are enabled. My situation is that I have a Survey123 that when submitted has a web hook connected to Microsoft Power Automate. In Power Automate, I make a REST API call for Execute Task (Export Web Map Task). I parse the JSON to get the resulting URL that contains the image I'm after. I then make a GET http request for the image URL returned in the previous step. I finally make a POST request for the addAttachment method and pass the body of the GET request performed on the image as the attachment parameter. This results in a generic error that isn't helpful at all. Any idea what I am doing wrong?

 

Alternatively, I thought about using the ArcGIS API for Python and using the add attachment functionality there. This works great when pointing to a local file, but when I point to URL it errors asking for a file path. Any idea how I could use python to add an attachment form URL?

 

Thanks,

Nikholai

2 Replies
TedChapin
Frequent Contributor

You can use an HTTP action with the addAttachment request. You have to use a multipart request, which means you don't put the request parameters in the query string of the http request. You construct a Body with the multipart form syntax. Here's an example Body:

{
  "$content-type": "multipart/form-data",
  "$multipart": [
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"attachment\"; filename=\"@{outputs('Parse_job_result')['body']['resultInfo']['resultFiles'][0]['name']}\""
      },
      "body": "@{body('HTTP_get_file')['$content']}"
    },
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"f\""
      },
      "body": "json"
    },
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"token\""
      },
      "body": "@{body('Parse_get_token')?['token']}"
    }
  ]
}

There 3 pieces of dynamic content:
Filename: in the case of a S123 feature report, get this from the job result info
Body: use the output of a http get request. In the case of S123 feature reports, use the url parameter returned by the job (if you leave out the uploadInfo parameter the report doesn't get created as a content item but you get a url directly to the Amazon S3 file)
Token: token obtained from generateToken with built-in user credentials

Here are some articles I used:
https://ashiqf.com/2021/07/25/how-to-use-form-data-and-form-urlencoded-content-type-in-power-automat...


https://willpage.dev/2019/12/20/using-the-http-action-to-post-multipart-form-data-in-power-automate-...

 

TL2
by
Frequent Contributor

@Anonymous User wrote:

Hello,

I am trying to us the ArcGIS Rest API to add an attachment to a service. Attachments are enabled. My situation is that I have a Survey123 that when submitted has a web hook connected to Microsoft Power Automate. In Power Automate, I make a REST API call for Execute Task (Export Web Map Task). I parse the JSON to get the resulting URL that contains the image I'm after. I then make a GET http request for the image URL returned in the previous step. I finally make a POST request for the addAttachment method and pass the body of the GET request performed on the image as the attachment parameter. This results in a generic error that isn't helpful at all. Any idea what I am doing wrong?

 

Alternatively, I thought about using the ArcGIS API for Python and using the add attachment functionality there. This works great when pointing to a local file, but when I point to URL it errors asking for a file path. Any idea how I could use python to add an attachment form URL?

 

Thanks,

Nikholai


Can you help me with this part:  "In Power Automate, I make a REST API call for Execute Task (Export Web Map Task). I parse the JSON to get the resulting URL that contains the image I'm after."

I am getting a 302 error when calling my rest api.  How are you configuring your GET request?

Thanks.

0 Kudos