Million Dollar YearGet the free app

How to build AI lead scoring with n8n and GoHighLevel

By Max Warnault · 22 April 2025 · 9 min read

In short

An AI setter in n8n asks a lead a set of qualification questions. Once it has asked them all, it returns a lead score, the reasoning behind it and a next step. An If node decides whether to send the next question or score the lead. HTTP requests to the GoHighLevel API then save the score and reasoning to custom fields. Leads scoring above five get tagged for an AI scheduler. Everyone else gets tagged for an AI seller.

In my earlier video, I built an AI agent that qualifies leads by asking them a series of questions. That covers half the job. The answers have to turn into a score, and the score has to land in your CRM so you can do something with it.

This article covers the second half. I connect n8n to the GoHighLevel API, save the lead score and the reasoning behind it on the contact, and tag the lead. Qualified leads go to an AI scheduler that gets them on a call. Everyone else goes to an AI seller that sells them a product.

How the AI lead scoring workflow works

In this build, the AI agent is called the AI setter. During qualification it asks one question at a time: the lead's first name, whether they want to scale their agency or coaching business, which client acquisition method they use, and so on. Each time the lead answers, the workflow runs again. The AI setter checks what it needs to do next and asks the next question.

Once it has asked every question, the AI setter stops asking and scores the lead. It returns three things:

  • a lead score (a number)
  • the lead score reasoning (why it gave that score)
  • a next step (a message such as "you're the exact person we help, would you be open to some ideas?")

That means the workflow has to tell the two kinds of output apart and handle each one differently.

Step 1: Check whether the AI returned a question or a lead score

Before the workflow responds, add an If node right after the AI agent. Rename the agent node to "AI setter" so the If node's expression can point to it by name.

The If node tests one expression:

  • If the output is a question, the If node is true, and the workflow just sends the next question.
  • If the output is a lead score, the If node is false, and the workflow scores the lead in the CRM.

Define the output format with "any of"

I reformatted the AI agent's structured output so it accepts either of two shapes. I used "any of" with two elements:

  1. An object that contains a question.
  2. An object that contains the lead score, the lead score reasoning and the next step.

The lead score has to be an integer. The lead score reasoning, the next step and the question all have to be strings.

The AI sometimes wraps its answer in an "output" object, so the format checks both cases: the object with the question directly inside it, or the object with "output" and then the question. Most of the time the answer comes back inside "output".

Step 2: Create a private integration in GoHighLevel

To change a lead's score, n8n has to talk to the GoHighLevel API v2. The goal here is to update a contact's custom field.

  1. In GoHighLevel, go to Settings, then Private Integrations.
  2. Create a new integration and click Next.
  3. Copy the private integration token (PIT) it gives you.

Use this token to check that your HTTP requests work before you build them into n8n. In the API documentation's "get contact" request, set the authorization to "Bearer" with a capital B, a space, then your token.

Step 3: Find the custom field IDs for the lead score

Next, you need the IDs of the custom fields you will write to.

  1. Go to Contacts and search for a test contact (I searched for myself).
  2. Copy that contact's ID.
  3. Send the "get contact" API request with that ID.

The response shows the contact's emails, tags and custom fields. I had already given a test contact a lead score of seven and some text in the reasoning field. I scrolled through the response until I found the field with the value seven. That gave me the ID of the lead score field, and the reasoning field's ID sat right next to it.

Step 4: Update the contact's custom fields from n8n

On the false branch of the If node, add an HTTP Request node to update the contact.

  1. Open the "update contact" request in the API documentation and copy its URL.
  2. Set the method to PUT, because this is an update.
  3. Put the contact ID in the path of the URL as an expression.
  4. For authentication, choose "predefined credential" and pick the GoHighLevel OAuth2 API connection you already set up. That replaces the bearer token.
  5. Turn on "send headers" and add a header named "Version" with the value from the documentation.
  6. Set the body to JSON.

In the JSON body, open curly brackets for the custom fields. Add two entries, separated by a comma:

  • the lead score field's ID, with the value set to the AI setter's lead score output
  • the lead score reasoning field's ID, with the value set to the AI setter's lead score reasoning output

For the values, copy the expression that points to the AI setter's question output, then swap "question" for "lead score", and then for "lead score reasoning".

Step 5: Route qualified leads with tags

After the update, add another If node and call it "Qualified?". It checks whether the lead score, as a number, is greater than five. A score above five means the lead is qualified.

To add a tag, use the "add tag" request from the API documentation. It is a POST.

  1. Duplicate the update node and rename it "Tag scheduler".
  2. Change the method to POST and use the "add tag" URL, with the contact ID in the path.
  3. Keep the same Version header.
  4. Copy the body from the documentation and set the tag to "AI scheduler".

Then duplicate that node for the false branch. Unqualified leads get the tag "AI seller", which sends them to the sales bot later on.

Step 6: Respond with the next step

At the end of the scoring branch, respond to the lead with the next step. There is no question in this output, so the response uses the "next step" field instead. Rename the node "Respond with next step". The lead replies to this message, and the reply is what starts the next AI agent.

In GoHighLevel, you can now build automations that watch for a lead score change and use the tag to send the lead to the AI scheduler or the AI seller. This is the kind of system we install at Million Dollar Year: code that keeps qualifying and routing leads while you do other work.

Testing the AI lead qualification agent on WhatsApp

To test, I cleared the lead score on my test contact, removed the "AI scheduler" tag and added the "AI setter" tag, so the conversation would go to the AI setter. Then I sent the trigger keyword on WhatsApp.

Fix the "wrong type" error in the If node

The first run threw a "wrong type" error. The AI had returned a question, but the If node was not getting a true or false value. The fix is to check whether the question exists and is not empty, using "question trim". That returns a boolean. When the question is not empty, the result is true and the workflow moves on.

To check for the lead score, the expression has to confirm four things: the lead score is defined, the lead score is a number, the lead score reasoning is not empty, and the next step is not empty. The only difference between the two checks is the "output" in the middle of the path.

Reference the AI setter node by name

I don't like using plain $json in expressions. If you later add steps between nodes, $json points at a different item and the workflow breaks. So in every response node, I reference the AI setter's item JSON output, then "question" or "next step". I always reference the earlier node by its name.

After those fixes, the conversation worked. The AI setter asked about my client acquisition method, then how many clients that brings each month and my current pricing, then where I want the business to be in six to twelve months, then what is holding me back. Each reply came back to my phone within seconds. The agent's memory showed the whole conversation history.

Fixing the GoHighLevel "authorization failed" scope error

When the AI finally scored the lead, the update node failed with "authorization failed: this OAuth class type is not allowed to access this scope". I had connected the credential at the agency level, and these calls need location-level access.

The fix:

  1. Create a new GoHighLevel credential in n8n.
  2. Connect it to the sub-account instead of the agency account.
  3. Use that credential in the update and tag nodes, and remove the old authorization header.

After that, the run worked. The contact got a lead score of eight and the reasoning appeared in the custom fields. The "AI scheduler" tag was added, and when I replied, the conversation went to the AI scheduler, which asked the right question.

Two things to improve

I hadn't given the AI setter any qualification criteria, so it had nothing specific to score against. Give it clear criteria so the score means something.

There is also a redundant step. The last qualification question asks whether the lead is open to hearing how you can help, and then the scoring output's next step asks the same thing again. Remove one of the two.

Key takeaways

  • Make your AI agent return either a question or an object with a lead score, the score reasoning and a next step, and use an If node to tell them apart.
  • Create a private integration in GoHighLevel and use a test contact to find the IDs of your lead score and reasoning custom fields.
  • Update the contact with a PUT request that includes the Version header and a JSON body of custom fields filled from the AI agent's output.
  • Tag leads scoring above five for an AI scheduler and everyone else for an AI seller, so GoHighLevel automations can route them.
  • Connect your GoHighLevel credential to the sub-account instead of the agency account if you get an authorization scope error.
  • Give the AI agent clear qualification criteria so its score has something specific to measure against.

Questions and answers

How do I send an AI lead score from n8n to GoHighLevel?

Use an HTTP Request node with the PUT method on the GoHighLevel API v2 update contact endpoint, with the contact ID in the path. Add the Version header and a JSON body of custom fields. Put the lead score field ID with the AI's lead score, and the reasoning field ID with the AI's reasoning.

How do I find a custom field ID in GoHighLevel?

Create a private integration under Settings to get an access token. Then run the get contact API request on a test contact that already has a value in the field. Look through the custom fields in the response for that value. The ID next to it is the field's ID.

Why does GoHighLevel say my OAuth class type is not allowed to access this scope?

In my case, the credential was connected to the agency account, and these calls need location-level access. I created a new credential in n8n, connected it to the sub-account, and the update and tag requests worked.

What score counts as a qualified lead?

In this build, any lead score greater than five counts as qualified. Qualified leads get the AI scheduler tag to get them on a call. Unqualified leads get the AI seller tag to be offered a product.

Why does my n8n If node give a wrong type error?

The If node needs a true or false value. Checking whether the question exists and is not empty, with a trim, returns a boolean, and that fixed the error. Reference the AI agent node by its name too, so the expression keeps working if you add steps later.

For 6-figure coaches and agencies

Build a million dollar business, solo, with systems and AI.

Start with the free app: your year planned down to today, your numbers in one place, and exactly what your goal takes.

Get the free app

Free · No card · On the web and on your iPhone

Keep reading