Search code examples
power-automate

Power Automate web, using Compose get URL out of text


I want to extract a URL in an email that has about three and download it. I have the below flow.

  1. When a new email arrives in a shared mailbox (V2)
  2. Html to text
  3. Compose (but having trouble here)

(When a new email arrives in a shared mailbox (V2)) Added action to (Html to text) in Content, used Dynamic content outputs. View the code below.

    {
  "type": "OpenApiConnection",
  "inputs": {
    "parameters": {
      "Content": "<p>@{triggerOutputs()}</p>"
    },
    "host": {
      "apiId": "/providers/Microsoft.PowerApps/apis/shared_conversionservice",
      "connection": "shared_conversionservice",
      "operationId": "HtmlToText"
    }
  },
  "runAfter": {}
}

This produced an output of this.

Download Periodic Report
[\"http://email.notifications.xxxxxxxx.xxx/c/nQA1I0dYLR0M88n97jlMuWwxXvZ6k6QuVKj22P42HL9bENp16-_AQAA__-bGnPH\"]
and more URLs in similar formats

 

So, I need to get the URL following the following as my Compose output. It is the link after text Download Periodic Report

http://email.notifications.xxxxxxxx.xxx/c/nQA1I0dYLR0M88n97jlMuWwxXvZ6k6QuVKj22P42HL9bENp16-_AQAA__-bGnPH

I have tried this expression but have not had any luck.

substring(outputs('Html_to_text'), add(indexOf(outputs('Html_to_text'), 'Download Periodic Report ["') + length('Download Periodic Report ["'), 0), sub(indexOf(outputs('Html_to_text'), '"]'), add(indexOf(outputs('Html_to_text'), 'Download Periodic Report ["') + length('Download Periodic Report ["'), 0)))

Show raw outputs

Download Periodic Report\n[\\\"http://.....bGnPH\\\"]

Solution

  • Suggest using split:

    split(
      coalesce(
        split(
          string(outputs('Html_to_text')) , 
          'Download Periodic Report\n[\\\"'
        )?[1],
        ''
      ),
      '\\\"]'
    )[0]