APIs & Integrations

dannsg
Member

Unable to udpate property via api with dash "-" in value

SOLVE

I am trying to update property values via the hubspot api, and I have no issues unless there is a special character in the property value.

 

In particular, I wan to update a propety like this:

 

 

    'properties' => array(
        array(
            'property' => 'email',
            'value' => 'dan@nsgroupllc.com'
        ),
        array(
            'property' => 'firstname',
            'value' => 'daniel'
        ),
        array(
            'property' => 'lastname',
            'value' => 'from nsg testing'
        ),
        array(
            'property' => 'phone',
            'value' => '222-2222'
        ),
        array(
            'property' => 'zip',
            'value' => '54321'
        ),
        array(
            'property' => 'how_long_have_you_owned_your_home_',
            'value' => "5 – 10 years"
        ),

 

 

Here are the values for how_long_have_you_owned_your_home_:

 

1 – 5 Years
5 – 10 Years
10 – 15 Years
16+ Years
I Do Not Own The Home I Live In.
I Am Currently Building A New Home.
I Am Looking To Purchase A New Home.

 

I have no problems if I add a value without any special characters (such as the last 4 items in the list). But if I try to add any value with a dash in it (such as the first 3 items in the list), I get an error similar to the one below:

 

 

"{"validationResults":[{"isValid":false,"message":"5 – 10 years was not one of the allowed options: [label: \"1 \\342\\200\\223\\302\\2405 years\"\nvalue: \"1 \\342\\200\\223\\302\\2405 years\"\ndisplay_order: 0\ndouble_da
ta: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"5 \\342\\200\\223\\302\\24010 years\"\nvalue: \"5 \\342\\200\\223\\302\\24010 years\"\ndisplay_order: 1\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_onl
y: false\n, label: \"10 \\342\\200\\223\\302\\24015 years\"\nvalue: \"10 \\342\\200\\223\\302\\24015 years\"\ndisplay_order: 2\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"16+ years\"\nvalue: \"16+ ye
ars\"\ndisplay_order: 3\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"I do not own the home I live in.\"\nvalue: \"I do not own the home I live in.\"\ndisplay_order: 4\ndouble_data: 0.0\nhidden: false\
ndescription: \"\"\nread_only: false\n, label: \"I am currently building a new home.\"\nvalue: \"I am currently building a new home.\"\ndisplay_order: 5\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"I
am looking to purchase a new home.\"\nvalue: \"I am looking to purchase a new home.\"\ndisplay_order: 6\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n]","error":"INVALID_OPTION","name":"how_long_have_you_owned_yo
ur_home_"}],"status":"error","message":"Property values were not valid","correlationId":"c4fdbba2-1e73-4677-8b24-6dcdbfc5b9b3"}"

 

 

 

As you can see, the dash (-) is being interpreted as:

\\342\\200\\223\\302\\240

 

How can I send the following values via the api?

 

1 – 5 Years
5 – 10 Years
10 – 15 Years

 

Thanks!

 

radio-select.jpg

0 Upvotes
1 Accepted solution
dannsg
Solution
Member

Unable to udpate property via api with dash "-" in value

SOLVE

I have finally got to the bottom of this by brute force.

 

I compiled a very long list of potential values which included direct copy/pastes, utf-8 characters and html entities, each of which were subject to different iterations of escaping and encoding.

 

Then, using the api, I spammed hubspot with each value until one of them eventually worked.

 

As it turns out, there were actually two special characters in there:

 

\342\200\223

 is octal for en-dash

 

\302\240

 is octal for non-breaking-space

 

The special characters just needed to be sent as octal without any special escaping or encoding.

 

At the end of the day, this is what worked:

 

array(
'property' => 'how_long_have_you_owned_your_home_',
'value' => "1 \342\200\223\302\2405"
)

 

I'm sharing this here in case anyone else runs into this issue, as I don't believe this is documented anywhere and there are a bunch of related, unsolved issues lingering in the Community forums.

 

Hopefully this helps!

View solution in original post

15 Replies 15
dannsg
Solution
Member

Unable to udpate property via api with dash "-" in value

SOLVE

I have finally got to the bottom of this by brute force.

 

I compiled a very long list of potential values which included direct copy/pastes, utf-8 characters and html entities, each of which were subject to different iterations of escaping and encoding.

 

Then, using the api, I spammed hubspot with each value until one of them eventually worked.

 

As it turns out, there were actually two special characters in there:

 

\342\200\223

 is octal for en-dash

 

\302\240

 is octal for non-breaking-space

 

The special characters just needed to be sent as octal without any special escaping or encoding.

 

At the end of the day, this is what worked:

 

array(
'property' => 'how_long_have_you_owned_your_home_',
'value' => "1 \342\200\223\302\2405"
)

 

I'm sharing this here in case anyone else runs into this issue, as I don't believe this is documented anywhere and there are a bunch of related, unsolved issues lingering in the Community forums.

 

Hopefully this helps!

davidk
Member

Unable to udpate property via api with dash "-" in value

SOLVE

This is AWESOME.

I ran into the same problem.

It looks to me like octal escapes (which are deprecated) no longer work.

But unicode escapes DO seem to work. 

Joy.

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Unable to udpate property via api with dash "-" in value

SOLVE

So added a value with the en-dash and I am still able to submit the data 🤔

Here is my payload

{
  "properties": [
    {
      "property": "test_spaces",
      "value": "11 – 15"
    }
  ]
}

It isn't obvious in that code block, but that is the en-dash – and not the hyphen minus -

 

@quentin_lamamy , did you have a chance to test?

0 Upvotes
dannsg
Member

Unable to udpate property via api with dash "-" in value

SOLVE

Any news here? This is not a php issue as far as I can tell. I created a json file called test.json that looks like this:

 

{
  "properties": [
    {
      "property": "email",
      "value": "dan@nsgroupllc.com"
    },
    {
      "property": "firstname",
      "value": "dan"
    },
    {
      "property": "lastname",
      "value": "dandandan"
    },
    {
      "property": "phone",
      "value": "111-1111"
    },
    {
      "property": "zip",
      "value": "48104"
    },
    {
      "property": "how_long_have_you_owned_your_home_",
      "value": "1 – 5 years"
    }
  ]
}

 

I can post this to HubSpot using curl:

 

curl -X POST https://api.hubapi.com/contacts/v1/contact/vid/{redacted}/profile?hapikey={redacted} -H "Content-Type: application/json" --data-binary "@test.json"

 

When I do, I get the same error:

 

{"validationResults":[{"isValid":false,"message":"1 – 5 years was not one of the allowed options: [label: \"1 \\342\\200\\223\\302\\2405 years\"\nvalue: \"1 \\342\\200\\223\\302\\2405 years\"\ndisplay_order: 0\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"5 \\342\\200\\223\\302\\24010 years\"\nvalue: \"5 \\342\\200\\223\\302\\24010 years\"\ndisplay_order: 1\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"10 \\342\\200\\223\\302\\24015 years\"\nvalue: \"10 \\342\\200\\223\\302\\24015 years\"\ndisplay_order: 2\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"16+ years\"\nvalue: \"16+ years\"\ndisplay_order: 3\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"I do not own the home I live in.\"\nvalue: \"I do not own the home I live in.\"\ndisplay_order: 4\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"I am currently building a new home.\"\nvalue: \"I am currently building a new home.\"\ndisplay_order: 5\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"I am looking to purchase a new home.\"\nvalue: \"I am looking to purchase a new home.\"\ndisplay_order: 6\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n]","error":"INVALID_OPTION","name":"how_long_have_you_owned_your_home_"}],"status":"error","message":"Property values were not valid","correlationId":"f93ebc88-a2c2-4163-a3d8-0c4fb58a0e51"}

 

If I post a value without an endash, the post is successful, there are no errors, and the changes are immediately reflected in my hubspot account.

 

I must say this is pretty frustrating. The issue has been open for 2 weeks, and I have no idea how to troubleshoot. What can be done to solve this?

 

@dennisedson, if I share my vid and hapikey with you, could you try posting to see if you get the same error?

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Unable to udpate property via api with dash "-" in value

SOLVE

Sure, shoot me a dm 🙂

0 Upvotes
quentin_lamamy
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Unable to udpate property via api with dash "-" in value

SOLVE

Hi @dennisedson @dannsg ,

I am actually not in front on my iMac, i will answer you during the night (Paris timezone) or tomorrow 


0 Upvotes
dannsg
Member

Unable to udpate property via api with dash "-" in value

SOLVE

Any help provided is very much appreciated. Thank you both for your time.

 

@dennisedson, it looks like the dash you are successfully using is not the same character I am using.

 

The dash you're using is hypen-minus:

https://www.unicodepedia.com/unicode/basic-latin/2d/hyphen-minus/

 

The dash I'm using is an en-dash:

https://www.unicodepedia.com/unicode/general-punctuation/2013/en-dash/

 

I ran a test, and I also have no problems passing property values with hyphen-minus.

 

The failure occurs when I try to pass a property value with an en-dash.

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Unable to udpate property via api with dash "-" in value

SOLVE

Hey @dannsg , was out of office yesterday.  Will test again with the en-dash and report back to you! 

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Unable to udpate property via api with dash "-" in value

SOLVE

Hello @dannsg 

Thanks for hanging in there.  So I tested again using the update a contact endpoint and was successful with this JSON payload:

{
  "properties": [
    {
      "property": "test_spaces",
      "value": "1 - 5"
    }
  ]
}

This is leading me to believe that something is off with the PHP that you have there.  I am no pro at PHP.  I should probably get better at it 😀

@quentin_lamamy , I believe, is a bit more savy with that language.  Hoping he can chime in here

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Unable to udpate property via api with dash "-" in value

SOLVE

Ah.  We are looking at two different endpoints :facepalm

I thought you were using the update form endpoint

I will test on the one you are using and get back to you!

0 Upvotes
dannsg
Member

Unable to udpate property via api with dash "-" in value

SOLVE

Dennis, I really appreciate your help!

 

Example code below:

 

<?php
$vid = [redacted];
$hapikey = [redacted];
$email = "dan@nsgroupllc.com";

$arr = array(
    'properties' => array(
        array(
            'property' => 'email',
            'value' => 'dan@nsgroupllc.com'
        ),
        array(
            'property' => 'firstname',
            'value' => 'djh'
        ),
        array(
            'property' => 'lastname',
            'value' => 'lastname'
        ),
        array(
            'property' => 'phone',
            'value' => '555-5555'
        ),
        array(
            'property' => 'zip',
            'value' => '48104'
        ),
        array(
            'property' => 'how_long_have_you_owned_your_home_',
            'value' => "1 – 5 years"
        ),
    )
);

$updatecontact = "https://api.hubapi.com/contacts/v1/contact/vid/". $vid . "/profile?hapikey=" . $hapikey;
$post_json = json_encode($arr);
$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $post_json);
@curl_setopt($ch, CURLOPT_URL, $updatecontact);
@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;

 

Output from that code is:

 

curl Errors:
Status code: 400
Response: {"validationResults":[{"isValid":false,"message":"1 – 5 years was not one of the allowed options: [label: \"1 \\342\\200\\223\\302\\2405 years\"\nvalue: \"1 \\342\\200
\\223\\302\\2405 years\"\ndisplay_order: 0\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"5 \\342\\200\\223\\302\\24010 years\"\nvalue: \"5 \\
342\\200\\223\\302\\24010 years\"\ndisplay_order: 1\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"10 \\342\\200\\223\\302\\24015 years\"\nval
ue: \"10 \\342\\200\\223\\302\\24015 years\"\ndisplay_order: 2\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"16+ years\"\nvalue: \"16+ years\
"\ndisplay_order: 3\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"I do not own the home I live in.\"\nvalue: \"I do not own the home I live i
n.\"\ndisplay_order: 4\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"I am currently building a new home.\"\nvalue: \"I am currently building
a new home.\"\ndisplay_order: 5\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"I am looking to purchase a new home.\"\nvalue: \"I am looking t
o purchase a new home.\"\ndisplay_order: 6\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n]","error":"INVALID_OPTION","name":"how_long_have_you_owned_you
r_home_"}],"status":"error","message":"Property values were not valid","correlationId":"48f34ac4-04fe-4335-85bc-fdde95f4d02f"}

 

As previously stated, I have no problem submitting values without an en dash. For example, this works fine:

 

        array(
            'property' => 'how_long_have_you_owned_your_home_',
            'value' => "I do not own the home I live in."
        ),

 

 

0 Upvotes
dannsg
Member

Unable to udpate property via api with dash "-" in value

SOLVE

To provide further information, that dash is an en dash.

 

https://www.unicodepedia.com/unicode/general-punctuation/2013/en-dash/

 

I've tried escaping it in every way I can, but no luck.

 

I've also tried posting the endash as string from the error message, like this:

 

array(
'property' => 'how_long_have_you_owned_your_home_',
'value' => "5 \\342\\200\\223\\302\\24010 years"
)

 

That returns this error:


string(1556) "{"validationResults":[{"isValid":false,"message":"5 \\342\\200\\223\\302\\24010 years was not one of the allowed options: [label: \"1 \\342\\200\\223\\302\\2405 years\"\nvalue: \"1 \\342\\200\\223\\302\\2405 years\"\ndisplay_order: 0\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"5 \\342\\200\\223\\302\\24010 years\"\nvalue: \"5 \\342\\200\\223\\302\\24010 years\"\ndisplay_order: 1\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"10 \\342\\200\\223\\302\\24015 years\"\nvalue: \"10 \\342\\200\\223\\302\\24015 years\"\ndisplay_order: 2\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"16+ years\"\nvalue: \"16+ years\"\ndisplay_order: 3\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"I do not own the home I live in.\"\nvalue: \"I do not own the home I live in.\"\ndisplay_order: 4\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"I am currently building a new home.\"\nvalue: \"I am currently building a new home.\"\ndisplay_order: 5\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n, label: \"I am looking to purchase a new home.\"\nvalue: \"I am looking to purchase a new home.\"\ndisplay_order: 6\ndouble_data: 0.0\nhidden: false\ndescription: \"\"\nread_only: false\n]","error":"INVALID_OPTION","name":"how_long_have_you_owned_your_home_"}],"status":"error","message":"Property values were not valid","correlationId":"66e120a5-6db2-4efe-a7ee-73742bf6768e"}"


Pulling out the relevant parts of the error:

 

5 \\342\\200\\223\\302\\24010 years was not one of the allowed options
5 \\342\\200\\223\\302\\24010 years\"\nvalue: \"5 \\342\\200\\223\\302\\24010 years\"

 

I'm completely stuck. Any suggestions?

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Unable to udpate property via api with dash "-" in value

SOLVE

hey @dannsg !

Apologies for not getting back for you sooner.  I set up a test in my portal and was successfully able to pass this json through the API endpoint

{
  "name": "updated form name",
  "redirect": "http://hubspot.com",
  "formFieldGroups": [
    {
            "fields": [
                {
                    "name": "test_spaces",
                    "label": "test spaces",
                    "type": "enumeration",
                    "fieldType": "select",
                    "description": "",
                    "groupName": "contactinformation",
                    "displayOrder": -1,
                    "required": false,
                    "selectedOptions": [],
                    "options": [
                        {
                            "label": "1 - 5",
                            "value": "1 - 5",
                            "displayOrder": 0,
                            "doubleData": 0.0,
                            "hidden": false,
                            "description": "",
                            "readOnly": false
                        },
                        {
                            "label": "6 - 20",
                            "value": "6 - 20",
                            "displayOrder": 1,
                            "doubleData": 0.0,
                            "hidden": false,
                            "description": "",
                            "readOnly": false
                        }
                    ],
                    "validation": {
                        "name": "",
                        "message": "",
                        "data": "",
                        "useDefaultBlockList": false,
                        "blockedEmailAddresses": []
                    },
                    "enabled": true,
                    "hidden": false,
                    "defaultValue": "",
                    "isSmartField": false,
                    "unselectedLabel": "",
                    "placeholder": "",
                    "dependentFieldFilters": [],
                    "labelHidden": false,
                    "propertyObjectType": "CONTACT",
                    "metaData": [],
                    "objectTypeId": "0-1"
                }
            ]
          }
      ]
    }
  ]
}

 

@kierana, do you see anything glaring that would cause this to fail?

@dannsg , maybe you could put your full code block up here so we can take a closer look?

 

 

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Unable to udpate property via api with dash "-" in value

SOLVE

Hello @dannsg !

Are you tied to having the internal values as they are?  I would recommend underscores for them

dannsg
Member

Unable to udpate property via api with dash "-" in value

SOLVE

Hi Dennis!

 

I appreciate your response, but I'm not sure I understand what you're suggesting.

 

If you mean I should change the Internal Values, that is not an option. The Internal values can't be changed once they're in use (see screenshot attached).

 

Currently, they are in use by embedable js forms created by HubSpot.

 

What I am doing is building a separeate interface using the HubSpot API. As mentioned previously, this works perfectly as long as the property values don't have a dash in them.

 

So the question remains open: How can I send the following values via the api?

 

1 – 5 Years
5 – 10 Years
10 – 15 Years

 

Thanks!

 

 cannot-change-internal-values.jpg

0 Upvotes