java.util.ArrayList out of START_OBJECT token /Creat Dev App

Not applicable

I am trying to create an associate an app for an existing developer by using post. It should be correct because the idea is the same. I am using the wordpress wp_remote_post() function. I am getting this error: !!! java.util.ArrayList out of START_OBJECT token!! I gues the reason is that I am not giving the data in the correct format. Could you have a look? Thank you.

$post_url ='www.xxx.xxx';
$arg_data = array("name" => "trial", "apiProducts" => array ( "myfistproduct"), "keyExpiresIn" => "", "attributes" => array( "name" => "amazingapp","value" => "My Awesome App"), array("name" => "Notes", "value" => "notes_for_developer_app"), array("name" => "custom_attribute_name","value" => "custom_attribute_value"), "scopes" => array (0 => '')); $data = json_encode( $arg_data ); $args = array('headers'=> array('Content-Type'=>'application/json', 'Authorization' => 'Basic dmFuaW5hLnlvcmRhbm92YUBsaWdodGluZy5jb206aTwzYXBp'),'body'=> $data ); $response = wp_remote_post( esc_url_raw( $post_url ), $args ); $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response );
Solved Solved
0 2 22.7K
1 ACCEPTED SOLUTION

Hi, @Vanina Yordanova,

Yes, the JSON string that is generated by $args_data is wrong.

Change your attribute array to like below:

    $arg_data = array("name" => "trial",
			"apiProducts" => array ( "myfistproduct"),
			"keyExpiresIn" => "",
			"attributes" => array(
			    array( "name" => "amazingapp","value" => "My Awesome App"),
			    array("name" => "Notes", "value" => "notes_for_developer_app"),
			    array("name" => "custom_attribute_name","value" => "custom_attribute_value")
			    ),
"scopes" => array (0 => 'READ'));


$data = json_encode( $arg_data );


echo $data;

This should work.

- Cheers!

View solution in original post

2 REPLIES 2

Hi, @Vanina Yordanova,

Yes, the JSON string that is generated by $args_data is wrong.

Change your attribute array to like below:

    $arg_data = array("name" => "trial",
			"apiProducts" => array ( "myfistproduct"),
			"keyExpiresIn" => "",
			"attributes" => array(
			    array( "name" => "amazingapp","value" => "My Awesome App"),
			    array("name" => "Notes", "value" => "notes_for_developer_app"),
			    array("name" => "custom_attribute_name","value" => "custom_attribute_value")
			    ),
"scopes" => array (0 => 'READ'));


$data = json_encode( $arg_data );


echo $data;

This should work.

- Cheers!

Thahk you:) It works!