# 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:** 14
**Page:** 2

<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:40 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/21 "2022-10-04T14:40:22Z")

</div>

OK they are quick to respond:  
"You need to use your API key as Username and x as password under basic authentication."  
I used this and still got the error that only one auth mechanism allowed..  
They responded:  
"We are not sure if NodeRED supports the end point URL provided by us."  
Of which I asked for a Curl example.

---

<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:45 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/22 "2022-10-04T14:45:17Z")

</div>

Postman works without an issue.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/5/d5ef9472fef96bea7361b7562765209c362e4fe2.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:48 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/23 "2022-10-04T14:48:19Z")

</div>

so copy the working request as a cURL from postman: [php - Converting a Postman request to curl - Stack Overflow](https://stackoverflow.com/questions/49432735/converting-a-postman-request-to-curl)

Be sure to sanitise it before posting

Also, use the forum `</>` code button before sending.

EDIT...

But first, try adding those headers to node-red HTTP-Request.

> [@sourceminer](#):
>
> "We are not sure if NodeRED supports the end point URL provided by us."

If their server is standards compliant, I can pretty much guarantee node-red can do this.

---

<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:49 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/24 "2022-10-04T14:49:52Z")

</div>

```auto
curl --location --request GET 'https://company.freshservice.com/api/v2/analytics/export?id=xxx-3344xxxkkk' \
--header 'Authorization: Basic XX=='

```

---

<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:51 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/25 "2022-10-04T14:51:24Z")

</div>

did you delete the password? `Basic XX==` looks like you did.

Would be better to take the working postman, change the password to something like `bad_pass` then export it.

---

<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:53 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/26 "2022-10-04T14:53:16Z")

</div>

```auto
curl --location --request GET 'https://company.freshservice.com/api/v2/analytics/export?id=Long-ID-KEY-With-88882222-Numbers' \
--header 'Authorization: Basic YmFkX3Bhc3M6c2VudA=='

```

---

<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 15:01 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/27 "2022-10-04T15:01:18Z")

</div>

Before I translate this, I forgot to ask, have you tried the cURL command in a terminal window (not powershell) Ideally from a linux box/PI/wsl instance

---

<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 15:05 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/28 "2022-10-04T15:05:22Z")

</div>

Yes using the exact command from postman I was able to collect data in the terminal of the nodered system

---

<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 15:15 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/29 "2022-10-04T15:15:00Z")

</div>

Can you try this...

```auto
[{"id":"145be34f3883da89","type":"inject","z":"ccdc4f1f78201a08","name":"Click me","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":360,"y":640,"wires":[["bbcb4f6127d457d8"]]},{"id":"bbcb4f6127d457d8","type":"function","z":"ccdc4f1f78201a08","name":"","func":"//original curl: \n//\n//curl --location --request GET 'https://company.freshservice.com/api/v2/analytics/export?id=xxx-3344xxxkkk' \\\n//--header 'Authorization: Basic XX=='\n\nmsg.method = \"get\";\nmsg.url = \"https://company.freshservice.com/api/v2/analytics/export?id=xxx-3344xxxkkk\";\nmsg.payload = ``;\nmsg.headers = {\n \"Authorization\": \"Basic XX==\" //CHANGE XX== TO WHAT POSTMAN SENDS\n //Add other headers postman sends if necessary\n};\nmsg.cookies = null;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":640,"wires":[["c423adfebdc95cdd"]]},{"id":"c423adfebdc95cdd","type":"http request","z":"ccdc4f1f78201a08","name":"","method":"use","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":720,"y":640,"wires":[["144e9139f50e8e6d"]]},{"id":"144e9139f50e8e6d","type":"debug","z":"ccdc4f1f78201a08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":900,"y":640,"wires":[]}]

```

Be sure to update the function node as per the comments inside

---

<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 15:34 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/30 "2022-10-04T15:34:27Z")

</div>

Didnt work.  
Same error message

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

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [4 October 2022 16:54 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/31 "2022-10-04T16:54:11Z")

</div>

Did you "unset" the auth in the http-request node ?

---

<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 17:05 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/32 "2022-10-04T17:05:22Z")

</div>

Yes there is no auth in the HTTP request mode.

---

<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: [5 October 2022 07:46 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/33 "2022-10-05T07:46:47Z")

</div>

For anyone following along: I have been looking at this with @sourceminer privately and it seems the issue is related to the HTTP-Request node failing to follow redirects!

This works if you operate the "Manually follow redirects" inject...

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

Demo flow (URL and Auth will need to be set in the `Set URL` function)...

```auto
[{"id":"145be34f3883da89","type":"inject","z":"ccdc4f1f78201a08","name":"Follow Redirects (default)","props":[{"p":"followRedirects","v":"true","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":570,"y":580,"wires":[["bbcb4f6127d457d8"]]},{"id":"c423adfebdc95cdd","type":"http request","z":"ccdc4f1f78201a08","name":"","method":"use","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"Accept","keyValue":"","valueType":"application/json","valueValue":""},{"keyType":"Content-Type","keyValue":"","valueType":"application/json","valueValue":""}],"x":800,"y":640,"wires":[["e61cbdf8ca902fad"]]},{"id":"144e9139f50e8e6d","type":"debug","z":"ccdc4f1f78201a08","name":"redirected response","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1500,"y":640,"wires":[]},{"id":"bbcb4f6127d457d8","type":"function","z":"ccdc4f1f78201a08","name":"Set URL","func":"\nmsg.method = \"get\";\nmsg.url = \"https://test_my_api.com/api/v1/info\";\nmsg.payload = ``;\nmsg.headers = {\n \"Authorization\": \"Basic XXX\" //Set XXX Accordingly\n //Add other headers if necessary\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":640,"wires":[["c423adfebdc95cdd"]]},{"id":"e61cbdf8ca902fad","type":"switch","z":"ccdc4f1f78201a08","name":"200? \\n 302 \\n otherwise","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"str"},{"t":"eq","v":"302","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":960,"y":640,"wires":[["63c8b43605bbc35e"],["16ababd4a0963ee7"],["14e464e951c2313e"]]},{"id":"63c8b43605bbc35e","type":"debug","z":"ccdc4f1f78201a08","name":"direct response","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1480,"y":580,"wires":[]},{"id":"14e464e951c2313e","type":"debug","z":"ccdc4f1f78201a08","name":"fail!","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1450,"y":700,"wires":[]},{"id":"867f4d6102286c40","type":"http request","z":"ccdc4f1f78201a08","name":"","method":"use","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"Accept","keyValue":"","valueType":"application/json","valueValue":""},{"keyType":"Content-Type","keyValue":"","valueType":"application/json","valueValue":""},{"keyType":"Location","keyValue":"","valueType":"msg","valueValue":"headers.location"}],"x":1310,"y":640,"wires":[["144e9139f50e8e6d"]]},{"id":"16ababd4a0963ee7","type":"function","z":"ccdc4f1f78201a08","name":"follow redirect","func":"msg.url = msg.headers.location\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1140,"y":640,"wires":[["867f4d6102286c40"]]},{"id":"9ee8a6ecac185a61","type":"inject","z":"ccdc4f1f78201a08","name":"Manually Follow Redirects","props":[{"p":"followRedirects","v":"false","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":570,"y":700,"wires":[["bbcb4f6127d457d8"]]}]

```

---

<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: [4 December 2022 07:47 UTC](https://discourse.nodered.org/t/cannot-collect-data-in-nodered-json-parse-error-works-in-powershell/68552/34 "2022-12-04T07:47:46Z")

</div>

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

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