Need help in http request node

@Steve-Mcl how to send msg.payload value from first node to last node?
say i want to use the value of one msg.payload to last node to use as templete?
what am i doing is send a magnetic torrent url from telegram and i have telegram node which detects and sends that data... cant i use that value like

var url = msg.payload.content
msg.payload = '-----------------------------6688794727912\r\n'+
    'Content-Disposition: form-data; name="urls"\r\n' +
    '\r\n' +
    url;

tried this but does not work..
coz its not sending any value i guess as the flow passes to next node it kills the previous node values i guess
what i want is to send telegram msg value to the funtion node as below and also trigger the 1st node

store it somewhere else in the msg

e.g. use a change node to copy (set) msg.originalPayload from msg.payload (deep copy)

OR in the 1st function...

msg.originalPayload = RED.util.cloneMessage(msg.payload)

then at the end you should see it in msg.originalPayload

1 Like

edit: works with change node deep copy

did not work
i added this in 1st funtion node before 1st http request node

msg.originalPayload = RED.util.cloneMessage(msg.payload.content);

then im reading it in other funtion node as

var y = msg.responseCookies.SID.value
var x = "SID="
var cookie = x + y
var link = msg.originalPayload
msg.url = "http://192.168.0.104:8080/api/v2/torrents/add";

msg.headers = {};
msg.method = "POST";
msg.headers["cookie"] = "cookie";
msg.headers["POST"] = "/api/v2/torrents/add HTTP/1.1";
msg.headers["Content-Type"] = "multipart/form-data; boundary=---------------------------6688794727912";
msg.headers["Host"] = "192.168.0.104:8080";
msg.cookie = cookie;
msg.payload = '-----------------------------6688794727912\r\n'+
    'Content-Disposition: form-data; name="urls"\r\n' +
    '\r\n' +
    link;
return msg;

but still it does not work
payload fails
and the first payload i saved is showing up in headers but cant read the value from it ..
image
and this is the funtion node debug

image

where does msg.payload.content come from? Which ever node generates that - put this code AFTER that.

Use debug nodes everywhere to understand what is happening in your flow.

Use node.warn inside your function nodes to understand what is going on inside the function

e.g. you show msg.originalPayload as being undefined - was it EVER anything?

e.g. add a node.warn...

//
// ... other code ...
//
node.warn({ "msg.payload.content": msg.payload.content})
msg.originalPayload = RED.util.cloneMessage(msg.payload.content)
node.warn({ "msg.originalPayload": msg.originalPayload })
//
// ... other code ...
//
1 Like

it works now..when i add msg.originalPayload = RED.util.cloneMessage(msg.payload.content) at the top in fn node then it works


if i do the same by adding at bottom it fails to send (whats where i made mistake but no sure why is it like that?)


PS, please dont post pictures of code (use the code button and paste as text)

1 Like

hanks @Steve-Mcl ...sorry for posting images of code.
one help...i have two telegram trigger nodes one which detects commands and other for messages and contents.. what i want is something like wait untill or switch
say if i send /movie as message in telegram followed by message as x then it should start one flow
same if i send /series as message in telegram followed by message as x then it should start other flow.
Why am i doing this is: movies or series both the torrent magnet link starts with magnet and i want to switch this because i want to add torrent with different categories which download files to specific filepath which then runs script internally to scan and add that to jelly fin server under movies and series section

This is a different subject.

Please mark it as solved.

For your new question: Please start a new thread with appropriate title. Include detail like "what you have" what you are trying to do" and a minimal flow using only standard nodes (e.g. an inject can "fake" the incoming telegram message" and a debug node can "fake" the outgoing telegram node)

@Steve-Mcl
how do i set this up in nodered? for json object and send as POST to http://192.168.0.104:8080/api/v2/app/setPreferences

json={"save_path":"C:/Users/Dayman/Downloads","queueing_enabled":false,"scan_dirs":{"C:/Games": 0,"D:/Downloads": 1}}


should i create header with json?

Same as before but set the payload before it goes to the HTTP node...

// ... other code
msg.payload = {
  "save_path":"C:/Users/Dayman/Downloads",
  "queueing_enabled":false,
  "scan_dirs":{
    "C:/Games": 0,
    "D:/Downloads": 1
  }
}
return msg;
1 Like

thanks one quick question i get a data with time like this
"added_on":1665160878
what i want is to compare time now with current time and check if its greater than 1665160878 what time format is this?
if i could get current time in this format i can do the compare stuff

Again. This is a different question & should be a different thread.

But to save you some time that number is a JavaScript epoch

From the net...

epoch time is Unix style in milliseconds since 01/01/1971, which means it returns a long number in milliseconds. It is epoch time or Unix timestamp. Javascript provides the Date object provides the date and time-related things

Didnt proof read that - @E1cid spotted a mistake. The number you are describing is a Unix Epoch which is number of s since 1970/01/01 00:00:00 UTC

JS works in MS so multiply by 1000 to get UTC

e.g: 1665160878 x 1000 = 16651608780000 == 2022-10-07T16:41:18.000Z
image

Search the forum for epoch or start a new thread.

Looks like a unix timestamp in seconds.
So all you need to do is multiple it by a 1000, then it can be compared with a Node-red JS timestamp, which is in milliseconds

[Edit] The unix Epoch date is 01-01-1970

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.