Using the Java API, how do you set a clients API key? eg: the client logs into my (awesome!) system, and saves their CM API key in my system.
My system then retrieves the API key and uses it to connect to CM.
I've got this working with my login, BUT... I use the createsend.properties file to specify the API key. How do you do it programatically?
From the code:
API key seems to be set in the resourcefactory in the JerseyClientImpl on creation:
private ResourceFactory authorisedResourceFactory = new AuthorisedResourceFactory(Configuration.Current.getApiKey(), "x");
The Configuration.Current loads properties from the System.Classloader (not quite sure why, its pretty inconvenient in a JEE environment), and one of these properties files is the createsend.properties file.
So this is all loaded on creation of the jerseyClientImpl. The problem is, how do you programmatically set the clients API key here? There seems to be no ability to update the Configuration.current object, or access the authorisedResourceFactory object.
I'm guessing I'm being obtuse, but I have been through all the source trying to find a hook to let me programmatically set the clients API, but... no luck.
I have managed to work around this, by overriding the JerseyClientImpl with my own version. This client overrides all the methods that use the authorisedResourceFactory and points it to my own resourcefactory, which I can programmatically set an API key.
Its pretty hacky, but I can't see another way to do it. The java API could be ... more friendly!
Can you provide the example of how to create a List by overriding the JerseyClientImpl ?
I found out, here the example:
Lists listAPI = new Lists(listID,new JerseyClientImpl(clientAPIKey));
From Australia to Zimbabwe, and everywhere in between, companies count on Campaign Monitor for email campaigns that drive real business results.Get started for free