From 8702b374306b18e924cf20ff0c5a7c78f97fa82f Mon Sep 17 00:00:00 2001 From: Cameron Moore Date: Tue, 24 Dec 2019 12:38:12 -0600 Subject: [PATCH] Add multipart form data examples --- docs/Hook-Examples.md | 74 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-) diff --git a/docs/Hook-Examples.md b/docs/Hook-Examples.md index 1f0a031..1a95745 100644 --- a/docs/Hook-Examples.md +++ b/docs/Hook-Examples.md @@ -287,12 +287,12 @@ __Not recommended in production due to low security__ ] ``` -# JIRA Webhooks +## JIRA Webhooks [Guide by @perfecto25](https://sites.google.com/site/mrxpalmeiras/notes/jira-webhooks) -# Pass File-to-command sample +## Pass File-to-command sample -## Webhook configuration +### Webhook configuration
 [
@@ -315,7 +315,7 @@ __Not recommended in production due to low security__
 ]
 
-## Sample client usage +### Sample client usage Store the following file as `testRequest.json`. @@ -474,3 +474,69 @@ Given the following payload: } ] ``` + +## Multipart Form Data + +Example of a [Plex Media Server webhook](https://support.plex.tv/articles/115002267687-webhooks/). +The Plex Media Server will send two parts: payload and thumb. + +```json +[ + { + "id": "plex", + "execute-command": "play-command.sh", + "trigger-rule": + { + "match": + { + "type": "value", + "parameter": { + "source": "payload" + "name": "payload.event", + }, + "value": "media.play" + } + } + } +] +``` + +Each part of a multipart form data body will have a `Content-Disposition` header. +An example header: + +``` +Content-Disposition: form-data; name="payload"; filename="payload.json" +``` + +We key off of the `name` attribute in the `Content-Disposition` value. + +If the named part is JSON but has an incorrect `Content-Type`, +use the `parse-parameters-as-json` setting to force it to be parsed as JSON: + +```json +[ + { + "id": "plex", + "execute-command": "play-command.sh", + "parse-parameters-as-json": [ + { + "source": "payload", + "name": "payload" + } + ], + "trigger-rule": + { + "match": + { + "type": "value", + "parameter": { + "source": "payload" + "name": "payload.event", + }, + "value": "media.play" + } + } + } +] + +```