Announcement

Collapse
No announcement yet.

API Call to Get Email Addresses on Specific Target List

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • API Call to Get Email Addresses on Specific Target List

    Hi guys, EspoCRM is such a great piece of software that I hardly ever get to communicate with you guys unless I'm stuck but that's what I am today. Maybe I'm just missing something obvious.


    I would like to make a GET request to the API to fetch email addresses on a specific target list and then add to it if the email doesn't exist. The "adding" bit can wait until I figured out the "getting" bit.


    If I call the API on entity "TargetList" I get the lists in my system, and can see the entryCount attributes, but how to get the actual email addresses programmatically? I would be calling the API from another application that will allow that client app to take action based on whether or not an email already exists on a specific target-list.

    Any ideas would be greatly appreciated as always.

  • #2

    Okay, I see in the network tab in Chrome dev tools the following query string, so I kind of answered my own question here.

    Code:
    primaryFilter=&select=salutationName%2CfirstName%2ClastName%2CmiddleName%2Cname%2Cstatus%2CemailAddressIsOptedOut%2CemailAddress%2CemailAddressData%2CcreatedAt&maxSize=50&offset=0&orderBy=createdAt&order=desc
    This will work, I suppose at first glance, but the above query string is a little hard to work with and I'd much rather use the API with a JSON query like what is well documented. But I have run into a snag with the espocrm-api-client.js code provided at the below link:

    https://docs.espocrm.com/development...ascript-nodejs


    My code snippet:
    Code:
    const client = new Client(
    '<MY URL>',
    '<MY API KEY>',
    );
    var params = {
        maxSize: 5,
        where: [
      {
        type: 'equals',
        attribute: 'type',
        value: 'Customer'
      }],
        select: 'id,name',
        };
        client.request('GET', 'Account', params)
        .then(
        (response) => {
        console.log(response);
       }
    )

    I am getting the following error:
    Code:
    Uncaught (in promise) TypeError:
    The "listener" argument must be of type Function. Received type object

    EDIT: I should mention that this is from a React component if that is helpful to know. The above code is taken from the example in the docs and not related to my initial query.
    Last edited by boognish; 05-12-2021, 07:15 AM.

    Comment

    Working...
    X