3

i was trying to create customer in magento via SOAP API (customerCustomerCreate (SOAP V2)) in android app , but i get this error :

SoapFault - faultcode: '100' faultstring: 'Customer email is required' faultactor: 'null' detail: null

i set email address with this code :

    request = new SoapObject(NAMESPACE, "customerCustomerCreate");
    request.addProperty("sessionId", sessionId);

    SoapObject value = new SoapObject(NAMESPACE, "associativeEntity");
    value.addProperty("key", "in");
    value.addProperty("value", "[email protected]");

    SoapObject complexFilter = new SoapObject(NAMESPACE,
            "complexFilter");
    complexFilter.addProperty("key", "email");
    complexFilter.addProperty("value", value);
                SoapObject filterArray = new SoapObject(NAMESPACE,
            "complexFilterArray");
    filterArray.addProperty("item", complexFilter);

    SoapObject filters = new SoapObject(NAMESPACE, "filters");
    filters.addProperty("complex_filter", filterArray);

    request.addProperty("filters", filters);

    env.setOutputSoapObject(request);

    androidHttpTransport.call("", env);
    result = env.getResponse();

Does anyone have any idea what is the wrong I am doing here?

5 Answers 5

1

Magento has its own soap connection. By using this connection you can new create customer. see this "http://www.magentocommerce.com/api/soap/customer/customer.create.html".Here details have been described.

3
  • : i saw this link and i can create customer with PHP code but my problem is with java in android ! i try to create customer with android application in magento store and i get this erroe : "SoapFault - faultcode: '100' faultstring: 'Customer email is required' faultactor: 'null' detail: null"
    – mahdi
    Commented Jan 8, 2014 at 8:16
  • I think that means that the customer email is required :-/
    – philwinkle
    Commented Jan 8, 2014 at 17:04
  • @philwinkle i kno that mean , but if you look my code i set email as property
    – mahdi
    Commented Jan 8, 2014 at 18:53
1

Hey I work with this type of functionality.

1) Send the request URL from your android or iPhone devices with the POST OR GET METHOD in json format like simple url www.domain.com/createnewuser.php fie.

2) In php file must reside in the mangento installation folder.

3) in this file you can easily fetch data in passed by GET OR POST Method and decoede that data.

4) refer the soap api and create the object of SOAP and simple call the method i

<?php
$client = new SoapClient('http://magentohost/api/v2_soap/?wsdl');

// If some stuff requires api authentification,
// then get a session token
$session = $client->login('apiUser', 'apiKey');
$result = $client->customerCustomerCreate($session, array('email' => 'customer-  [email protected]', 'firstname' => 'Dough', 'lastname' => 'Deeks', 'password' => 'password', 'website_id' => 1, 'store_id' => 1, 'group_id' => 1));

var_dump ($result);
?>

5) This method return the new generated customer id try to put in try catch block so you can handle errors and if he generate errors then you can manage with SOAP FOULT.

6) If you not got any error then return the response as a customer id and you can easily managed in the android.

1

Use this method ... i am going with it and its working fantastic for me and i also use it for update also...

public class MainActivity extends Activity implements OnClickListener
{
    Button click;
    HttpTransportSE androidHttpTransport;
    SoapObject request ;
    SoapSerializationEnvelope env = new SoapSerializationEnvelope(SoapEnvelope.VER11);
   ArrayList<HashMap<String, String>> arrayList = new ArrayList<HashMap<String, String>>();
    private static final String NAMESPACE = "urn:Magento";
    // private static final String URL =
    // "website/api/v2_soap/?wsdl";
    private static final String URL = "website/index.php/api/v2_soap/index/";
    private static final String SOAP_ACTION = "urn:Mage_Api_Model_Server_V2_HandlerAction";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
            .permitAll().build();
        StrictMode.setThreadPolicy(policy);


        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        click=(Button)findViewById(R.id.button1);
        click.setOnClickListener(this);

    }

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public void onClick(View v) {
    String email = "[email protected]";
    String firstname= "name";
    String lastname= "surname";
    String password= "password";
    CreateNewCustomer(email, firstname, lastname, password);

}

public void CreateNewCustomer(String email, String firstname, String lastname, String password) {


    try {
        env.dotNet = false;
        env.xsd = SoapSerializationEnvelope.XSD;
        env.enc = SoapSerializationEnvelope.ENC;
        request = new SoapObject(NAMESPACE, "login");
        request.addProperty("username", "abcd");
        request.addProperty("apiKey", "abcd");
        env.setOutputSoapObject(request);

       HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.call("", env);
        Object session = env.getResponse();
        String sessionId = session.toString();

        Log.d("sessionId", sessionId.toString()); 

        Log.d("Create "," Creating......");
        request = new SoapObject(NAMESPACE,"customerCustomerCreate");
        request.addProperty("sessionId", sessionId);
        request.addProperty("product", product_id);

        //-----use Kvm Serializable class to serialize the key value data-------

        CreateCustomerKVMserialize createcustomerkvm = new CreateCustomerKVMserialize();

        createcustomerkvm.Email = email;
        createcustomerkvm.Firstname = firstname;
        createcustomerkvm.Lastname = lastname;
        createcustomerkvm.Password = password;

        PropertyInfo pi = new PropertyInfo();
        pi.setName("customerData");
        pi.setValue(createcustomerkvm);
        pi.setType(createcustomerkvm.getClass());
        request.addProperty(pi);

        env.setOutputSoapObject(request);
        env.addMapping(NAMESPACE, "customerData",new CreateCustomerKVMserialize().getClass());

        androidHttpTransport.call("", env);
        Object customer_create = env.getResponse();
        Log.d("mainactivity "," "+customer_create.toString());


    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
}

create class which implements KvmSerializable

public class CreateCustomerKVMserialize implements KvmSerializable{

public String Email;
public String Firstname;
public String Lastname;
public String Password;

public CreateCustomerKVMserialize(){}

public CreateCustomerKVMserialize(String email, String firstname, String lastname,String password) {

    Email = email;
    Firstname = firstname;
    Lastname = lastname;
    Password = password;
}

@Override
public Object getProperty(int arg0) {
    // TODO Auto-generated method stub
     switch(arg0)
        {
        case 0:
            return Email;
        case 1:
            return Firstname;
        case 2:
            return Lastname;
        case 3:
            return Password;    

        }

        return null;

}

@Override
public int getPropertyCount() {
    // TODO Auto-generated method stub
    return 4;
}

@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
    // TODO Auto-generated method stub

     switch(index)
        {
        case 0:
            info.type = PropertyInfo.STRING_CLASS;
            info.name = "email";
            break;
        case 1:
            info.type = PropertyInfo.STRING_CLASS;
            info.name = "firstname";
            break;
        case 2:
             info.type = PropertyInfo.STRING_CLASS;
             info.name = "lastname";
            break;
        case 3:
             info.type = PropertyInfo.STRING_CLASS;
             info.name = "password";
            break;
        default:break;
        }
}

@Override
public void setProperty(int index, Object value) {
    // TODO Auto-generated method stub

    switch(index)
    {
    case 0:
        Email = value.toString();
        break;
    case 1:
        Firstname = value.toString();
        break;
    case 2:
        Lastname = value.toString();
        break;
    case 3:
        Password = value.toString();
        break;

    default:
        break;
    }
}
}

and i am using soap version 2 and if u want to download lib. then click here

0

yo have to use latest SOAP version.

ksoap2-android-assembly-2.5.8-jar-with-dependencies

you can download it from this linkksoap2-android-assembly-2.5.8-jar-with-dependencies

3
  • i use 3.3.0 version.
    – mahdi
    Commented Aug 7, 2014 at 6:14
  • is it work or not..? Commented Aug 7, 2014 at 6:53
  • unfortunately not !
    – mahdi
    Commented Aug 8, 2014 at 9:33
0

For anybody who are still facing problem, try below code,

request = new SoapObject(NAMESPACE, "customerCustomerCreate");
    request.addProperty("sessionId", sessionId);

 SoapObject customerEntity = new SoapObject(NAMESPACE, "customerCustomerEntityToCreate");


customerEntity.addProperty("email", "[email protected]");
customerEntity.addProperty("firstname", "Code");
customerEntity.addProperty("lastname", "Code");

request.addProperty("customerData", customerEntity);


env.setOutputSoapObject(request);

    androidHttpTransport.call("", env);
    result = env.getResponse();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.