Values from array to curl post

Hi,

I need to take values from a json and put them into a post request similar to this:

curl -i -H "Content-Type: application/json" -X POST -d '{"pv_power_forecast":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 70, 141.22, 246.18, 513.5, 753.27, 1049.89, 1797.93, 1697.3, 3078.93, 1164.33, 1046.68, 1559.1, 2091.26, 1556.76, 1166.73, 1516.63, 1391.13, 1720.13, 820.75, 804.41, 251.63, 79.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}' http://localhost:5000/action/dayahead-optim

I need to take the marketprice-values from the following screenshot and place them in the received order (0-23) into the -brackets of the above post request in the same format (so separated with a comma and space).
image

Prior to putting them into the request, I need to manipulate each value by dividing it by 1000 and then substracting 0.0058.

How would I do that?

Thanks!

You can use the request node set to POST to replace curl. I think that the default for POST bodies is JSON so you probably don't need the content-type header but you can add it anyway in the node.

To deal with the data, you can use a change node or a function node to make changes to your origin json data. You send it to the request on the payload property of the msg.

I tried using the change node and moving msg.payload.marketprice to msg.prices.
Did some variations by trying msg.payload[i].marketprice, msg.payload.marketprice and so on.

Is there a way to use a variable to get all these marketprices into one msg?

THat does not match up with your first post. To reproduce the example in the first post, you would need to set msg.payload to JSON containing:

{
    "pv_power_forecast":
        [
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 70, 141.22, 246.18, 513.5, 753.27, 1049.89, 1797.93, 1697.3, 3078.93, 1164.33, 1046.68, 1559.1, 2091.26, 1556.76, 1166.73, 1516.63, 1391.13, 1720.13, 820.75, 804.41, 251.63, 79.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        ]
}

You need to share more information about your input data. You've only described a single msg input so far. There are several ways to reorganise the data on a single input message either using a change node or a function node. If you need to collate multiple input messages, you will need to tell us what they look like, how many, how quickly they arrive, etc.

Hi,

here is a sample output I receive (unconverted):

{
  "object": "list",
  "data": [
    {
      "start_timestamp": 1663912800000,
      "end_timestamp": 1663916400000,
      "marketprice": 415.13,
      "unit": "Eur/MWh"
    },
    {
      "start_timestamp": 1663916400000,
      "end_timestamp": 1663920000000,
      "marketprice": 344.95,
      "unit": "Eur/MWh"
    },
    {
      "start_timestamp": 1663920000000,
      "end_timestamp": 1663923600000,
      "marketprice": 365.18,
      "unit": "Eur/MWh"
    },
    {
      "start_timestamp": 1663923600000,
      "end_timestamp": 1663927200000,
      "marketprice": 354.64,
      "unit": "Eur/MWh"
    },
    {
      "start_timestamp": 1663927200000,
      "end_timestamp": 1663930800000,
      "marketprice": 317.72,
      "unit": "Eur/MWh"
    },
    {
      "start_timestamp": 1663930800000,
      "end_timestamp": 1663934400000,
      "marketprice": 301.71,
      "unit": "Eur/MWh"
    },
    {
      "start_timestamp": 1663934400000,
      "end_timestamp": 1663938000000,
      "marketprice": 305.89,
      "unit": "Eur/MWh"
    },
    {
      "start_timestamp": 1663938000000,
      "end_timestamp": 1663941600000,
      "marketprice": 321.9,
      "unit": "Eur/MWh"
    },
    {
      "start_timestamp": 1663941600000,
      "end_timestamp": 1663945200000,
      "marketprice": 375,
      "unit": "Eur/MWh"
    },
    {
      "start_timestamp": 1663945200000,
      "end_timestamp": 1663948800000,
      "marketprice": 422.09,
      "unit": "Eur/MWh"
    },
    {
      "start_timestamp": 1663948800000,
      "end_timestamp": 1663952400000,
      "marketprice": 460.13,
      "unit": "Eur/MWh"
    },
    {
      "start_timestamp": 1663952400000,
      "end_timestamp": 1663956000000,
      "marketprice": 420.1,
      "unit": "Eur/MWh"
    },
    {
      "start_timestamp": 1663956000000,
      "end_timestamp": 1663959600000,
      "marketprice": 384.94,
      "unit": "Eur/MWh"
    },
    {
      "start_timestamp": 1663959600000,
      "end_timestamp": 1663963200000,
      "marketprice": 385.43,
      "unit": "Eur/MWh"
    },
    {
      "start_timestamp": 1663963200000,
      "end_timestamp": 1663966800000,
      "marketprice": 369.95,
      "unit": "Eur/MWh"
    },
    {
      "start_timestamp": 1663966800000,
      "end_timestamp": 1663970400000,
      "marketprice": 369.91,
      "unit": "Eur/MWh"
    }
  ],
  "url": "/at/v1/marketdata"
}

At the end, I need to have all values from "marketprice" in the received order in the POST curl.

So the question is how I would place these marketprice values into in the json.

Thanks

You can do that with JSONata but it always takes me a lot of time to get my head into the right "mode" to work it out.

THe "easy" way (if you are a coder), would be something like:

const msg2 = { payload: { pv_power_forecast: [] } }
msg.payload.data.forEach( entry => {
    msg2.payload.pv_power_forecast.push( entry.marketprice )
} )
return msg2

Note that the above is untested but should be about right. Double check that you get the prices in the right order though, JavaScript can occasionally be a bit loose about the order of things. If there is an issue (which hopefully there isn't in this case), you can do a sort on the data array using the timestamp.

Hi!

Thanks, this is getting really close.

Any idea how I would round the values to 2 digits and add a space between each?

Thanks!

You will find advice on how to fix to 2 digits elsewhere in the forum or a quick search will show you a tutorial.

For the space, why would you need that? You are sending JSON not a string.

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