Cannot Collect Data in NodeRed Json parse error works in powershell

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:

However in NodeRed

[
    {
        "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"
            ]
        ]
    }
]

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.

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 ```)

``` 
   code goes here 
```

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

See this post for more details - How to share code or flow json

Sorry about that.. its fixed.

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

Alternatively, change the HTTP Req node to return a string and use an XML node to convert to JSON.
image

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

1 Like

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

Trying options stand by

Yes the basic auth is the api key

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

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.

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.

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

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?

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.

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."

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

I tried that but still doesnt like it.
image

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.

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