API v1 Reference

Java – Create Individual Account
Not Supported

Code Not Supported

Unfortunately, due to changing priorities, we are no longer able to support the code provided here. However, we are leaving these pages public for historical reference and the benefit of our developer community.


package com.z2systems.cxfclient.samples.account;

import com.z2systems.schemas.account.*;
import com.z2systems.schemas.common.*;
import com.z2systems.schemas.neonws.AccountService;
import com.z2systems.schemas.neonws.Neonws;
import org.junit.Test;

import javax.xml.namespace.QName;
import java.net.MalformedURLException;
import java.net.URL;

public class CreateIndividualAccount {

    private static final QName SERVICE_NAME = new QName("http://www.z2systems.com/schemas/neonws/", "Neonws");


    @Test
    public void createIndividualAccountTest() {
        URL wsdlURL = null;
        try {
            wsdlURL = new URL("https://api.neoncrm.com/neonws/services/AccountService?wsdl");

        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        Neonws ss = new Neonws(wsdlURL, SERVICE_NAME);
        AccountService port = ss.getAccountPort();

        CreateIndividualAccountRequest request = new CreateIndividualAccountRequest();
        IndividualAccount individualAccount = new IndividualAccount();

        //construct Primary contact. "John Doe"
        Contact contact = new Contact();
        contact.setFirstName("John");
        contact.setLastName("Doe");
        contact.setPrefix("Mr."); // available prefixes can be retrieved from common/listPrefixes

        CodeNamePair gender = new CodeNamePair(); //available genders can be retrieved from account/listGenders
        gender.setCode("M");
        contact.setGender(gender);

        // add address for "John Doe"
        Address address = new Address();
        address.setIsPrimaryAddress(Boolean.TRUE);
        address.setIsShippingAddress(Boolean.FALSE);

        IdNamePair addressType = new IdNamePair();
        addressType.setName("Home");
        address.setAddressType(addressType);

        address.setAddressLine1("unit 3, 26 Hercules Street");
        address.setCity("Chicago");

        //state code name pair can be retrieved by account/listStates
        CodeNamePair state = new CodeNamePair();
        state.setCode("IL");
        address.setState(state);

        //country id name pair can be retrieved by account/listCountries
        IdNamePair country = new IdNamePair();
        country.setId("1");
        address.setCountry(country);

        address.setZipCode("60601");

        AddressList addressList = new AddressList();
        addressList.getAddress().add(address);
        contact.setAddresses(addressList);
        individualAccount.setPrimaryContact(contact);

        //construct custom field data. field id & optionIds can be retrieved from common/listCustomFields
        CustomFieldDataList customFieldDataList = new CustomFieldDataList();
        CustomFieldData customFieldData = new CustomFieldData();
        customFieldData.setFieldId("53");
        customFieldData.setFieldOptionId("16");
        customFieldDataList.getCustomFieldData().add(customFieldData);
        individualAccount.setCustomFieldDataList(customFieldDataList);

        //choose individual types, individualTypes can be retrieved from account/listIndividualTypes
        IndividualTypeList individualTypeList = new IndividualTypeList();
        IdNamePair type1 = new IdNamePair();
        type1.setId("6");
        IdNamePair type2 = new IdNamePair();
        type2.setId("5");
        individualTypeList.getIndividualType().add(type1);
        individualTypeList.getIndividualType().add(type2);
        individualAccount.setIndividualTypes(individualTypeList);

        request.setIndividualAccount(individualAccount);
        request.setUserSessionId("T1357615747419"); //user session Id retrieved from login
        CreateIndividualAccountResponse response = port.createIndividualAccount(request);

        if (response != null) {

            System.out.println(response.getOperationResult().toString());

            if (OperationResult.SUCCESS.equals(response.getOperationResult())) {
                System.out.println(response.getAccountId());
            } else {
                System.out.println(response.getErrors());
            }
        }
    }
}