Android Subscriber API Issues

Does anyone have any advice for subscribing via Android/ JAVA... at the moment I'm using Volley for the JSon request...

Been playing with this for a while now  - doesn't mention the Basic Auth

I keep getting Response Code 400 Errors with no body message...

String baseURL = "" + Constants.CAMPAIGN_MANAGER_LIST_ID + ".json";

        try {
            RequestQueue mRequestQueue = Volley.newRequestQueue(getActivity().getApplicationContext());

            JSONObject jsonObject = new JSONObject();
            jsonObject.put("EmailAddress", "");
            jsonObject.put("Name", "New Subscriber");
            jsonObject.put("Resubscribe", true);
            jsonObject.put("RestartSubscriptionBasedAutoresponders", true);

            JsonObjectRequest request = new JsonObjectRequest(
                    createMyReqErrorListener()) {

                public Map<String, String> getHeaders() throws AuthFailureError {

                    Map<String, String> headers = super.getHeaders();
                    Map<String, String> headerMap = new HashMap<String, String>();
                    String credentials = Constants.CAMPAIGN_MANAGER_API + ":" + Constants.CAMPAIGN_MANAGER_API;
                    String base64EncodedCredentials = Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
                    headerMap.put("Authorization", "Basic " + base64EncodedCredentials);
                    return headerMap;

        } catch (JSONException e) {
            Log.e("JSONException", e.toString());

big thanks for any help/ advice given

terryt terryt, 3 years ago

Hi Nick,

I'm not overly familiar with the tool you are using. The logs suggest that the email address is invalid:

{"Code":1,"Message":"Please provide a valid email address."}

I'm not sure what to suggest with your code, but have you considered using our Java API wrapper? You can find it here:

Let me know if you have any further questions!

Terry Tice

Terry Tice
Campaign Monitor

See why 200,000 companies worldwide love Campaign Monitor.

From Australia to Zimbabwe, and everywhere in between, companies count on Campaign Monitor for email campaigns that boost the bottom line.

Get started for free