1
API call returning Object reference not set to an instance of an object, why?
Problem reported by YS Tech - 4/23/2023 at 4:51 AM
Submitted
I thought i'd followed the API documentation but I just keep getting this error:
Object reference not set to an instance of an object.
I'm authenticating ok as I'm getting this far.
Trying to add extra data to a member of a mailing list using:


Obviously I have values for the URL, subscriber email and mailing list id. But I still get the error.
Any idea why?

Data I'm trying to post:

{"emailAddress":wmail@domain.com,"fieldValues":[{"name":fullname,"value":Fred Bloggs}],"subscribedLists":[4]}

But I don't think it's getting that far.

Logs say:
[2023.04.24] 13:02:12.638 [MAILING LIST SERVICE] Object reference not set to an instance of an object.
[2023.04.24]    at MailService.WCF.MailingLists.MailingListsService.EditSubscriber(String token, String email, String domainName, Nullable`1 mailingListId, String subscriberEmail, MailingListSubscriberInput inputs) 

Do you have an example of a successful call to this API as there aren't really any examples with real data and what the data should look like?
Thanks

5 Replies

Reply to Thread
1
Andrew Barker Replied
Employee Post
The error you are encountering may be due to how your JSON data is formatted. In JSON, string values should be enclosed in quotes. Your data would then be formatted like:

{"emailAddress":"wmail@domain.com","fieldValues":[{"name":"fullname","value":"Fred Bloggs"}],"subscribedLists":[4]} 


Andrew Barker Software Developer SmarterTools Inc. (877) 357-6278 www.smartertools.com
1
YS Tech Replied
Thanks Andrew, I thought I'd originally had the double quotes but I obviously hadn't!
Now working many thanks.
0
YS Tech Replied
Another quick question hopefully, as you don't list how your data needs to be formatted.
Adding new subscribers, how is this formatted, you show:
[
    text
    ...
]
Does that mean for example:
[
    etc...
]

I've tried comma-separated, tab-separated, \r\n separated and none seem to work, I just get:
Must provide at least one email address

Sent

All give me: 
Must provide at least one email address

It would make things a lot easier if you gave us an idea of how the data should look with some example data?
Many thanks
0
Zach Sylvester Replied
Employee Post
Hello, 

Thanks for posting the question. I haven't tried adding more than one email at a time but if you add them one by one you can pass them in by doing {'data':test@gmail.com}
Here's an example function that I made. If you want to see more examples check out this. https://github.com/zjs81/SmarterToolsPythonWrapper/blob/main/api/smapi.py
def add_digest_subscribers(self, input_mailing_list_id, email):
        """
        Add digest subscribers to a mailing list.
        """
        url = f"{self.url}/api/v1/settings/domain/mailing-lists/{input_mailing_list_id}/digest-subscriber-add"
        data = {'data': email}
        headers = {'Authorization': f'Bearer {self.auth}'}
        response = requests.post(url, data=data, headers=headers)
        response.encoding = response.apparent_encoding
        return response.text
Thanks, 
Zach Sylvester System/Network Administrator SmarterTools Inc. (877) 357-6278 www.smartertools.com
0
YS Tech Replied
Hi Zach, thanks for the reply, i've managed to figure it out.

So for the AddSubscribers API call the data should be formatted like this:

["email1@domain.com","email2@domain.com","email3@domain.com"]

NOT
[
    text
    ...
]
As it says in the documentation!

So it accepts comma-separated and in quotes. The same format goes for RemoveSubscribers.
ST please show examples of the data that you accept, it would save us all a lot of time trying to guess it?

Reply to Thread