Include $json variable in Body String for HTTP node

Describe the problem/error/question

I want to make the following code dynamic:
FROM:

{
    "filters": [
        {
            "propertyName": "hubspot_owner_id",
            "operator": "EQ",
            "value": "49383796"
        }
    ]
}

TO:

{
    "filters": [
        {
            "propertyName": "hubspot_owner_id",
            "operator": "EQ",
            "value": "{{ $json["results"]["id"] }}"
        }
    ]
}

I tried both double quotes and single quotes. ie: {{ $json[‘results’][‘id’] }}
I need this because I have other Body Parameters to populate like “after” and “limit”.

What is the error message (if any)?

Please share your workflow

Needs authentication to work so I can’t share.

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.34.0
  • Database (default: SQLite): Postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • Operating system: Ubuntu Linux 22.04?

@tim.berneman , so, what is the problem? Single quotes or {{ $json.results.id }} should be just fine.

Needs authentication to work so I can’t share.

Of cause you can share and you should. We do not need to connect but we need to see your configuration.

Yet, again, you haven’t explain what problem you have encountered. Any error message?

The problem is it doesn’t do the substitution
of {{ $json[“results”][“id”] }}
to 12345678

The Error is “[invalid syntax]”

Thanks for you prompt and courteous reply.

The dropdown option “Using Fields Below” means you should enter a string there.
You can force it to use a JSON by placing all the content inside the double brackets {{ <your_json> }} or you should use the JSON Body type and specify the whole JSON there

That is why we need to see your workflow configuration. For example, here’s no syntax error.

Having said that, I believe you have chosen not the right body structure. According to HubSpot Tasks API, the body structure would be something like this

// Example request body
{
  "properties": {
     "hs_timestamp": "2019-10-30T03:30:17.883Z",
     "hs_task_body": "Send Proposal",
     "hubspot_owner_id": "64492917",
     "hs_task_subject": "Follow-up for Brian Buyer",
     "hs_task_status": "WAITING",
     "hs_task_priority": "HIGH",
     "hs_task_type":"CALL"
},
"associations": [
    {
     "to": {
        "id": 101
      },
      "types": [
        {
          "associationCategory": "HUBSPOT_DEFINED",
          "associationTypeId": 204
        } ]
    }, 
    {
     "to": {
        "id": 102
      },
      "types": [
        {
          "associationCategory": "HUBSPOT_DEFINED",
          "associationTypeId": 204
        } ]
}]
}

It’s has nested JSON structure. Therefore, I would suggest engaging “Using JSON” option (instead of “Using Fields Below”) as the body of the request. For example,

Ya, that’s what I ended up doing. I switched to “Using JSON” and did it as a whole block.

Thanks for your help!

1 Like

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