cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Musicians, convert your MuseScore files to PDF to play music on the go! Learn more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: Error in search... options: expected array, got string

Error in search... options: expected array, got string

toki4004
Helpful | Level 5
Go to solution

I am trying to use search to find any file with txt extension inside a particular path. I get the error: "Error in call to API function "files/search_v2": options: expected array, got string".  What am I doing wrong here:

 

 

 

    $options = array(
        "filename_only" => true,
		"max_results" => 1,
		"file_status" => "active",
		"path" => "/some/folder/folder",
		"file_extensions" => "txt"
    );

    $params = array(
        "options" => $options,
        "query" => "txt",
    );

    $headers = array(
        'Authorization: Bearer ' . $auth_token,
        'Content-Type: application/json'
    );

    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $params ) );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
    curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
    curl_setopt( $ch, CURLOPT_URL, 'https://api.dropboxapi.com/2/files/search_v2' );

 

 

 

 

1 Accepted Solution

Accepted Solutions

Здравко
Legendary | Level 20
Go to solution

Yes, let's think a bit: you have parameter name "file_extensions" 😉 (plural, not singular)! Here a list of extensions is expected, so even when there is single extension, this extension has to be an only entry in a list and not raw string (as noted in the error message too).

View solution in original post

2 Replies 2

toki4004
Helpful | Level 5
Go to solution

I tried wrapping options in another array - still get: "options: expected object, got array"

  $options = array(
		array(
			...
		)
	);

 

Здравко
Legendary | Level 20
Go to solution

Yes, let's think a bit: you have parameter name "file_extensions" 😉 (plural, not singular)! Here a list of extensions is expected, so even when there is single extension, this extension has to be an only entry in a list and not raw string (as noted in the error message too).

Need more support?