UTF-8 to ISO-8859-1 for POST

Hi everyone,

we are using n8n to transfer shipment data form our ERP to the logistics company.
Unfortunately, special characters like ß, ü, ö and so on are not transferred to the logistics company as they need the POST request to be in ISO-8859-1.

Any idea how I could solve that?

Thanks

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Sure,
n8n version: 1.32.2
Database: unchanged, so I guess SQLite
n8n EXECUTIONS_PROCESS setting: default
Running in Docker on Synology NAS
OS: Synology

Hi @smitterer

Thanks for posting here and welcome to the community! :partying_face:

Would you care to share your workflow? Are you using the HTTP Node for the data transfer?

You can share your workflow here by pasting the JSON content (after you download the workflow from you workspace) in between two block quotes (```).

Unfortunately I can hardly share the flow as it holds some sensitive data. (not only credentials but also one specific API is not open to the public)
We use the HTTP node to get data from json in previous nodes and then post it to the API:

@ria do you maybe have an idea?
Thanks

Hi @smitterer

sorry for the late reply!

When sharing workflows the credentials are automatically excluded :wink:

I was gonna see if I could use a Code Node to do the data encoding between your previous nodes and the HTTP Node to your logistics company.

Unfortunately some of the nodes (like the http) directly hold sensitive data.

We try to use the following code to change the encoding, whichs works with then using “Convert to File” (with the correct encoding selected) and after that “Read/Write files from disk”.

function encodeToISO88591(str) {
return Buffer.from(str, ‘utf8’).toString(‘binary’);
}

function encodeObject(obj) {
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
if (typeof obj[key] === ‘string’) {
obj[key] = encodeToISO88591(obj[key]);
} else if (typeof obj[key] === ‘object’ && obj[key] !== null) {
obj[key] = encodeObject(obj[key]);
}
}
}
return obj;
}

// Get the input data
const inputData = items.map(item => item.json);

// Encode all values in the input data
const encodedData = inputData.map(data => encodeObject(data));

// Return the encoded data
return encodedData.map(data => ({ json: data }));

Using the following headers in the http node does not work unfortunately:

@ria do you maybe have any idea?

Thanks!

@ria I’d really appreciate if you had an idea.
Thanks

@ria any idea?

Thank you

Set the http request node to save file. (Response / Response Format = file / Put Output in Field = data.

Add a “code” node

const iconv = require(‘iconv-lite’);
const fileData = items[0].binary.data;
const binaryData = Buffer.from(fileData.data, ‘base64’);
const decodedContent = iconv.decode(binaryData, ‘iso-8859-1’);
return [
{
json: {
data: decodedContent
}
}
];

We improved our handling of ISO-8859-1 responses 4 days ago. Once this fix is out on Wednesday, can you please try to upgrade, and also set the Content-Type to include charset=latin1 on your requests we well?

We might still need to update a few other nodes to make them all respect the response encoding. So if this is about a specific node, please let us know, and we’ll try to prioritize updating that node’s response handling.

1 Like

Thanks a lot for your reply and the commit.

How do I see in which release this is included? I don’t see it in 1.50.1
Is there a 1.50.2 planned for today?

Thanks

This hasn’t gone out yet. It’s included in 1.51.0, that’s building right now.

Once the PR is released, there will be a comment from Jan on the PR mentioning the release that particular PR went out in.

Hi @smitterer

Just got released with [email protected]