Edit Account API

The Edit Account API lets you edit the logged in account holder's information in your Twig templates.

Learn more about APIs.

Important - This only updates the logged in account holder. If no one is logged in as a public account then nothing will be updated.

API Call to edit the account

{% do _api.account.editAccount.data({'key': 'value'}) %}

To edit an account you call the "editAccount" method and use the "data" parameter to pass the account data to update. In the "data" parameter you pass an array where each key is an account attribute template key and the value is the new value for that attribute.

For example, if you wanted to update the first and last name for the account you could do this:

{% do _api.account.editAccount.data({'firstName': 'Bob', 'lastName': 'Hope'}) %}

Return Data

The API call will return an array to indicate whether or not the call was successful or not. To use it you can simply set a variable to the API result.

{% set apiResult = _api.account.editAccount.data({'firstName': 'Bob', 'lastName': 'Hope'}) %}
{% if apiResult.status == 'ok' %}
    <p>Yea! The account updated.</p>
{% else %}
    <p>Oh no! There was an issue updating the account.<br>{{ apiResult.message }}</p>
{% endif %}
Result value Description
message

A message to explain the result status. There are three possible messages.

Success message meaning that the account was successfully updated:

  • Account was successfully updated

Error messages:

  1. Account data needs to be an array of data (This means that you didn't submit the data as an array. The data needs to be submitted as name => value pairs in an array.)
  2. Account is not logged in so nothing could be updated (The person browsing the site isn't logged into an account so nothing could be updated.)
status

This holds whether or not the account was successfully updated. Possible values are:

  • ok
  • error

"ok" means the account was updated successfully.

"error" means that the account was not updated. Check the "message" value in the result to see why.

Editing core attributes

All apps have core or default attributes. You can also add custom attributes. Below are the array keys that you should use to edit core attributes.

  • company
  • department
  • email
  • firstName
  • gender
  • middleName
  • lastName
  • namePrefix
  • nameSuffix
  • password
  • phoneHome
  • phoneOffice
  • phoneMobile
  • phoneOther
  • phoneTollFree
  • profileImage
  • title
  • username
  • website

Editing custom attributes

To edit a custom attribute you would use it's template key as the array key.

For example, if your custom attribute was called "Favorite color" and it's template key is "favoriteColor", then you can edit it like this:

{% do _api.account.editAccount({
    'favoriteColor': 'green'
})

Saving an array of data as a JSON string

There may be a case where you need to save a JSON string, but you're building the value as an array. You can simply use the json filter to convert the data to a JSON string.

For example, lets have an example where you are saving the favorite colors for someone. The attribute is a "Paragraph Text" attribute and you're wanting to save the value as a JSON string. The data will be the color name and its HEX value. In this example we'll start with some data, and then add to, and finally save it.

Note, the "favoriteColors" information below may look like JSON data, but in reality, Twig considers it an array. JSON would be a string, the favoriteColors data below is an array.

{# Set some default colors. Note that "favoriteColors" is an array. #}
{% set saveData = {
    'favoriteColors': {
       'blue': '#00FFFF',
       'green': '00A36C'
    }
} %}

{# Add another color #}
{% set saveData.favoriteColors.purple = '#5D3FD3' %}

{# Add an email address update too #}
{% set saveData.email = 'newemail@me.com' %}

{# Convert the array of color data to a JSON string #}
{% set saveData.favoriteColors = saveData.favoriteColors|json %}

{# Save the account data #}
{% set result = _api.account.editAccount.data(saveData) %}
{% if result.status == 'ok' %}
    <p>Favorite colors and email were updated!</p>
{% else %}
    <p>There was an issue updating the account: {{ result.message }}</p>
{% endif %}