# HTTP request with specific request headers/payloads

**URL:** <https://discourse.nodered.org/t/http-request-with-specific-request-headers-payloads/77961>\
**Category:** General\
**Tags:** http-request\
**Created:** [26 April 2023 15:58 UTC](https://discourse.nodered.org/t/http-request-with-specific-request-headers-payloads/77961 "2023-04-26T15:58:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![EL\_tech](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@EL\_tech](https://discourse.nodered.org/u/EL_tech)\
**Post date:** [26 April 2023 15:58 UTC](https://discourse.nodered.org/t/http-request-with-specific-request-headers-payloads/77961/1 "2023-04-26T15:58:42Z")

</div>

Hello,  
I would like to show the the current petrol prices to my dashboard.  
For the data reference I use [this](https://github.com/jumpjack/distributori-benzina) link.  
He explains how can I configure a http request.  
For Example:

- Url: [https://carburanti.mise.gov.it/ospzApi/search/area](https://carburanti.mise.gov.it/ospzApi/search/area)
- Header: vuoto
- Payload:
  - region: ([numero](https://carburanti.mise.gov.it/ospzApi/registry/region)),
  - province: ([sigla della provincia](https://carburanti.mise.gov.it/ospzApi/registry/province?regionId=9) oppure null; il link di esempio fornisce l'elenco delle province della regione 9 (Lazio)),
  - town: ([nome del coumne](https://carburanti.mise.gov.it/ospzApi/registry/town?province=RM) oppure null; il link di esempio fornisce la lista dei comuni della provincia di Roma),
  - priceOrder: "asc" o "desc",
  - fuelType: "FuelType-RefuelingMode" (FuelType e RefuelingMode sono numeri (v. sotto))

Example of the header complete:

```auto
{ 
 "region" : 9, 
 "province" : "RM", 
 "town" : "Monterotondo", 
 "priceOrder" : "desc",
 "fuelType": "1-1",
 "refuelingMode" : 1
}

```

For my Node-RED project I found this as a possible solution:

> <https://stackoverflow.com/questions/51745966/node-red-http-post-parameters>

[https://cookbook.nodered.org/http/set-request-header](https://cookbook.nodered.org/http/set-request-header)

I create this node, but unfortunately it doesn't work:

```auto
[
    {
        "id": "cf770b6810ef06f2",
        "type": "inject",
        "z": "67e5e39e7b6a8e54",
        "name": "",
        "repeat": "",
        "crontab": "",
        "once": false,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 220,
        "y": 3500,
        "wires": [
            [
                "28957e037055f9ad"
            ]
        ]
    },
    {
        "id": "28957e037055f9ad",
        "type": "function",
        "z": "67e5e39e7b6a8e54",
        "name": "set payload and headers",
        "func": "msg.headers = {};\nmsg.headers = {\n};\n\n\nmsg.payload = {};\nmsg.payload = {\n 'region' : 9,\n 'province': 'RM',\n 'town' : 'Monterotondo',\n 'priceOrder':'desc', \n 'fuelType': '1-1',\n 'refuelingMode': 1\n};\n\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 410,
        "y": 3500,
        "wires": [
            [
                "032934fb12b24bb2"
            ]
        ]
    },
    {
        "id": "032934fb12b24bb2",
        "type": "http request",
        "z": "67e5e39e7b6a8e54",
        "name": "post to HttpBin",
        "method": "POST",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "https://carburanti.mise.gov.it/ospzApi/search/area",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "credentials": {},
        "x": 620,
        "y": 3500,
        "wires": [
            [
                "62e926b2531c4d02"
            ]
        ]
    },
    {
        "id": "62e926b2531c4d02",
        "type": "debug",
        "z": "67e5e39e7b6a8e54",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 790,
        "y": 3500,
        "wires": []
    }
]

```

I hope somebody can help me.  
Thanks in advance.

Bye.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 April 2023 16:26 UTC](https://discourse.nodered.org/t/http-request-with-specific-request-headers-payloads/77961/2 "2023-04-26T16:26:00Z")

</div>

Your flow works for me.  
returns

```auto
{
    "success": true,
    "center": {
        "lat": 42.06220282165148,
        "lng": 12.610557592213357
    },
    "results": [
        {
            "id": 52326,
            "name": "A.P. FUEL MONTEROTONDO",
            "fuels": [
                {
                    "id": 52057739,
                    "price": 2.015,
                    "name": "Benzina",
                    "fuelId": 1,
                    "isSelf": false
                },
                {
                    "id": 52057738,
                    "price": 1.895,
                    "name": "Benzina",
                    "fuelId": 1,
                    "isSelf": true
                },
                {
                    "id": 52057737,
                    "price": 1.865,
                    "name": "Gasolio",
                    "fuelId": 2,
                    "isSelf": false
                },
                {
                    "id": 52057736,
                    "price": 1.745,
                    "name": "Gasolio",
                    "fuelId": 2,
                    "isSelf": true
                }
            ],
            "location": {
                "lat": 42.04967116667672,
                "lng": 12.612383841139243
            },
            "insertDate": "2023-04-26T10:18:39+02:00",
            "address": "VIA DELLE FORNACI KM. 4+150 SNC 00015 - MONTEROTONDO RM",
            "brand": "PompeBianche"
        },
        {
            "id": 51457,
            "name": "IP",
            "fuels": [
                {
                    "id": 52051391,
                    "price": 1.889,
                    "name": "Benzina",
                    "fuelId": 1,
                    "isSelf": false
                },
                {
                    "id": 52051390,
                    "price": 1.889,
                    "name": "Benzina",
                    "fuelId": 1,
                    "isSelf": true
                },
                {
                    "id": 52051393,
                    "price": 1.739,
                    "name": "Gasolio",
                    "fuelId": 2,
                    "isSelf": false
                },
                {
                    "id": 52051392,
                    "price": 1.739,
                    "name": "Gasolio",
                    "fuelId": 2,
                    "isSelf": true
                },
                {
                    "id": 52051389,
                    "price": 0.769,
                    "name": "GPL",
                    "fuelId": 4,
                    "isSelf": false
                }
            ],
            "location": {
                "lat": 42.054144386972524,
                "lng": 12.634397429824284
            },
            "insertDate": "2023-04-24T08:28:13+02:00",
            "address": "VIA SANDRO PERTINI 20 00015 - MONTEROTONDO RM",
            "brand": "Api-Ip"
        },
        {
            "id": 11823,
            "name": "MONTEROTONDO-VIA LEONARDO DA VINCI 25",
            "fuels": [
                {
                    "id": 52034918,
                    "price": 1.889,
                    "name": "Benzina",
                    "fuelId": 1,
                    "isSelf": true
                },
                {
                    "id": 52034919,
                    "price": 1.749,
                    "name": "Gasolio",
                    "fuelId": 2,
                    "isSelf": true
                },
                {
                    "id": 52034920,
                    "price": 2.049,
                    "name": "Hi-Q Diesel",
                    "fuelId": 6,
                    "isSelf": true
                },
                {
                    "id": 52034921,
                    "price": 2.189,
                    "name": "HiQ Perform+",
                    "fuelId": 28,
                    "isSelf": true
                }
            ],
            "location": {
                "lat": 42.07473447662624,
                "lng": 12.596212245368974
            },
            "insertDate": "2023-04-24T00:34:14+02:00",
            "address": "VIA LEONARDO DA VINCI 25 00015 - MONTEROTONDO RM",
            "brand": "Q8"
        },
        {
            "id": 35156,
            "name": "AREA COFFEE",
            "fuels": [
                {
                    "id": 52129778,
                    "price": 2.079,
                    "name": "Benzina",
                    "fuelId": 1,
                    "isSelf": false
                },
                {
                    "id": 52129777,
                    "price": 1.879,
                    "name": "Benzina",
                    "fuelId": 1,
                    "isSelf": true
                },
                {
                    "id": 52129780,
                    "price": 1.939,
                    "name": "Gasolio",
                    "fuelId": 2,
                    "isSelf": false
                },
                {
                    "id": 52129779,
                    "price": 1.739,
                    "name": "Gasolio",
                    "fuelId": 2,
                    "isSelf": true
                },
                {
                    "id": 52129781,
                    "price": 0.769,
                    "name": "GPL",
                    "fuelId": 4,
                    "isSelf": false
                },
                {
                    "id": 52129782,
                    "price": 2.289,
                    "name": "Hi-Q Diesel",
                    "fuelId": 6,
                    "isSelf": false
                }
            ],
            "location": {
                "lat": 42.06386561323193,
                "lng": 12.629591524600983
            },
            "insertDate": "2023-04-26T09:54:46+02:00",
            "address": "VIA EINAUDI KM 2,400 00015 - MONTEROTONDO RM",
            "brand": "Q8"
        },
        {
            "id": 12917,
            "name": "TREVISAN ROBERTO",
            "fuels": [
                {
                    "id": 52073023,
                    "price": 2.149,
                    "name": "Benzina",
                    "fuelId": 1,
                    "isSelf": false
                },
                {
                    "id": 52073022,
                    "price": 1.849,
                    "name": "Benzina",
                    "fuelId": 1,
                    "isSelf": true
                },
                {
                    "id": 52073021,
                    "price": 1.994,
                    "name": "Gasolio",
                    "fuelId": 2,
                    "isSelf": false
                },
                {
                    "id": 52073020,
                    "price": 1.694,
                    "name": "Gasolio",
                    "fuelId": 2,
                    "isSelf": true
                }
            ],
            "location": {
                "lat": 42.06312744588049,
                "lng": 12.590307891368866
            },
            "insertDate": "2023-04-24T15:40:03+02:00",
            "address": "VIA SALARIA KM. 23+330 00015 - MONTEROTONDO RM",
            "brand": "Api-Ip"
        },
        {
            "id": 6657,
            "name": "MONTEROTONDO VIA FILIPPO TURATI 101",
            "fuels": [
                {
                    "id": 52034876,
                    "price": 1.849,
                    "name": "Benzina",
                    "fuelId": 1,
                    "isSelf": true
                },
                {
                    "id": 52034877,
                    "price": 1.699,
                    "name": "Gasolio",
                    "fuelId": 2,
                    "isSelf": true
                }
            ],
            "location": {
                "lat": 42.06103257306434,
                "lng": 12.599813640117645
            },
            "insertDate": "2023-04-24T00:34:12+02:00",
            "address": "VIA FILIPPO TURATI 101 00016 - MONTEROTONDO RM",
            "brand": "Q8"
        },
        {
            "id": 22874,
            "name": "eni monterotondo",
            "fuels": [
                {
                    "id": 52005501,
                    "price": 2.064,
                    "name": "Benzina",
                    "fuelId": 1,
                    "isSelf": false
                },
                {
                    "id": 52005500,
                    "price": 1.844,
                    "name": "Benzina",
                    "fuelId": 1,
                    "isSelf": true
                },
                {
                    "id": 52005503,
                    "price": 1.924,
                    "name": "Gasolio",
                    "fuelId": 2,
                    "isSelf": false
                },
                {
                    "id": 52005502,
                    "price": 1.704,
                    "name": "Gasolio",
                    "fuelId": 2,
                    "isSelf": true
                },
                {
                    "id": 52005505,
                    "price": 2.024,
                    "name": "Blue Diesel",
                    "fuelId": 20,
                    "isSelf": false
                },
                {
                    "id": 52005504,
                    "price": 1.804,
                    "name": "Blue Diesel",
                    "fuelId": 20,
                    "isSelf": true
                }
            ],
            "location": {
                "lat": 42.06099852084146,
                "lng": 12.586717754602432
            },
            "insertDate": "2023-04-22T13:53:01+02:00",
            "address": "VIA SALARIA KM. 22,950 SNC 00015 - MONTEROTONDO RM",
            "brand": "AgipEni"
        }
    ]
}

```

Maybe something specific to your setup is the issue, describe your setup.

Do you get any errors returned?

---

<div class="post-metadata">

**Author:** ![EL\_tech](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@EL\_tech](https://discourse.nodered.org/u/EL_tech)\
**Post date:** [26 April 2023 18:43 UTC](https://discourse.nodered.org/t/http-request-with-specific-request-headers-payloads/77961/3 "2023-04-26T18:43:00Z")

</div>

Hello @E1cid,  
thank you a lot for your helpfulness and your quickly answer.  
I have no idea how long I've been trying around my code. I am all the more pleased that the code works. But why I get a request error every time I still have to look. I suspect it is due to my unstable WLAN connection ...:-/

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 May 2023 18:43 UTC](https://discourse.nodered.org/t/http-request-with-specific-request-headers-payloads/77961/4 "2023-05-10T18:43:57Z")

</div>

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