# Getting error on data outputs in custom code

**URL:** <https://community.hubspot.com/t/getting-error-on-data-outputs-in-custom-code/123865>\
**Category:** CMS Development\
**Tags:** enterprise\
**Created:** [January 14, 2025, 10:52am UTC](https://community.hubspot.com/t/getting-error-on-data-outputs-in-custom-code/123865 "2025-01-14T10:52:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ASund-Nielsen](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@ASund-Nielsen](https://community.hubspot.com/u/ASund-Nielsen)\
**Post date:** [January 14, 2025, 10:52am UTC](https://community.hubspot.com/t/getting-error-on-data-outputs-in-custom-code/123865/1 "2025-01-14T10:52:15Z")

</div>

Hi,

Im using the below custom code for a workflow. The API token has been changed to now show it, but is correctly inserted.

The script runs successfully, but the data outputs show as not defined in code. What am I doing wrong?

```lia-code-sample
# Import required modules
import hubspot
from hubspot.crm.deals import ApiException

def main(event):
 # Initialize HubSpot client with hardcoded API token
 hubspot_client = hubspot.Client.create(access_token="PRIVATE")

 debug_outputs = {} # Dictionary to collect debug logs

 try:
 # Input data from the workflow
 deal_identifier = event.get("inputs", {}).get("deal_identifier") # Retrieve the deal identifier from workflow inputs
 debug_outputs["input_deal_identifier"] = deal_identifier # Log the deal identifier passed in the input

 if not deal_identifier:
 debug_outputs["error"] = "deal_identifier is not being passed correctly from the workflow."
 return debug_outputs

 try:
 # Fetch the current deal data
 deal_api = hubspot_client.crm.deals
 deal = deal_api.basic_api.get_by_id(deal_identifier, properties=["pipeline", "deal_identifier"])

 # Debugging: Log the current pipeline and deal_identifier values
 pipeline = deal.properties.get("pipeline")
 current_value = deal.properties.get("deal_identifier")
 debug_outputs["debug_pipeline"] = pipeline
 debug_outputs["debug_current_value"] = current_value

 # Ensure the deal is in the specified pipeline
 if pipeline != "602537446": # Replace with your target pipeline ID
 debug_outputs["skipped"] = True
 debug_outputs["message"] = "Deal not in the target pipeline."
 return debug_outputs

 # Increment the deal_identifier value
 if current_value is None:
 current_value = 3000 # Start counting at 3000 if the property is not set
 else:
 current_value = int(current_value) # Convert current value to integer

 # Debugging: Log the incremented value
 new_value = current_value + 1
 debug_outputs["debug_new_value"] = new_value

 # Update the deal property
 deal_api.basic_api.update(
 deal_identifier,
 {"properties": {"deal_identifier": new_value}}
 )

 # Return success message and the new value
 debug_outputs["message"] = "Success"
 debug_outputs["new_value"] = new_value
 return debug_outputs

 except ApiException as e:
 # Handle API exceptions
 debug_outputs["error"] = f"API exception occurred: {e.status} - {e.reason}"
 debug_outputs["details"] = str(e.body)
 return debug_outputs

 except Exception as e:
 # Handle unexpected exceptions
 debug_outputs["error"] = f"An unexpected error occurred: {str(e)}"
 return debug_outputs

```

 ![ASundNielsen_1-1736851849447.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/f/fd07c5e8ba54c88fd96839e1003cec9ebbc321f7.png)

 ![ASundNielsen_2-1736851879301.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/5/5046952b26b7f955525707c899e63f75537b76e2.png)

---

<div class="post-metadata">

**Author:** ![evaldas](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/evaldas/32/69160_2.png) [@evaldas](https://community.hubspot.com/u/evaldas)\
**Post date:** [January 14, 2025, 3:47pm UTC](https://community.hubspot.com/t/getting-error-on-data-outputs-in-custom-code/123865/2 "2025-01-14T15:47:18Z")

</div>

Hi @ASund-Nielsen,

The custom coded actions in workflows expect the output to be returned in JSON format with “outputFields” nested dictionary.

For example, instead of this:

```lia-code-sample
if not deal_identifier:
 debug_outputs["error"] = "deal_identifier is not being passed correctly from the workflow."
 return debug_outputs

```

Try replacing with this structure:

```lia-code-sample
 if not deal_identifier:
 return {
 "outputFields": {
 "message": "deal_identifier is not being passed correctly from the workflow.",
 "debug_new_value": None
 }
 }

```

I replaced the “error” with “message” since I do not see “error” being one of your outputs, but you can customize to what your output fields need to be.

This would apply to all of the return statements for the outputs.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![GRajput](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/grajput/32/102020_2.png) [@GRajput](https://community.hubspot.com/u/GRajput)\
**Post date:** [January 15, 2025, 12:45pm UTC](https://community.hubspot.com/t/getting-error-on-data-outputs-in-custom-code/123865/3 "2025-01-15T12:45:13Z")

</div>

Hi @ASund-Nielsen

You have to define output fields in the code and make sure to use the same name defined  
eg instead of directly returning the debug\_outputs you have to write

```lia-code-sample
return {
 "outputFields": {
 "debug_current_value": "value you want.",
 "debug_new _value": "value you want.",
 "debug_pipeline": "value you want.",
 "message": "value you want."
 }
 }

```

I hope this will help you out. Please mark it as **Solution Accepted and upvote** to help another Community member.  
Thanks!
