JSON/RAW parameters not working as expected

Hi! I’m trying to do a POST request as shared below.

n8n doesn’t like the “” and suggests to Set Body Content Type to “RAW/Custom” for XML or other types of payloads. Once I do this, I get the following error: ERROR: Cannot create property ‘accept’ on string ‘{ “Api-Key”: “123”, “Content-Type”: “application/json” }’

Not sure what I’m doing wrong as I have very low coding skills.

Hi @Artego, I am so sorry to hear you are having trouble. Is there a chance you are using either an older version of n8n or an older workflow here?

I am asking because your example uses version 2 of the n8n HTTP Request node, whereas the current version of the node would be 4.1.

So perhaps you want to upgrade your n8n version, then add a new HTTP Request node from scratch? The new node comes with a bunch of useful features, such as a curl import function which would allow you to simply import your working requests from other tools (like curl, Postman, or Insomnia).

It would also run your example request without complaining (well, I am still getting an error, but that’s because I don’t have a valid API key, not because of the format) like so:

1 Like

I am running an older version of n8n. We are in the process of updating, but it might take some time.

Is there a way to fix the workflow without an update?

Can you share the exact version of n8n you’re currently using?

Sure. It’s 0.187.2

Thanks @Artego! Can you give this updated version of your workflow a go?

I couldn’t test this first-hand due to the missing API key, but iirc earlier version of n8n were a bit picky when it came to using either a JSON-like string or an actual JSON object in the expression. This approach uses the latter, so n8n won’t complain about the invalid JSON.

Sorry, I don’t see any settings. Am I doing something wrong?

Looks like the forum stripped these, I am so sorry. I guess it too struggles with the old node version :see_no_evil:

Can you try manually using an expression for the body like this (no linebreaks, everything wrapped in double curly braces):

{{ { "query":{ "domain":["B2C2.com"] }, "order_by": "relevance" } }}

And for the header:

{{ { "Api-Key": "123", "Content-Type": "application/json" } }}

This one works, however I need to place B2C2.com double quotation marks and this breaks everything :smiling_face_with_tear:

Are you 100% sure you need double quotation marks? RocketReach API - Built for developers, our APIs are simple, yet powerful. suggests you only have to send an array of strings, which is what the example expression I have provided returns.

If you still want to include double double quotes as part of your string you could use single quotes and then wrap as many double quotes as you want with them. For example:

{{ { "query":{ "domain":['""B2C2.com""'] }, "order_by": "relevance" } }}

Also, always make sure to use an expression field rather than a plain text field, otherwise the part between {{ and }} will not be evaluated as JavaScript.

2 Likes

Yes, here is a screenshot from the RocketReach API documentation

I’ll give it a try. Thanks a lot

1 Like

This worked great. Thank you so much
However, another thing is not working for me :smiling_face_with_tear:

I’m trying to place an array from the output of the last node instead of [‘““B2C2.com””’] and it doesn’t seem to pull the data. The field just goes blank

Here is the output of the Function node:
[
{
“websites”: [
“""Bitflyer.com""”,
“""Coinpass.com""”,
“""https://www.circle.com/\“\””,
“""B2C2.com""”,
“""Coincheck.com""”,
“""Kraken.com""”,
“""Bitcoin.DMM.com""”,
“""KuCoin.com""”,
“""https://www.gc.exchange/\“\””,
“""https://www.lmaxdigital.com/\“\””,
“""bitbank.cc""”,
“""https://global.rakuten.com/\“\””,
“""BITPoint.co.jp""”,
“""BITMAX.me""”,
“""FreeBitco.in""”,
“""404|SBI VCトレード|暗号資産(仮想通貨)・口座開設”,
“""BitoEX.com""”,
“""MEXC.com""”,
“""Zaif.jp""”,
“""AlphaPo.net""”,
“""Bitget.com""”,
“""Bitpanda.com""”,
“""Bitrue.com""”,
“""Bitterz.com""”,
“""IndependentReserve.com""”,
“""Krabiti.com""”,
“""Nexo.io""”,
“""Bittrex.com""”,
“""BTSE.com""”,
“""Huobi.com""”,
“""Mercuryo.io""”,
“""Whitebit.com""”,
“""1xBit.com""”,
“""AAX.com""”,
“""AEX.com""”,
“""https://www.ambergroup.io/\“\””,
“""AscendEX.com""”,
“""AuraeLifestyle.com""”,
“""B2BinPay.com""”,
“""A Leading Crypto Processing & Blockchain Enterprise Wallets”,
“""https://bc.game/\“\””,
“""BetFury.io""”,
“""Bibox.com""”,
“""https://big.one""”,
“""BiKi.com""”,
“""Binary.com""”,
“""BingX.com""”,
“""Bit2c.co.il""”,
“""Bitazza.com""”,
“""BitBuy.ca""”,
“""BitcoinWallet.com""”,
“""BitForex.com""”,
“""Bithumb.com""”,
“""Bitkub.com""”,
“""Bitmania-ex.com""”,
“""BitMart.com""”,
“""BitMEX.com""”,
“""BitoPro.com""”,
“""https://www.bittrade.co.jp""”,
“""BitZ.ai""”,
“""Bixter.org""”,
“""BKEX.com""”,
“""BrasilBitcoin.com.br""”,
“""BTCBOX.co.jp""”,
“""BTCEX.com""”,
“""BTCTurk.com""”,
“""Bustabit.com""”,
“""Cashmaal.com""”,
“""ChangeNOW.io""”,
“""Coin-Trade.cc""”,
“""Coinage.co.jp""”,
“""Coinbene.com""”,
“""CoinBox.org""”
]
}
]

@MutedJam Hi Tom, I hope your vacation was great.

Could you help here please? I’m stuck.

Hi @Artego, looks like you’re nesting double quotes here which presumably results in invalid JSON.

Perhaps you want to try an expression like {{ { "query":{ "domain":$json["websites"] }, "order_by": "relevance" } }} in your Body Parameters field instead?

1 Like

thank you so much

1 Like

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