How Can I Bypass Error 422 in a Workflow When Contact Doesn't Exist in Gohighlevel?

This topic was automatically generated from Slack. You can find the original thread here.

Hey Guys,

I am working on a workflow on which i added the check if the contact exist in Gohighlevel. I am sending a “GET” Request and in response i get the lead data. Here’s the 2 scenarios:

  1. Lead Exist (This scenario is working great because i am getting 200 success response + A contact Data)
  2. Lead Does Not Exist (Stopped the whole workflow because of ERROR 422. Because email doesn’t exist and this is why it is throwing 422 error).
    Is there anyway i can bypass the error 422 since i already added a check on next step which will check if the contacts exists or not? I don’t want the error to stop the workflow.

We have the exact some condition in one of our workflows.

We used a fetch request in a node.js code step instead.

How to send an HTTP GET request using fetch in node.js

To send an HTTP GET request using fetch in Node.js, you can use the node-fetch package. Here’s a step-by-step guide on how to do it: 1. Install the node-fetch package: First, you need to install the node-fetch package in your Node.js environment. You can do this by running the following command: bash npm install node-fetch 2. Use node-fetch to make a GET request: Once you have installed the package, you can use it to make HTTP GET requests. Here’s an example of how to do this: import fetch from 'node-fetch'; async function fetchData(url) { try { const response = await fetch(url); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log(data); } catch (error) { console.error('Error fetching data:', error); } } const url = 'https://api.example.com/data'; fetchData(url); In this example, fetchData is an asynchronous function that takes a URL as an argument. It uses fetch to send a GET request to the specified URL. The response is checked for errors, and if successful, the JSON data is parsed and logged to the console. Remember to replace 'https://api.example.com/data' with the actual URL you want to request.

: node-fetch is not necessary, since fetch is available natively in node.js.

Please give an example without using node-fetch.

Certainly! In Node.js, you can use the native fetch API to make HTTP requests without needing to install node-fetch. Here’s an example of how you might use the native fetch to make a GET request: export default defineComponent({ async run({ steps, $ }) { const response = await fetch('https://api.example.com/data'); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); return data; } }); In this example: - We use the fetch function to send a GET request to https://api.example.com/data. - We check if the response is OK (status code 200-299) and throw an error if it’s not. - We use response.json() to parse the JSON response into a JavaScript object. - Finally, we return the parsed data. This example demonstrates how to use the native fetch API in Node.js without relying on external libraries like node-fetch.