Unable to render proper output from webhook

I am trying to create a webhook that will get an array of integers from a single field (field2) of a Thingspeak channel. I need to minimize the output so as not to overrun the webhook limit. The output I'm trying to produce would be like this:
235,
420,
399,
410,
410,
.....

what I get so far is this:
2024-01-31 14:12:11 -0600,1297,HEAT,235,61.6,18.2,26.1,68.0_67.4,52.2_51.0,
2024-01-31 15:12:26 -0600,1298,HEAT,420,62.0,32.8,46.2,70.1_67.7,44.9_43.0,
2024-01-31 17:28:45 -0600,1299,HEAT,399,61.7,31.4,44.8,70.3_68.3,48.2_45.3,
2024-01-31 20:03:46 -0600,1300,HEAT,410,61.9,31.3,44.7,70.5_68.6,47.4_45.3,
2024-01-31 21:31:04 -0600,1301,HEAT,410,61.6,31.2,44.8,69.9_67.5,48.3_44.7,
2024-01-31 23:48:44 -0600,1302,HEAT,410,62.3,30.6,43.7,7

Below is the custom template I'm using although I've tried many variations. I think I need to use a responseTemplate but everything I've tried so far seems to kill the output. Would anyone have some insight into my problem?
Thank you,
Bob
{
"name": "Get_HVAC_RT_History",
"event": "Get_HVAC_RT_History",
"deviceID": "999999999999999",
"responseTopic": "",
"errorResponseTopic": "",
"url": "https://api.thingspeak.com/channels/0000000/feeds.csv?api_key=MYREADKEY&minutes=1440&offset=-6",
"requestType": "GET",
"noDefaults": true,
"rejectUnauthorized": true,
"responseTemplate": ""
}
}

You can't process and return a subset of the data when using the csv feed in Thinkspeak.

One option is to switch to feeds.json and use mustache variables to parse and return a subset of the output.

1 Like

Thank you Rick. I tried the json before but I guess the moustache was not correct in the response template. Now I can get the first instance of field2 with {{feeds.0.field2}} but I don't know the moustache expression to get all the values and I can't seem to find out how to do it. Is there a tutorial somewhere that tells how?
Thanks,
Bob
The formatted JSON looks like this:

{
   "channel":
       {
           "id":2183737,
           "name":"ArgonRLW4_HVAC_RT",
           "description":"ArgonRLW4_HVAC_RT",
           "latitude":"0.0",
           "longitude":"0.0",
           "field1":"EVT",
           "field2":"RT",
           "field3":"PD_AVG",
           "field4":"TITOD_AVG",
           "field5":"TITOD_MAX",
           "field6":"AT_MAX_MIN",
           "field7":"AH_MAX_MIN",
           "field8":"key",
           "created_at":"2023-06-09T17:45:01-06:00",
           "updated_at":"2023-10-15T17:37:17-06:00",
           "last_entry_id":1322
       },
   "feeds":
       [
           
               {
                   "created_at":"2024-02-02T08:04:01-06:00",
                   "entry_id":1321,
                   "field1":"HEAT",
                   "field2":"420",
                   "field3":"62.1",
                   "field4":"31.3",
                   "field5":"44.7",
                   "field6":"69.2_67.0",
                   "field7":"44.8_41.7",
                   "field8":
               },
           
               {
                   "created_at":"2024-02-02T08:59:09-06:00",
                   "entry_id":1322,
                   "field1":"HEAT",
                   "field2":"409",
                   "field3":"62.2",
                   "field4":"30.9",
                   "field5":"44.2",
                   "field6":"69.1_67.0",
                   "field7":"44.7_41.8",
                   "field8":
               }
       ]
}

You need to put something in field8. The number 0 would work. The problem is that the feeds JSON is not valid JSON, so it won't be able to be parsed.

The technique is explained and there's a tester which is way faster than trying things randomly in the JSON page.

The response template will be similar to this. It iterates the feeds key array for objects, and extracts the field2 object into a comma-separated list.

{{#feeds}}{{field2}},{{/feeds}}
2 Likes

I tried your example and it worked perfectly. I'll also check out the tester link you set for better understanding in future projects. I did not have to insert a zero in field8 but it parsed completely anyway.
Thank You,
Bob

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