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, 2 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

200,000 companies around the world can't be wrong.

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