HTTP Request Error: ERROR: str.replace is not a function

I’m following the Spotify Client Credentials Auth Guide and keep getting this error.

ERROR: str.replace is not a function

TypeError: str.replace is not a function
    at Querystring.rfc3986 (C:\Users\malga\AppData\Roaming\npm\node_modules\n8n\node_modules\request\lib\querystring.js:43:14)
    at Request.json (C:\Users\malga\AppData\Roaming\npm\node_modules\n8n\node_modules\request\request.js:1287:30)
    at Request.init (C:\Users\malga\AppData\Roaming\npm\node_modules\n8n\node_modules\request\request.js:406:10)
    at Request.RP$initInterceptor [as init] (C:\Users\malga\AppData\Roaming\npm\node_modules\n8n\node_modules\request-promise-core\configure\request2.js:45:29)
    at new Request (C:\Users\malga\AppData\Roaming\npm\node_modules\n8n\node_modules\request\request.js:127:8)
    at Object.request (C:\Users\malga\AppData\Roaming\npm\node_modules\n8n\node_modules\request\index.js:53:10)
    at Object.execute (C:\Users\malga\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-nodes-base\nodes\HttpRequest.node.ts:747:35)
    at Workflow.runNode (C:\Users\malga\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-workflow\src\Workflow.ts:1127:28)
    at C:\Users\malga\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-core\src\WorkflowExecute.ts:597:41
    at C:\Users\malga\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-core\src\WorkflowExecute.ts:692:6

This is my HTTP Request Node json

{
      "parameters": {
        "requestMethod": "POST",
        "url": "https://accounts.spotify.com/api/token",
        "options": {},
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "grant_type",
              "value": "client_credentials"
            }
          ]
        },
        "headerParametersUi": {
          "parameter": [
            {
              "name": "Authorization",
              "value": "Basic 08505f64474e4de0a0e57c2e1bfe1517:0b178174dc9e40eaa146093c03bb18d1"
            },
            {
              "name": "Content-Type",
              "value": "application/x-www-form-urlencoded"
            }
          ]
        }
      },
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        850,
        290
      ]
    }

Any idea what might be wrong?

Welcome to the community @malgamves!

To send the data properly you should set “urlencode” properly on the Node instead of setting just the header manually. Else the data will still be sent wrong and apparently, also other things go wrong.

So something like this should work:

{
  "nodes": [
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://accounts.spotify.com/api/token",
        "options": {
          "bodyContentType": "form-urlencoded"
        },
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "grant_type",
              "value": "client_credentials"
            }
          ]
        },
        "headerParametersUi": {
          "parameter": [
            {
              "name": "Authorization",
              "value": "Basic 08505f64474e4de0a0e57c2e1bfe1517:0b178174dc9e40eaa146093c03bb18d1"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        620,
        411
      ]
    }
  ],
  "connections": {}
}

I get nevertheless still an error message ERROR: 400 - {"error":"invalid_client"} which can have to do with the Authorization header:

So you should maybe check that again. If not I sadly do not know, but n8n should at least not be the problem.

Btw. please make sure to always paste the whole node-json and not just parts of it. If that does not get done, it can not simply be pasted again in n8n and all the node data has to be typed in manually instead which causes unnecessary additional work. Thanks!

1 Like

Thanks for the warm welcome! I tried encoding the credentials but nothing helped :confused: hopefully Spotify gets back to me soon. Would be a nice workflow to have. Also next time I’ll paste the whole file thanks.

If they did and you got some additional information on the issue simply get back to us. Maybe we are then able to help some more.