APIs & Integrations

krotons
Member

got Invalid input JSON Error

Invalid input JSON on line 1, column 1: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token

 

my code:

from hubspot3 import Hubspot3

def sync_product(self):        
        conn = self.env['hubspot.connection'].search([])
        api_key = conn.api_key
        client = Hubspot3(api_key=api_key)
        data = {
            "properties": [
                {
                    "name": "name",
                    "value": self.display_name or " "
                },
                {
                    "name": "description",
                    "value": self.description or " "
                },
                {
                    "name": "price",
                    "value": self.standard_price or " "
                },
                {
                    "name": "recurringbillingfrequency",
                    "value": "quarterly"
                }
            ]
        }
        product = client.products.create(data)

what's wrong with this i got warning like

 

hub root: Too many retries for /crm-objects/v1/objects/products?hapikey=92..........

 

also:

 

Invalid input JSON on line 1, column 1: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token

---- request ----
POST api.hubapi.com/crm-objects/v1/objects/products?hapikey=9274****, [timeout=<class 'int'>]

---- body ----
<class 'NoneType'>

---- headers ----
<class 'dict'>

---- result ----
<class 'int'>

---- body -----
{"status":"error","message":"Invalid input JSON on line 1, column 1: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token","correlationId":"88ea35f6-43c5-421a-9684-8a3fbee08532","requestId":"24dcbdef-d951-4092-868d-48e7d86bf0ed"}

---- headers -----
<class 'http.client.HTTPMessage'>

---- reason ----
Bad Request

---- trigger error ----
<class 'NoneType'>

 

i have successfully connection with api i didn't get any error with api connection. 

 

please help.

 

 

0 Upvotes
3 Replies 3
ms19
Member

got Invalid input JSON Error

i've same problem in php?

 {"status":"error","message":"Invalid input JSON on line 1, column 1: Cannot deserialize value of type `com.hubspot.inbounddb.publicobject.core.v2.SimplePublicObjectInputForCreate$Json` from Array value (token `JsonToken.START_ARRAY`)","correlationId":"b292d6c5-55a4-4d5f-b386-875453f88bf1"}

 

 here is my code:

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Check if the 'name', 'email', and 'phone' keys exist in the $_POST array
    if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["phone"])) {
        // Retrieve form data
        $name = $_POST["name"];
        $email = $_POST["email"];
        $phone = $_POST["phone"];
 
        // Perform any validation or processing here
 
        // Prepare data to be sent to the API
        $data = array(
[
            
['name' => 'name', 'value' => $name],
['name' => 'email', 'value' => $email],
['name' => 'phone', 'value' => $phone]
]
        );
 
        $data_string = json_encode($data);
 
        // API URL
        $access_token = 'pat-na1-7618b06c-b2ad-4cd6-9c41-55efa0116a38'; // Replace with your actual access token
 
        $ch = curl_init($api_url);
 
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            'authorization: Bearer ' . $access_token
        ));
 
        $response = curl_exec($ch);
 
        if (curl_errno($ch)) {
            echo 'Error: ' . curl_error($ch);
        } else {
            // Process the API response here (e.g., display or save it)
            echo "API Response: <pre>" . $response . "</pre>";
        }
 
        curl_close($ch);
    } else {
        // Handle the case where one or more form fields are missing
        echo "One or more form fields are missing.";
    }
} else {
    // Handle the case where the page is first loaded
    // You can optionally display the form here
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>Contact Form</title>
    <!-- Include Bootstrap CSS from a CDN -->
</head>
<body>
<section>
    <h2 class="text-center">Contact Form</h2>
    <form method="post" action="contacts.php" class="container">      
        <div class="mb-3">
            <label for="name" class="form-label">Name:</label>
            <input type="text" name="name" class="form-control" required>
        </div>
        
        <div class="mb-3">
            <label for="email" class="form-label">Email:</label>
            <input type="email" name="email" class="form-control" required>
        </div>
        
        <div class="mb-3">
            <label for="phone" class="form-label">Phone:</label>
            <input type="tel" name="phone" class="form-control" required>
        </div>
        <div class="text-center">
            <button type="submit" value="submit" name="submit" class="btn btn-primary">Submit</button>
        </div>
    </form>
 
    <!-- Include Bootstrap JavaScript and jQuery if needed -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</body>
</html>

 

 

 

0 Upvotes
IsaacTakushi
HubSpot Employee
HubSpot Employee

got Invalid input JSON Error

Hi, @krotons.

 

The v1 Products API expects a single array in the payload. Here's the example from the documentation:

[
  {
    "name": "name",
    "value": "A new product"
  },
  {
    "name": "description",
    "value": "A description of this product."
  },
  {
    "name": "price",
    "value": "27.50"
  },
  {
    "name": "recurringbillingfrequency",
    "value": "quarterly"
  }
]

If you remove the {} and the "properties": key, you should receive a successful response.

Isaac Takushi

Associate Certification Manager
0 Upvotes
AShaikh8
Member

got Invalid input JSON Error

Hi I am too facing the same error 
"Invalid input JSON on line 1, column 132: Cannot deserialize value of type `java.util.ArrayList` from Object value (token `JsonToken.START_OBJECT`)" 
Where I am passing the json through curl request below is the following json
{
"name": "DEMO_NAME",
"label": "Demo Property",
"type": "enumeration",
"field_type": "select",
"group_name": "contactinformation",
"options": {
"label": "Danzig",
"value": "Danzig"
},
"display_order": 2,
"has_unique_value": false,
"hidden": false,
"form_field": true
}

and this is my curl request code

$ch = @curl_init();

@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
@curl_setopt($ch, CURLOPT_URL, $endpoint);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
));
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = @curl_exec($ch);
print_r($response);
exit;
$status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_errors = curl_error($ch);
@curl_close($ch);
echo "<br>";

print_r($response);
if($response)
{
echo "Property Created";
echo "<br>";
return $response . "
";
$result = file_get_contents($response);
var_dump(json_decode($result, true));
}
echo "<br>";

}



Please help me out in this with a helpful solution

0 Upvotes