2016-02-26 81 views
0

我做了與woo commerce的所有連接,我的產品和所有東西都可以正確取出,但是當我創建一個客戶時,它會給我一個缺少參數數據的錯誤。如何在android應用程序中爲woo-commerce網站創建客戶?

aQuery = new AQuery(context); 

HashMap<String, String> stringStringHashMap = new HashMap<>(); 
String url = WooCommerceAuthentication.getUrl("POST&", "customers", stringStringHashMap); 

AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() { 

    @Override 
    public void callback(String url, JSONObject jsonObject, AjaxStatus status) { 
     System.out.println(jsonObject); 
    } 
}; 

String data = "{\n" + 
     "\t\"customer\": {\n" + 
     "\t\t\"email\": \"[email protected]\"}}"; 
JSONObject jsonObject = null; 
try { 
    jsonObject = new JSONObject(data); 
} catch (JSONException e) { 
    e.printStackTrace(); 
} 

cb.header("Accept", "application/json"); 
cb.header("Content-Type", "application/json"); 
cb.header("User-Agent", "WooCommerce API Client-PHP/2.0.1"); 

Map<String, Object> params = new HashMap<String, Object>(); 
params.put("method", "POST"); 
params.put("data", "[email protected]"); 

cb.params(params); 

aQuery.ajax(url, JSONObject.class, cb); 

回答

0

您提交的客戶信息不完整。根據文檔here,客戶字段應爲:

"customer": { 
    "email": "[email protected]", 
    "first_name": "John", 
    "last_name": "Doe", 
    "username": "john.doe", 
    "billing_address": { 
     "first_name": "John", 
     "last_name": "Doe", 
     "company": "", 
     "address_1": "969 Market", 
     "address_2": "", 
     "city": "San Francisco", 
     "state": "CA", 
     "postcode": "94103", 
     "country": "US", 
     "email": "[email protected]", 
     "phone": "(555) 555-5555" 
    }, 
    "shipping_address": { 
     "first_name": "John", 
     "last_name": "Doe", 
     "company": "", 
     "address_1": "969 Market", 
     "address_2": "", 
     "city": "San Francisco", 
     "state": "CA", 
     "postcode": "94103", 
     "country": "US" 
    } 
    } 
相關問題