I use the method to edit ads .

In response, I get this error:

["error_code"]=>100 ["error_msg"]=>"One of the parameters specified was missing or invalid: data[data][ad_id] is invalid" 

The data array itself:

 string(185) "{"data":{"0":{"ad_id":"15142751","cpc":4.4},"1":{"ad_id":"15142643","cpc":4.4},"2":{"ad_id":"15210287","cpc":4.4},"3":{"ad_id":"15210280","cpc":4.4},"4":{"ad_id":"15210269","cpc":4.4}}}" 

ID ads are correct, most likely I am forming an array of objects.

  $data = json_encode(array('data' => $data), JSON_FORCE_OBJECT); 

Full answer with error:

  array(1) { ["error"]=> array(3) { ["error_code"]=> int(100) ["error_msg"]=> string(84) "One of the parameters specified was missing or invalid: data[data][ad_id] is invalid" ["request_params"]=> array(5) { [0]=> array(2) { ["key"]=> string(5) "oauth" ["value"]=> string(1) "1" } [1]=> array(2) { ["key"]=> string(6) "method" ["value"]=> string(13) "ads.updateAds" } [2]=> array(2) { ["key"]=> string(10) "account_id" ["value"]=> string(10) "xxxxxxxxxx" } [3]=> array(2) { ["key"]=> string(4) "data" ["value"]=> string(151) "{"data":[{"ad_id":22981362,"cpc":4.4},{"ad_id":22975854,"cpc":4.4},{"ad_id":22721708,"cpc":4.4},{"ad_id":26690417,"cpc":0},{"ad_id":22690359,"cpc":0}]}" } [4]=> array(2) { ["key"]=> string(1) "v" ["value"]=> string(4) "5.62" } } } } 

    1 answer 1

    1. account_idAdvertising account ID required parameter, int (number) And you do not.

    2. From the documentation: ad_id integer, required And you give the line.

    3. And for what use , JSON_FORCE_OBJECT ? The API wants an array of dataSerialized JSON array of objects that describe changes in ads .

    It looks like the API is waiting:

     // $data = json_encode(['data' => json_encode($data)]); { "data": '[{"ad_id": 123,"cpc":4.4},{"ad_id": 321,"cpc":7.7}]', "account_id" : 123 } 

    And you:

     { "data": { "1": {"ad_id": "123","cpc":4.4}, "2": {"ad_id": "321","cpc":7.7} } } 
    • to get an object, "JSON_FORCE_OBJECT - Выдавать объект вместо массива при использовании неассоциативного массива" - Hardc0re
    • @ Hardc0re Updated and supplemented the answer. - E_p
    • Rewrote, but the error still remained: string(151) "{"data":[{"ad_id":22981362,"cpc":4.4},{"ad_id":21975854,"cpc":4.4},{"ad_id":26721708,"cpc":4.4},{"ad_id":26790417,"cpc":0},{"ad_id":25690359,"cpc":0}]}" - Hardc0re
    • @ Hardc0re Where are the "account_id"? - E_p
    • one
      @Hardc0re Looks like a second try, I guessed it :). - E_p