Code step not working

I’m trying to run a code step to retrieve the prefix of a URL.

I’m getting this error: Screenshot by Lightshot . To clarify, I’m looking to retrieve the ‘htzone’ part.

Here’s my code:const url = {{$json.body.zendeskURL}};const urlObject = new URL(url);const p -

Here’s the relevant part of the workflow: Screenshot by Lightshot

Information on your n8n setup

  • **n8n version: 0.228.2
  • Running on the cloud.

Hi @Tamir_Bashkin, welcome to the community. Your code has a few problems:

  1. While you need to add {{}} in other nodes to reference data, you don’t need to do this in the code node.
  2. When using the mode Run Once for Each Item the node expects you to return one JSON object only and not an error.
  3. Our code node unfortunately can’t use the URL object.

The following should work (you might wanna check if the string is a valid URL before though):

1 Like

That works perfectly, thanks! :slight_smile:
Can you also help me understand how I remove special characters and apply a regex at the same step?

I’d like to apply this regex: ([^0-9a-zA-Zא-תА-яЁё]+) to the latestComment property, and replace everything with a space character. Then return the updated string.

Thanks! :slight_smile:

@Tamir_Bashkin not sure if I understood you correctly, but this should do it if I did

1 Like

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