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  - https://www.campaignmonitor.com/api/subscribers/ doesn't mention the Basic Auth

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

String baseURL = "https://api.createsend.com/api/v3.1/subscribers/" + Constants.CAMPAIGN_MANAGER_LIST_ID + ".json";

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

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

            JsonObjectRequest request = new JsonObjectRequest(
                    baseURL,
                    jsonObject,
                    createMyReqSuccessListener(),
                    createMyReqErrorListener()) {

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

                    Map<String, String> headers = super.getHeaders();
                    Map<String, String> headerMap = new HashMap<String, String>();
                    headerMap.putAll(headers);
                    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;
                }
            };
            mRequestQueue.add(request);

        } 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: https://github.com/campaignmonitor/createsend-java

Let me know if you have any further questions!

Cheers,
Terry Tice


Terry Tice
Campaign Monitor

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