Java API - createsend-java - authentication error 100: Invalid...

Hi,

I'm trying to light up your sample code and have run into a roadblock.  The only API call I've seen work is the call to get the API key when passed the user credentials.  All other calls give me:

com.createsend.util.exceptions.UnauthorisedException: The CreateSend API responded with the following authentication error 100: Invalid API Key

private static void runGeneralMethods() throws CreateSendException {
  General client = new General();

// Below updated with credentials I use to login to site  - It works and gives me back the API key I expect to see
  System.out.printf("Result of get apikey: %s\n",
            client.getAPIKey("Site URL", "Username", "Password"));

System.out.println("About to perform client.getCountries()");
client.getCountries();

It looks to me like for whatever reason I can't see the api key created in the createsend.properties.

createsend.apikey=deadbeefdeadbeefdeadbeef   <- with a good value - the same value I see when I login to the site in a browser and look at API Key, or perform the api call above...

So my questions are:

1) Is there a way to instantiate General or your other classes with an API Key passed as part of the constructor - or some other method that will give me a working instance?

2) If I can't do 1) Is there any way to do something like.
  General client = new General();
  client.setAPIKey("deadbeefdeadbeefdeadbeef");   

I looked for a setter but couldn't find any...

3) Any chance you could provide a setter for the classes that need a client id too - or if there's a way of doing the same as 2) but with client Id you could share it? 

3) Lower priority - Is there any chance you guys could upload a known good and working API to the maven repository?   That would make things easier...

I'm pretty much down to pulling your source and rebuilding from source...

Thanks in advance. 
Peter

mortena, 4 years ago

Strange to see no replies to this post. Did you make it work.

It seems that CampaignMonitor has released a sample code for java that doesn't work.

Strange. I thought they knew better than that ;-)

Please update us on this.

Ken Ken, 4 years ago

Hi guys,

Just letting you know we'll look into this and get back to you as soon as we can.

Ken


http://www.campaignmonitor.com
biviel, 4 years ago

Hi!

have you checked the issue and corrected? Planning to pay lot of money and to be able to connect your CM with our internal systems, but the actual situation with this is stopping us to move further and plannig leave CM.

Please respond immediately!

Thanks,
Regards,
GeneralElectric Lighting headquarters

Stig Stig, 4 years ago

Hey biviel, sorry about the lack of updates in this forum thread.

I believe the issues mentioned above have been resolved, but I'll double check with our developers so they can post an update here.

Also, if you're experiencing any particular problems with the Java API wrapper yourself, feel free to provide more details here or in an email to support.


The Campaign Monitor Blog – HTML email smarts to go with your good looks.
jamesd jamesd, 4 years ago

Hey all, I've just managed to get the Java library working from scratch very easily (I am not the author of this library). I did the following:

1. Downloaded the zip with the createsend jar file as well as all dependencies: https://github.com/downloads/campaignmo … encies.zip

2. Reference all the jar files included in the zip file from your project (I won't go into specifics of how to do that, I used Eclipse though).

3. I wrote a class as follows:

import java.util.Arrays;
import com.createsend.*;
import com.createsend.util.exceptions.*;

public class Main {
    public static void main(String[] args) throws CreateSendException {
        General client = new General();
        System.out.printf("Result of get clients: %s\n", Arrays.deepToString(client.getClients()));
        System.out.printf("Result of get countries: %s\n", Arrays.deepToString(client.getCountries()));
    }
}

4. And wrote a createsend.properties file as follows:

createsend.apikey = myapikey

5. Ran the project in Eclipse, and received the following output:

Result of get clients: [com.createsend.models.clients.ClientBasics@4054824, ...]
Result of get countries: [Afghanistan, Albania, Algeria, ...]

Are you sure you're reading the API key from the properties file?

I would debug and inspect the client object you're creating. You'll want to make sure that the client.authorisedResourceFactory.authFilter.authentication field is set correcty.

It should be something like: "Basic blahhexblahhex...=="

Hope that helps.

Cheers,
James

jamesd jamesd, 3 years ago

Just a note to let any followers of this thread know that the latest version of createsend-java (3.1.0) is now available in the Maven Central repository.

All future releases of createsend-java will be released to Maven Central too.

Hope that helps.

Join 200,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free
1-888-533-8098