POST request to dashboard

Hi i trying to understand how i do a POST request. I use the "http request" and changing "GET" to "POST" and typing in the url https://api.trafikinfo.trafikverket.se/v2/data.json
but where do i put my question?
Is look like this

<REQUEST>
      <LOGIN authenticationkey="MYkey" />
      <QUERY objecttype="TrainAnnouncement" schemaversion="1.8" orderby="AdvertisedTimeAtLocation">
            <FILTER>
                  <AND>
                        <EQ name="ActivityType" value="Avgang" />
                        <EQ name="LocationSignature" value="Nkv" />
                        <OR>
                              <AND>
                                  
                                    <GT name="AdvertisedTimeAtLocation" value="$dateadd(-00:15:00)" />
                                    <LT name="AdvertisedTimeAtLocation" value="$dateadd(14:00:00)" />
                              </AND>
                              <AND>
                                    <LT name="AdvertisedTimeAtLocation" value="$dateadd(00:30:00)" />
                                    <GT name="EstimatedTimeAtLocation" value="$dateadd(-00:15:00)" />
                              </AND>
                        </OR>
                  </AND>
            </FILTER>
            <INCLUDE>AdvertisedTrainIdent</INCLUDE>
            <INCLUDE>AdvertisedTimeAtLocation</INCLUDE>
            <INCLUDE>TrackAtLocation</INCLUDE>
            <INCLUDE>ToLocation</INCLUDE>
      </QUERY>
</REQUEST>

In msg.payload this will be the body for your request.
You can use a Template node for this

Example Flow:

[{"id":"6597464adac2b97e","type":"http request","z":"54efb553244c241f","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://api.trafikinfo.trafikverket.se/v2/data.json","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"Content-Type","keyValue":"","valueType":"other","valueValue":"application/xml"}],"x":620,"y":2380,"wires":[["4cd916d5b0b7430d"]]},{"id":"38ae3ff4ca894356","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":2380,"wires":[["a98976b0540f7c97"]]},{"id":"a98976b0540f7c97","type":"template","z":"54efb553244c241f","name":"xml","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<REQUEST>\n      <LOGIN authenticationkey=\"MYkey\" />\n      <QUERY objecttype=\"TrainAnnouncement\" schemaversion=\"1.8\" orderby=\"AdvertisedTimeAtLocation\">\n            <FILTER>\n                  <AND>\n                        <EQ name=\"ActivityType\" value=\"Avgang\" />\n                        <EQ name=\"LocationSignature\" value=\"Nkv\" />\n                        <OR>\n                              <AND>\n                                  \n                                    <GT name=\"AdvertisedTimeAtLocation\" value=\"$dateadd(-00:15:00)\" />\n                                    <LT name=\"AdvertisedTimeAtLocation\" value=\"$dateadd(14:00:00)\" />\n                              </AND>\n                              <AND>\n                                    <LT name=\"AdvertisedTimeAtLocation\" value=\"$dateadd(00:30:00)\" />\n                                    <GT name=\"EstimatedTimeAtLocation\" value=\"$dateadd(-00:15:00)\" />\n                              </AND>\n                        </OR>\n                  </AND>\n            </FILTER>\n            <INCLUDE>AdvertisedTrainIdent</INCLUDE>\n            <INCLUDE>AdvertisedTimeAtLocation</INCLUDE>\n            <INCLUDE>TrackAtLocation</INCLUDE>\n            <INCLUDE>ToLocation</INCLUDE>\n      </QUERY>\n</REQUEST>","output":"str","x":420,"y":2380,"wires":[["6597464adac2b97e"]]},{"id":"4cd916d5b0b7430d","type":"debug","z":"54efb553244c241f","name":"debug 36","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":840,"y":2380,"wires":[]}]

Note: i have also added Content-Type: application/xml in the http-request that seems to be needed for the server to know what your are sending.
Also changed the http-request Return to be parsed as JS object since its JSON

That works perfect, thanks for the help!

1 Like

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