Problem with hapikey

contacts

#1

@pmanca please tell me what I have not added to the contacts when I change hapikey? I have 2 projects. I realized at one adding contacts, and the second insert the same code, changing only hapikey, but the contacts are not added to the two contacts list

js code:

function login() {
    var email = $('#agilefield-2').val();
    var message = '';
    if ($('input[name=remove]').prop('checked')) {
        message = nameApp + ' subscription: not requested';
    }
    $.ajax({
        type: "POST",
        url: "/" + courseDir + "/send-contact.php",
        data: {
            'email': email,
            'message': message
        },
        success: function(data) {
            console.log('succes)))');
        },
        error: function(xhr, str) {
            console.log('error)))');
        }
    })
}

php code:

$message = $_POST["message"];
$email = $_POST["email"];

if($message != null) {
    $arr = array(
        "properties" => array(
            array(
                "property" => "email",
                "value" => $email
            ),
            array(
                "property" => "lifecyclestage",
                "value" => 'opportunity'
            ),
            array(
                "property" => "message",
                "value" => $message
            )
        )
    );
} else {
    $arr = array(
        "properties" => array(
            array(
                "property" => "email",
                "value" => $email
            ),
            array(
                "property" => "lifecyclestage",
                "value" => "opportunity"
            )
        )
    );
}

$post_json = json_encode($arr);

$endpoint = "https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/".$email."/?hapikey=2489173";
$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@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);
@curl_exec($ch);
@curl_close($ch);

#2

@golinka

$arr = array(
        "properties" => array(
            array(
                "property" => "email",
                "value" => $email
            ),
            array(
                "property" =>; "lifecyclestage",
                "value" =>; "opportunity"
            )
        )
    );

I don’t believe you need to create an array of arrays here.

There is some example php here on this end point. This might help you.

I would look at how they make their array here.

$hs_context      = array(
    'hutk' => $hubspotutk,
    'ipAddress' => $ip_addr,
    'pageUrl' => 'http://www.example.com/form-page',
    'pageName' => 'Example Title'
);

Make sure to have it formatted to match the JSON in the dev documentation.


#3

@pmanca I do not think that’s the problem. I’ve used this code on the first project and everything works fine. When I moved the code into a new project, my form does not add a contact in the list.

But I will try your option


#4

Are you trying to add contacts which already exist? Did you move over your php file as well?


#5

@golinka do both projects go to the same portal?


#6

@pmanca No, on different. on different domains, if you have it. but added in a single user crm


#7

@golinka Does the second portal have a message as a custom property as well? Do you get a response code back when you try it on the non-working portal?