How to send a proper post request to WHMCS installation from android app?

by Paul   Last Updated October 20, 2019 05:26 AM - source

I am trying to send an AddClient post request to my WHMCS installation through my android app but it keeps returning "result=error;message=You did not enter your first name".

I get it to authenticate successfully but it doesnt seem to be posting the jsonObject I am sending it.

Here is a link to WHMCS api documentation:

public void createWHMCSUser(final String emailID, final String random, final String uid) {

    final String AccessUserKey = "abc123";
    final String AccessKey = "abc123";
    Thread thread = new Thread(new Runnable() {
        public void run() {
            try {
                URL url = new URL("");
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestProperty("Content-Type", "application/json");

                JSONObject jsonParam = new JSONObject();
                jsonParam.put("action", "AddClient");
                jsonParam.put("identifier", AccessUserKey);
                jsonParam.put("secret", AccessKey);
                jsonParam.put("firstname", "User");
                jsonParam.put("lastname", "Name");
                jsonParam.put("email", emailID);
                jsonParam.put("address1", "na");
                jsonParam.put("city", "na");
                jsonParam.put("state", "na");
                jsonParam.put("postcode", "00000");
                jsonParam.put("country", "US");
                jsonParam.put("phonenumber", "0000000000");
                jsonParam.put("password2", random);
                jsonParam.put("repsonsetype", "json");

                Log.i("JSON", jsonParam.toString());
                DataOutputStream os = new DataOutputStream(conn.getOutputStream());
                os.writeBytes(URLEncoder.encode(jsonParam.toString(), "UTF-8"));


                Log.i("STATUS", String.valueOf(conn.getResponseCode()));
                Log.i("MSG", conn.getResponseMessage());

            } catch (Exception e) {




It should return "result=success".

But actually returns "result=error;message=You did not enter your first name".

Answers 1

It’s seems your API doesn’t work in this sample.

try Postman and if json doesn’t work there, issue is in your api.

alireza daryani
alireza daryani
October 20, 2019 05:22 AM

Related Questions

Swift: HTTP request with parameters in header

Updated March 28, 2018 12:26 PM

Flutter: http request with params

Updated September 03, 2018 11:26 AM

Can't get POST data in PHP from JAVA

Updated May 01, 2019 09:26 AM