API v8: getting account email addresses

Hi everyone!

I’m trying to get the email addresses associated with a specific Account, using the new JSON v8 API.
I can get my access token and use it to fetch the Account, now I’d like to get its email addresses too (I know that this particular account has two email addresses).

I’ve tried calling the
api/v8/modules/Accounts/{ACCOUNTID}/relationships/email_addresses
endpoint, here’s the data I’m receiving back:

[{'id': '1ee15ac7-18d3-96d7-035d-5b3f3c3dba94',
  'links': {'href': 'http://devcrm/api/v8/modules/Accounts/1ee15ac7-18d3-96d7-035d-5b3f3c3dba94'},
  'meta': {'middle_table': {'data': {'attributes': {'bean_id': 'a5ec312f-b1dc-d401-d3be-5b23b3058722',
                                                        'bean_module': 'Accounts',
                                                        'date_created': '2018-07-06 09:53:48',
                                                        'date_modified': '2018-07-06 09:53:48',
                                                        'deleted': '0',
                                                        'email_address_id': '1ee15ac7-18d3-96d7-035d-5b3f3c3dba94',
                                                        'id': '1ee15ac7-18d3-96d7-035d-5b3f3c3dba94',
                                                        'primary_address': '0',
                                                        'reply_to_address': '0'},
                                        'id': '',
                                        'type': 'Link'}}},
  'type': 'EmailAddresses'},
 {'id': '8f42881c-d788-9a69-15b3-5b3f3be9705f',
  'links': {'href': 'http://devcrm/api/v8/modules/Accounts/8f42881c-d788-9a69-15b3-5b3f3be9705f'},
  'meta': {'middle_table': {'data': {'attributes': {'bean_id': 'a5ec312f-b1dc-d401-d3be-5b23b3058722',
                                                        'bean_module': 'Accounts',
                                                        'date_created': '2018-07-06 09:49:13',
                                                        'date_modified': '2018-07-06 09:49:13',
                                                        'deleted': '0',
                                                        'email_address_id': '8f42881c-d788-9a69-15b3-5b3f3be9705f',
                                                        'id': '8f42881c-d788-9a69-15b3-5b3f3be9705f',
                                                        'primary_address': '0',
                                                        'reply_to_address': '0'},
                                        'id': '',
                                        'type': 'Link'}}},
  'type': 'EmailAddresses'}]

As you can see, there are two “branches”, one for each email address, but the REAL addresses (x@y.com) are nowhere to be seen, only the "email_address_id"s. Is this normal? Should I use the "email_address_id"s to make another call to the server? I’m not sure how I should do that though.

Many thanks for your time!

Email addresses is a module, and the email fields are related fields. So I can understand what you’re seeing, and yes, you could do a second request to get the actual address from the email_addresses table.

The table you’re seeing in that API return seems to be email_address_bean_rel

See this page (not official yet, but you can preview it), scroll to the bottom to see a diagram.

https://schema–suitedocs.netlify.com/schema/tables/email_addr_bean_rel.html

But all of this comes from my knowledge of the database; I don’t know much about the API…

1 Like

Hi, thanks for your answer!
I see that the database has a “email_addresses” table that maps the “email_address_id” (mentioned by the API response) to the real email addresses, but I can’t figure out how to fetch it using the API :frowning: I’ve tried calling
api/v8/modules/EmailAddresses/1ee15ac7-18d3-96d7-035d-5b3f3c3dba94
but I received a ModuleNotFoundException

Have you tried this way of listing available modules?

https://docs.suitecrm.com/developer/api/version-8/json-api/#_list_available_modules

Yes I did try that, here’s the answer:


AM_ProjectTemplates
AOBH_BusinessHours
AOK_KnowledgeBase
AOK_Knowledge_Base_Categories
AOR_Reports
AOR_Scheduled_Reports
AOS_Contracts
AOS_Invoices
AOS_PDF_Templates
AOS_Product_Categories
AOS_Products
AOS_Quotes
AOW_WorkFlow
Accounts
Bugs
Calendar
Calls
Campaigns
Cases
Contacts
Documents
EmailTemplates
Emails
FP_Event_Locations
FP_events
Home
Leads
Meetings
Notes
Opportunities
Project
ProspectLists
Prospects
ResourceCalendar
SecurityGroups
Spots
Surveys
Tasks
jjwg_Address_Cache
jjwg_Areas
jjwg_Maps
jjwg_Markers

As you can see, no “EmailAddresses”

I double-checked and I think that list is buggy it’s getting values from a different list called “moduleL1ist”, instead of “beanList” (see include/modules.php).

So EmailAddresses should really be working. The API just calls the Beans, and that’s a valid Bean name…

Any way you can try variations like

Email_Addresses
EmailAddress
etc

I am a bit confused by what is going on here… :frowning:

Well I’m MORE confused than you, since today the call to the EmailAddresses module IS working blush
Maybe I was doing something wrong… Many thanks for your assistance :slight_smile:
BTW, what’s the recommended way to propose a fix for the “list available modules” issue? GitHub?

Cool, I’m glad you got it working!

Yes, you can propose fixes on Github. However, there’s a big PR with a refactored v8 API waiting to be merged, so I would wait for that, or have a look at that PR:

https://github.com/salesagility/SuiteCRM/pull/5806

and comment there if you think it still needs that fix.

1 Like

Hi im trying to do a similar thing my call is /api/v8/modules/EmailAddresses/814979d4-06a5-4b0c-9361-5b717388bd51 but i get the following error in response.

"errors": [
        {
            "id": "1",
            "links": {
                "about": null
            },
            "status": 500,
            "code": 8025,
            "title": "JSON API Error",
            "detail": "Api Version: 8",
            "source": {
                "pointer": null,
                "parameter": null
            },
            "meta": {
                "about": "Exception",
                "class": "SuiteCRM\\API\\v8\\Exception\\ApiException",
                "code": 8025,
                "langMessage": null
            }
        },

Does your call to EmailAddresses still work?

Yes it’s still working… Have you tried checking suitecrm.log? Maybe increasing the log level from the administration panel?

1 Like

Thank you fanton.ff raising the log level has highlighted what I believe to be the issue retrieving the email addresses as it’s throwing a FATAL on converting the datetime field using SugarBean. here is the full error;

[FATAL] [SuiteCRM] [API] [Unable to convert datetime field using SugarBean] “confirm_opt_in_date”

Do you have any thoughts on how I fix this?

If I go to the database email_addresses table and fill out all the date fields it retrieves the email address no problem however as soon as one is null I have the error.

It’s good that we have found what is causing the issue but I think this is one will need resolving in the API code.

I suggest you open an issue with that precise information in Github, it will be useful to fix the issue.

I had the same problem and opened an issue a while ago: https://github.com/salesagility/SuiteCRM/issues/6148