Error: Invalid property expression: unexpected ' ' at position 1

I don’t understand this error message.
I get it when I do a media_player seek to resume the last watched casted show to the same position as when I stoped it.

This is the current sequence:

The switch is to switch between either saving the position when I stop a cast (the lower part) or to resume the play at the same position I stoped the play (upper part).

This setup I have now only uses one entity to save the in, but I will expand this to more later.

The upper function node does the following:

Loop through all entities (currently only one) that has a specific attribute.
Make sure the content ID is the same in the saved entity as the one being played.
Make sure the app name (play service: Netflix, HBO, etc.) in the saved entity as the one being played.
Get the media position that was saved and use it in the payload when it’s sent to the call service node.

var position = 0;
msg.list.forEach(function (value,index){
    if(value.attributes.media_content_id === msg.data.new_state.attributes.media_content_id){
        if(value.attributes.app_name === msg.data.new_state.attributes.app_name){
            position = value.attributes.media_position;
        }
    }
});

msg.payload = {
    data:{
        "entity_id": "media_player.chromecast_vardagsrum",
        "seek_position": position,
    }
}

return msg;

call service node is set up like this:

[{"id":"99474dbf.3a0b4","type":"switch","z":"94bc1df0.962d9","name":"","property":"data.old_state.state","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"},{"t":"eq","v":"playing","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":490,"y":2540,"wires":[["b296cbeb.2de478"],["eaf27e51.49d42"]]},{"id":"8f160738.cd1e78","type":"server-state-changed","z":"94bc1df0.962d9","name":"","server":"4bbca37b.1700ec","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"media_player.chromecast_vardagsrum","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":220,"y":2540,"wires":[["99474dbf.3a0b4"]]},{"id":"b296cbeb.2de478","type":"ha-wait-until","z":"94bc1df0.962d9","name":"","server":"4bbca37b.1700ec","outputs":2,"entityId":"media_player.chromecast_vardagsrum","entityIdFilterType":"exact","property":"state","comparator":"is","value":"playing","valueType":"str","timeout":"10","timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":620,"y":2500,"wires":[["9df4f985.83bc98"],[]]},{"id":"eaf27e51.49d42","type":"function","z":"94bc1df0.962d9","name":"","func":"if(typeof(msg.data.old_state.attributes.media_title) != \"undefined\"){\n   return msg; \n}else{\n    \n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":2580,"wires":[["f2b5499b.fdb728"]]},{"id":"9df4f985.83bc98","type":"ha-get-entities","z":"94bc1df0.962d9","server":"4bbca37b.1700ec","name":"","rules":[{"property":"attributes.vardagsrum","logic":"gt","value":"0","valueType":"num"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"list","output_results_count":1,"x":790,"y":2440,"wires":[["d631c14d.469e8","9b850d6b.479c9"]]},{"id":"f2b5499b.fdb728","type":"ha-entity","z":"94bc1df0.962d9","name":"last_watched","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"data.old_state.attributes.media_title","stateType":"msg","attributes":[{"property":"vardagsrum","value":"1","valueType":"str"},{"property":"media_position","value":"data.old_state.attributes.media_position","valueType":"msg"},{"property":"media_content_id","value":"data.old_state.attributes.media_content_id","valueType":"msg"},{"property":"app_name","value":"data.old_state.attributes.app_name","valueType":"msg"},{"property":"media_duration","value":"media_duration","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":810,"y":2580,"wires":[["9b850d6b.479c9"]]},{"id":"d9081699.4a0ee8","type":"inject","z":"94bc1df0.962d9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":600,"y":2440,"wires":[["9df4f985.83bc98"]]},{"id":"d631c14d.469e8","type":"function","z":"94bc1df0.962d9","name":"","func":"var position = 0;\nmsg.list.forEach(function (value,index){\n    if(value.attributes.media_content_id === msg.data.new_state.attributes.media_content_id){\n        if(value.attributes.app_name === msg.data.new_state.attributes.app_name){\n            position = value.attributes.media_position;\n            msg.test = 1;\n        }\n    }\n});\n\n//msg = [];\nmsg.payload = {\n    data:{\n        \"entity_id\": \"media_player.chromecast_vardagsrum\",\n        \"seek_position\": position,\n    }\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":980,"y":2440,"wires":[["6eb95220.beb69c"]]},{"id":"9b850d6b.479c9","type":"debug","z":"94bc1df0.962d9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1170,"y":2560,"wires":[]},{"id":"6eb95220.beb69c","type":"delay","z":"94bc1df0.962d9","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1140,"y":2440,"wires":[["9b850d6b.479c9","5da3ee1e.7cfa4"]]},{"id":"5da3ee1e.7cfa4","type":"api-call-service","z":"94bc1df0.962d9","name":"","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"service_domain":"media_player","service":"media_seek","entityId":"media_player.chromecast_vardagsrum","data":"","dataType":"json","mergecontext":"{ \"seek_position\": msg.position}","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1430,"y":2440,"wires":[[]]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Anyone know why I get that error and what is wrong?

Did you get anywhere with this? There are 2 threads on NR’s forum each time, an added space was the culprit. I don’t see one in your flow, there was mention of a bug in one thread but was a space in the end.

The error is on the call service node.

I think I have found the issue.
Just haven’t had time to try it.

But it seems I placed the JSON in the wrong box in the call service node.
I noticed it this morning when I read my post, see the JSON in merge context…
That was supposed to be in the data field but by some reason it didn’t save ( I wrongfully thought) so I decided to just create the JSON in the function node and add it as payload.

Once I’m finished with everything else I might have time to try and remove that line in the call service and see if it works.

Yes, that was the issue.
When I removed the json in the wrong field then it worked.