Skip to main content
Solved

Reformat phone numbers within Customer.io?


Rachel
  • Community Manager
  • 24 replies

We are storing phone number to to send SMS to our customers but it is not in the e.164 format. Before I go back to our data team, is there a way to transform the phone numbers into the correct format within Customerio? 

Best answer by joecomotion

Hey Rachel,

If you’re only sending SMS to a maximum of one country or area code, then yes it’s possible to transform a phone number attribute to E.164 format! 

To do so, you’ll create a campaign triggered by a segment which captures everyone who has the phone number attribute. Then in the workflow, you’ll have a create or update person block which updates their phone attribute. You’ll set the value of the attribute to liquid and use the following code:

{% assign x = customer.phone | replace:” “, “” | replace: “(”, “” | replace: “)”, “” | replace: “-”,‘’ %}
{% if x.size == 10 %} +1{{x}}
{% elsif x.size == 11 %} +{{x}}
{% elsif x.size == 12 %}{{x}}
{% endif %}

How this code works is it’ll remove all spaces, parentheses, and dashes and then it’ll add a +1 or + if needed. 

The liquid example above is for US area codes, but you can modify it for your country. For example, if you send to France, you’d change +1 to +33, for example. 

 

Once the create or update person action block is configured, then you can run the campaign to apply this update to everyone!

I hope this helps! 

 

View original
Did this topic help you find an answer to your question?

2 replies

  • Novice
  • 2 replies
  • Answer
  • April 24, 2023

Hey Rachel,

If you’re only sending SMS to a maximum of one country or area code, then yes it’s possible to transform a phone number attribute to E.164 format! 

To do so, you’ll create a campaign triggered by a segment which captures everyone who has the phone number attribute. Then in the workflow, you’ll have a create or update person block which updates their phone attribute. You’ll set the value of the attribute to liquid and use the following code:

{% assign x = customer.phone | replace:” “, “” | replace: “(”, “” | replace: “)”, “” | replace: “-”,‘’ %}
{% if x.size == 10 %} +1{{x}}
{% elsif x.size == 11 %} +{{x}}
{% elsif x.size == 12 %}{{x}}
{% endif %}

How this code works is it’ll remove all spaces, parentheses, and dashes and then it’ll add a +1 or + if needed. 

The liquid example above is for US area codes, but you can modify it for your country. For example, if you send to France, you’d change +1 to +33, for example. 

 

Once the create or update person action block is configured, then you can run the campaign to apply this update to everyone!

I hope this helps! 

 


joechen
  • Novice
  • 3 replies
  • July 10, 2024

Note: There’s a small error in the liquid above, here is the fixed liquid:

{% assign x = customer.phone | replace: " ", "" | replace: "(", "" | replace: ")", "" | replace: "-", "" %}
{% if x.size == 10 %} +1{{ x }}
{% elsif x.size == 11 %} +{{ x }}
{% elsif x.size == 12 %} {{ x }}
{% endif %}

 

Also, regarding customer.phone, phone is the name of the attribute; so if your attribute is named phone_number, then use customer.phone_number instead. 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings