APIs & Integrations

vbhubspotuser
Member

Can't add new contacts, "property cannot be missing or null"

SOLVE

Here is my code:

<?php

$propArr = array(
        'properties' => array(
            array(
                "name" => "email",
                "value" => "testingapis@hubspot.com"
            ),
            array(
              "name" => "firstname",
              "value" => "Adrian"
            ),
            array(
              "name" => "lastname",
              "value" => "Mott"
            ),
            array(
              "name" => "website",
              "value" => "http =>//hubspot.com"
            ),
            array(
              "name" => "company",
              "value" => "HubSpot"
            ),
            array(
              "name" => "phone",
              "value" => "555-122-2323"
            ),
            array(
             "name" => "address",
              "value" => "25 First Street"
            ),
            array(
              "name" => "city",
              "value" => "Cambridge"
            ),
            array(
              "name" => "state",
              "value" => "MA"
            ),
            array(
              "name" => "zip",
              "value" => "02139"
            )
        )
    );

    echo "Adding Contact \n\n";
    $endpoint = 'https://api.hubapi.com/contacts/v1/contact/?hapikey=' . $hapikey;
    $ch = @curl_init();
    @curl_setopt($ch, CURLOPT_POST, true);
    $post_json = json_encode($propArr);
    @curl_setopt($ch, CURLOPT_POSTFIELDS, $post_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);
    $status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $curl_errors = curl_error($ch);
    @curl_close($ch);
    echo "curl Errors: " . $curl_errors;
    echo "\nStatus code: " . $status_code;
    echo "\nResponse: " . $response . "\n\n";
}

And the error message I’m getting:

Response: {“status”:“error”,“message”:“property cannot be missing or null”, etc.}

I’m not sure what property the msg is referring to, have tried to add/remove different properties from the array to no avail.

Thanks

0 Upvotes
1 Accepted solution
vbhubspotuser
Solution
Member

Can't add new contacts, "property cannot be missing or null"

SOLVE

Nevermind, I am dumb. Needed to switch out the “name” property with “property.” Wish there was a way to delete the post, as it’s sort of useless at this point.

View solution in original post

10 Replies 10
JHUSSON
Participant

Can't add new contacts, "property cannot be missing or null"

SOLVE

All of this is still true in nov. 2021. This post helped me a lot today

Thank you

0 Upvotes
ramonpego
Member

Can't add new contacts, "property cannot be missing or null"

SOLVE

this help me today hahaha

0 Upvotes
Charlie_Stanard
Member

Can't add new contacts, "property cannot be missing or null"

SOLVE

This has helped me on multiple occasions now :smile:

0 Upvotes
hiltonrrn
Participant

Can't add new contacts, "property cannot be missing or null"

SOLVE

It's not a dumb question! I found myself with the same issue... typed the word "property" wrong! So, after read this post, it's fixed. Thanks!

gillytech
Contributor

Can't add new contacts, "property cannot be missing or null"

SOLVE

Yeah thanks for keeping this up because I had the same "dumb" question!

0 Upvotes
vbhubspotuser
Solution
Member

Can't add new contacts, "property cannot be missing or null"

SOLVE

Nevermind, I am dumb. Needed to switch out the “name” property with “property.” Wish there was a way to delete the post, as it’s sort of useless at this point.

koseto
Member

Can't add new contacts, "property cannot be missing or null"

SOLVE

Actually it's the fault of the HS person who architected the system; s/he is probaly either junior or did not pay attention to details. 
Several issues that will waste a lot of your time:

1) JSON format inconsistencies: some uploads require "name/value" pair; others "property/value" pair - it is not consistent! So if you copy your code for "contact" and use it for 'deal', you will get misleading error!!! I've spet tones of time searching for solution just to find out this stupid discrepancy. 

2) Inconsistent Error Behavior - if you use the incorrect JSON format (i.e. if you pass "name/value" instead of "property/value"), some API calls (such as Deals) will cause an error, while others (such as Company) will silently accept the API and will return NO errors (which causes confusion since you assume that the API call works)

3) Misleading errors: if you use the wrong JSON format, the error will NOT tell you that the value pair names are wrong, but rather will tell you that the property/name is missing with an "emtpy" string - which is useless and misleading.

4) Inconsistent use of HTTP verbs - some UPDATE API calls use "POST", others "PUT" 
5) Idiotic calculation of milliseconds from 1970-01-01 using UTC time - that's a good one.  I followed the instructions but my client is complaining that I am one day off. I manually add an extra day and it works in some cases but not in other.  If you convert it to UTC, the system comes back and states that it requires MIDNIGHT time and fails the API call.   I was not able to figure this one out so I told the client to contact HS. I gave up.  I guess it's very difficult ot accept a standard date like every other modern system. 

Since the issues are still there, I guess it's very difficult to either fix the inconsistencies, or even better, allow both "name/value" and "property/value" to be accepted as an input!!!

I spent a lot of time figuring out the immaturity of the system; I don't like it but a client want it.   I was very disappoint when I ask for help, and HubSpot offered me 1500$ for 4 hours for JScirpt development - i.e. 400$/hour support for trivial development?!   I wish I could send them my 20+ hours at their rate of researching their bad design at my expense 🙂 Their test guys should have caught this issues and address them, if not fixing them in the syste, at least document them in the useless forum.

Your post was one of the few that actually help.  Thank you!  The rest of it is mostly content to fill the pages...so you can say that there is something published (better than nothing) 🙂 

Good luck

LdePaulaLima
Participant

Can't add new contacts, "property cannot be missing or null"

SOLVE

just lost some hours in the same issue. hubspot needs to improve those error messages

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

Can't add new contacts, "property cannot be missing or null"

SOLVE

@vbhubspotuser I can remove the post for you if you’d like? I’d argue keeping it as others have run into or will run into the same error message at some point and I believe this could help future developers trying to interface with the HubSpot APIs.

0 Upvotes
vbhubspotuser
Member

Can't add new contacts, "property cannot be missing or null"

SOLVE

@pmanca Sure, we can keep it up. Hopefully it will help others.

0 Upvotes