0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Power Automate】URL パラメーターを抽出する

Posted at

URL からパラメーターを抽出します。

入力

URL 例
https://my.sharepoint.com/sites/sample_site/_layouts/15/Doc.aspx?sourcedoc=%7B27751A02-4974-49A6-B231-247559F5ABBB%7D&file=sample_data.xlsx&action=default&mobileredirect=true

手順

image.png

URL からパラメーター部分を取り出し、パラメーター毎に分けて配列にする。

image.png

作成:パラーメーター部分抽出
split(
  last(
    split(
      triggerBody()?['text'],
      '?'
    )
  ),
  '&'
)

KeyValue の配列に変換する

image.png

key
first(split(item(),'='))

image.png

value
decodeUriComponent(last(split(item(),'=')))

中間出力

選択::KeyValue
{
    "body": [
        {
            "key": "sourcedoc",
            "value": "{27751A02-4974-49A6-B231-247559F5ABBB}"
        },
        {
            "key": "file",
            "value": "sample_data.xlsx"
        },
        {
            "key": "action",
            "value": "default"
        },
        {
            "key": "mobileredirect",
            "value": "true"
        }
    ]
}

JSON の連想配列に変換する

以下の記事を参考にしてもらえれば変換できます。

JSON 文字列で変換する方法

上記の変換方法ではなく、[選択] アクションを使った方法を紹介します。

image.png

選択:JSON 文字列加工

range(0, length(body('選択::KeyValue')))
マップ
concat(
  '"', body('選択::KeyValue')?[item()]?['key'], '":',
  '"', body('選択::KeyValue')?[item()]?['value'], '"'
)

結合:カンマ区切りでつなげる

image.png

作成:JSON

image.png

入力
json(concat('{',body('結合:カンマ区切りでつなげる'),'}'))
出力結果
{
    "sourcedoc": "{27751A02-4974-49A6-B231-247559F5ABBB}",
    "file": "sample_data.xlsx",
    "action": "default",
    "mobileredirect": "true"
}

🔗参考サイト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?