Parsing POST Data


#1

1) Give a description of the problem
I’m trying to extract the a variable from the post data sent by Emby into my piston via Webhooks. Piston URL has been copied from into WebHook plugin and posts directly to it.

There is no way to filter the outbound URL in Emby so need to parse the post data in order to trigger different actions depending on the event.

There are 4 variables;

playback.pause / unpause / stop / start

2) What is the expected behaviour?
Being able to take the variable and use that to trigger different events e.g. turn a light off when unpausing and a light on when pausing.

3) What is happening/not happening?
Unable to parse variable to create bespoke triggers for events.

**4) Post a Green Snapshot of the piston

5) Attach logs after turning logging level to Full
16/04/2020, 02:12:13 +757ms
+1ms ╔Received event [Home].execute = XX.XXX.203.XXX with a delay of 29ms
+48ms ║RunTime Analysis CS > 12ms > PS > 27ms > PE > 9ms > CE
+50ms ║Runtime (37277 bytes) successfully initialized in 27ms (v0.3.110.20191009) (49ms)
+51ms ║╔Execution stage started
+54ms ║║Cancelling statement #7’s schedules…
+57ms ║║Executed virtual command parseJson (1ms)
+61ms ║║Executed virtual command setVariable (2ms)
+67ms ║║Comparison (string) Event is (string) playback.unpause = false (1ms)
+68ms ║║Condition #11 evaluated false (4ms)
+69ms ║║Condition group #10 evaluated false (state did not change) (6ms)
+71ms ║╚Execution stage complete. (20ms)
+72ms ╚Event processed successfully (71ms)
16/04/2020, 02:12:05 +840ms
+0ms ╔Received event [Home].execute = XX.XXX.203.XXX with a delay of 43ms
+64ms ║RunTime Analysis CS > 16ms > PS > 38ms > PE > 10ms > CE
+66ms ║Runtime (37278 bytes) successfully initialized in 38ms (v0.3.110.20191009) (65ms)
+67ms ║╔Execution stage started
+71ms ║║Cancelling statement #7’s schedules…
+74ms ║║Executed virtual command parseJson (1ms)
+79ms ║║Executed virtual command setVariable (3ms)
+84ms ║║Comparison (string) Event is (string) playback.unpause = false (1ms)
+86ms ║║Condition #11 evaluated false (5ms)
+87ms ║║Condition group #10 evaluated false (state did not change) (6ms)
+88ms ║╚Execution stage complete. (21ms)
+90ms ╚Event processed successfully (89ms)


#2

I think we’d need to see a sample of what is sent by Emby to be of any help to you.
(feel free to anonymize any personal data, but keep the rest intact)


#3

I’m not familiar with emby, however, have you looked at the contents of $args, the json data maybe held in there.


#4

Here you go, I’ve lifted an exert I capture with PipeDream - the thing I am trying to capture is the variable “Event”, in this instance it’s playback.unpause. I can’t work how to to highlight it below but if you follow the line which starts body raw you will see the Event variable shortly after.

{
  "method": "POST",
  "path": "/",
  "query": {},
  "headers": {
    "x-forwarded-for": "XXXX",
    "x-forwarded-proto": "https",
    "x-forwarded-port": "443",
    "host": "XXXX.m.pipedream.net",
    "x-amzn-trace-id": "Root=1-XXXX",
    "content-length": "5931",
    "user-agent": "Emby Server/4.4.2.0",
    "accept-encoding": "deflate",
    "content-type": "multipart/form-data; boundary=\"XXXX\""
  },
  "bodyRaw": "--XXXX\r\nContent-Type: application/json; charset=utf-8\r\nContent-Disposition: form-data; name=data\r\n\r\n{\"Event\":\"playback.unpause\",\"User\":{\"Name\":\"server\",\"ServerId\":\"XXXX\",\"ConnectUserName\":\"XXXX\",\"ConnectLinkType\":\"LinkedUser\",\"Id\":\"XXXX\",\"HasPassword\":true,\"HasConfiguredPassword\":true,\"HasConfiguredEasyPassword\":false,\"LastLoginDate\":\"2020-03-29T17:16:46.6982094+00:00\",\"LastActivityDate\":\"2020-04-16T01:12:05.6460414+00:00\",\"Configuration\":

#5

Thanks for your reply, Paul. I’m still very new to this so not totally sure how I’d do this.


#6

I’m just getting into this myself, trying to write some node.js code to relay requests from Plex to webcore and stripping out a jpeg that webcore can’t handle.

Try calling the following piston from emby, and set logging to full. Hopefully you’ll see the data you want in the $args variable.

I suspect you maybe can access the value you require using the expression $args.data.Event


#7

Cheers Paul, that was helpful. This is what it has logged, you can see the Event data is being pulled.

Sorry to ask for all the baby steps but how would one access the value “playback.start” in order for me to trigger something in smartthings?

16/04/2020, 11:45:09 +692ms
+0ms ╔Received event [Home].execute = XXXX with a delay of 33ms
+54ms ║RunTime Analysis CS > 15ms > PS > 32ms > PE > 7ms > CE
+56ms ║Runtime (36158 bytes) successfully initialized in 32ms (v0.3.110.20191009) (55ms)
+57ms ║╔Execution stage started
+61ms ║║Cancelling statement #1's schedules...
+65ms ║║data:{"Event":"playback.start","User":{"Name":"server","ServerId":"XXXX,"ConnectUserName":"XXXX","ConnectLinkType":"LinkedUser","Id":"XXXX","HasPassword":true,"HasConfiguredPassword":true,"HasConfiguredEasyPassword":false,"LastLoginDate":"2020-03-29T17:16:46.6982094+00:00","LastActivityDate":"2020-04-16T10:45:10.2185611+00:00","Configuration":{"AudioLanguagePreference":"eng","PlayDefaultAudioTrack":false,"SubtitleLanguagePreference":"","DisplayMissingEpisodes":false,"GroupedFolders":[],"SubtitleMode":"None","DisplayCollectionsView":false,"EnableLocalPassword":false,"OrderedViews":["XXXX","XXXX"],"LatestItemsExcludes":[],"MyMediaExcludes":[],"HidePlayedInLatest":false,"RememberAudioSelections":true,"RememberSubtitleSelections":true,"EnableNextEpisodeAutoPlay":false},"Policy":{"IsAdministrator":true,"IsHidden":false,"IsHiddenRemotely":true,"IsDisabled":false,"BlockedTags":[],"IsTagBlockingModeInc...[TRUNCATED]
+66ms ║║Executed virtual command log (1ms)
+68ms ║╚Execution stage complete. (12ms)
+69ms ╚Event processed successfully (69ms)

#8

I’ve figure it out, thanks for your help. As you say, by pulling the $args.data. Event I could isolate the string I needed and then compare that to a value which then triggers my lights in Smartthings.

For anyone interested here is what I’ve come up with;


#9

Thanks for this. I’m also trying to connect Emby to WebCore. Fore some reason I do not get the ||data: line with the events like you did when logging the events. Any advice is greatly appreciated.

Received event [VanHome].execute = ] with a delay of 28ms, canQueue: true, calledMyself: false
+12ms ║RunTime initialize > 11 LockT > 1ms > rtDT > 1ms > pistonT > 0ms (first state access 9 6 5)
+15ms ║Runtime (5807 bytes) successfully initialized in 1ms (v0.3.113.20210703_HE)
+16ms ║╔Execution stage started
+18ms ║║Cancelling statement #1’s schedules…
+22ms ║║[referer:null, remoteAddr:[
**]]
+24ms ║║Executed virtual command log (3ms)
+28ms ║╚Execution stage complete. (12ms)
+31ms ╚Event processed successfully (28ms)