# Cannot Collect Data in NodeRed Json parse error works in powershell

**URL:** <https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552>\
**Category:** General\
**Created:** [4 October 2022 13:22 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552 "2022-10-04T13:22:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sourceminer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sourceminer/32/68604_2.png) [@sourceminer](https://discourse.nodered.org/u/sourceminer)\
**Post date:** [4 October 2022 13:22 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/1 "2022-10-04T13:22:47Z")

</div>

Hello I am hoping that someone here can help me. Not sure why Node-Red is seeming to have such a hard time with such a simple process. Clearly has to be something I am over-looking.

Im pulling data from our ticketing system and from powershell it works without an issue:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/c/4c0c4fde33a1b8a37807ab41582554382ce9c887.jpeg)

However in NodeRed

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/4/84d0cce584af09387bb92412cdcfbd072ddeef87.png)

```auto
[
    {
        "id": "92d4157e9a6f0336",
        "type": "debug",
        "z": "a4ae3de1a01e4463",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 940,
        "y": 240,
        "wires": []
    },
    {
        "id": "5cc51b6ece33e3e1",
        "type": "function",
        "z": "a4ae3de1a01e4463",
        "name": "function 1",
        "func": "msg.headers = {\n 'Authorization': \"Basic XXXXXXX\"\n ,'Content-Type': 'application/json'\n}\nmsg.url = 'https://company.freshservice.com/api/v2/analytics/export?id=XXXXXX'\nmsg.method = 'GET'\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 560,
        "y": 300,
        "wires": [
            [
                "ec0d027d462ed1cf",
                "92d4157e9a6f0336"
            ]
        ]
    },
    {
        "id": "ec0d027d462ed1cf",
        "type": "http request",
        "z": "a4ae3de1a01e4463",
        "name": "",
        "method": "use",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": true,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 750,
        "y": 300,
        "wires": [
            [
                "92d4157e9a6f0336"
            ]
        ]
    },
    {
        "id": "a154d98fb671c800",
        "type": "inject",
        "z": "a4ae3de1a01e4463",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "str",
        "x": 390,
        "y": 300,
        "wires": [
            [
                "5cc51b6ece33e3e1"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [4 October 2022 13:36 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/2 "2022-10-04T13:36:07Z")

</div>

Please paste code inside a pre-formatted text block for readability `</>`.

~~Try setting the request to just return text. If it is \<1k, you may be able to output it to the debug sidebar, otherwise set the debug node to output to the node-red log and copy the XML string into a decent editor such as VScode and get it to parse the content to see what, if anything might be wrong.~~

No, forget that, I read the error now.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 October 2022 13:37 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/3 "2022-10-04T13:37:06Z")

</div>

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![sourceminer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sourceminer/32/68604_2.png) [@sourceminer](https://discourse.nodered.org/u/sourceminer)\
**Post date:** [4 October 2022 13:39 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/4 "2022-10-04T13:39:14Z")

</div>

Sorry about that.. its fixed.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 October 2022 13:39 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/5 "2022-10-04T13:39:14Z")

</div>

At a guess (hard to tell because your debug nodes are both named "debug 2") it looks like you recieve XML

I suspect the right solution is to set a header in the request so that you ask for JSON.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/8/48302590475d5492c6b21c162001fc85ee17cda0.png)

Alternatively, change the HTTP Req node to return a string and use an XML node to convert to JSON.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/3/632b3695834c3ee19631458513991293e4acb898.png)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [4 October 2022 13:41 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/6 "2022-10-04T13:41:38Z")

</div>

That's what I saw. But in fact, the reason XML is returned is because that is an error message.

According to the API spec, BASIC auth is not an option. You should be using a personal API key.

[Service Desk API for Developers | Freshservice](https://api.freshservice.com/#authentication)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 October 2022 13:43 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/7 "2022-10-04T13:43:27Z")

</div>

Also, I note that your PowerShell request has a "Content-Type" header. Try adding that to your request as well as the "Accept" header

---

<div class="post-metadata">

**Author:** ![sourceminer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sourceminer/32/68604_2.png) [@sourceminer](https://discourse.nodered.org/u/sourceminer)\
**Post date:** [4 October 2022 13:49 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/8 "2022-10-04T13:49:50Z")

</div>

Trying options stand by

---

<div class="post-metadata">

**Author:** ![sourceminer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sourceminer/32/68604_2.png) [@sourceminer](https://discourse.nodered.org/u/sourceminer)\
**Post date:** [4 October 2022 13:50 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/9 "2022-10-04T13:50:51Z")

</div>

Yes the basic auth is the api key

> **[Exporting Data from Analytics to Power BI](https://support.freshservice.com/en/support/solutions/articles/50000001123-exporting-data-from-analytics-to-power-bi)**
>
> Analytics module in Freshservice allows you to generate intuitive reports for your service desk. Integrating Power BI with Freshservice enables you to scale up your analytics with extensive dashboards and reports to drive business results using a...

---

<div class="post-metadata">

**Author:** ![sourceminer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sourceminer/32/68604_2.png) [@sourceminer](https://discourse.nodered.org/u/sourceminer)\
**Post date:** [4 October 2022 14:03 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/10 "2022-10-04T14:03:48Z")

</div>

Do I need to have a function here or is that redundant to the gather data headers?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/1/e1ca53fa44aa4ce26a953dc187573bee4abd0085.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 October 2022 14:06 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/11 "2022-10-04T14:06:17Z")

</div>

> [@sourceminer](#):
>
> Do I need to have a function here?

If you are using node-red v3+ then you do not need to set headers in a function. As you can see by my screenshot, it is now possible to set headers in the request node.

> [@Steve-Mcl](#):
>
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/8/48302590475d5492c6b21c162001fc85ee17cda0.png)

---

<div class="post-metadata">

**Author:** ![sourceminer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sourceminer/32/68604_2.png) [@sourceminer](https://discourse.nodered.org/u/sourceminer)\
**Post date:** [4 October 2022 14:13 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/12 "2022-10-04T14:13:32Z")

</div>

Yes thanks for the clarification, this is why I was asking... Seemed redundant.  
OK so I have updated to the following and still getting the error.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fc4342ded783cd12ae0e108c279dd8a8b104cf87.png)

---

<div class="post-metadata">

**Author:** ![sourceminer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sourceminer/32/68604_2.png) [@sourceminer](https://discourse.nodered.org/u/sourceminer)\
**Post date:** [4 October 2022 14:14 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/13 "2022-10-04T14:14:43Z")

</div>

I should mention that I took my API key in Powershell and converted it to base64.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 October 2022 14:15 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/14 "2022-10-04T14:15:44Z")

</div>

You probably need to set the API key in a specific header (not the username or password field as these will get base64 encoded). Can you find an example CURL or specific docs around providing the API key to a HTTP request?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 October 2022 14:16 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/15 "2022-10-04T14:16:45Z")

</div>

> [@sourceminer](#):
>
> should mention that I took my API key in Powershell and converted it to base64

there should be no need in the username/password fields (since it will do that under the hood) - you will only need to encode the key if you are providing it directly in a header and only if the API docs state it must be base64 encoded

Try putting the raw API key in the password field. Dont worry, it gets encrypted on your file system and cannot be retrieved or exported from the flow.

---

<div class="post-metadata">

**Author:** ![sourceminer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sourceminer/32/68604_2.png) [@sourceminer](https://discourse.nodered.org/u/sourceminer)\
**Post date:** [4 October 2022 14:18 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/16 "2022-10-04T14:18:16Z")

</div>

This is from the Link above where it specifically states to use the Basic Auth and use your username and password. OR "You can also use your FS User’s API key in the User name field (leave the password empty) and click on Connect."

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/e/cef95547d73c890b495c93af1fe74fc928fefd1c.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 October 2022 14:19 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/17 "2022-10-04T14:19:21Z")

</div>

try putting email in username & API key (non encoded) in the password field. The HTTP request node will correctly set the auth header with a base64 encoded value

---

<div class="post-metadata">

**Author:** ![sourceminer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sourceminer/32/68604_2.png) [@sourceminer](https://discourse.nodered.org/u/sourceminer)\
**Post date:** [4 October 2022 14:24 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/18 "2022-10-04T14:24:05Z")

</div>

I tried that but still doesnt like it.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/4/54fd9ca42fdcd24a93764c122f73ce303a7330f8.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 October 2022 14:28 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/19 "2022-10-04T14:28:11Z")

</div>

then all I can suggest is you try with cURL and/or postman and when you get it working, inspect all the headers & replicate those in node-red.

Alternatively, use wireshark (or similar) to capture a "good" transmission & inspect the headers sent in a good request.

> [@Steve-Mcl](#):
>
> Can you find an example CURL or specific docs around providing the API key to a HTTP request?

---

<div class="post-metadata">

**Author:** ![sourceminer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sourceminer/32/68604_2.png) [@sourceminer](https://discourse.nodered.org/u/sourceminer)\
**Post date:** [4 October 2022 14:30 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/20 "2022-10-04T14:30:46Z")

</div>

Thanks Steve, I will ask FreshService if they have a Curl Example.

[Next page](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552.md?page=2)
