cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: options: expected array, got string - but it is an array?

Error: options: expected array, got string - but it is an array?

James_T
Helpful | Level 6
Go to solution

I'm having trouble with an API call. It claims I send a string, but it seems to me to be an array.

This is the full error:

 

Error in call to API function "https://content.dropboxapi.com/2/files/search_v2": options: expected array, got string

 


This is what was sent to cURL:

 

method:"POST"
header:"Authorization: Bearer MYTOKEN
Content-Type: application/json
Content-Length: 86"
content:"{"query":"test","options":{"path":"","max_results":100,"file_categories":"folder"}}"
ignore_errors:true

 

 

 Anyone know what's wrong?

1 Accepted Solution

Accepted Solutions

James_T
Helpful | Level 6
Go to solution

Found the problem... the option file_categories needs to be an array as well.

View solution in original post

5 Replies 5

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

Hi @James_T,

Have you took a look on where parameters have to be put on? 🤔 Into header part of the HTTP query or into data part? 🧐 What are you doing actually? 🙂

Hope this tip gives right direction.

James_T
Helpful | Level 6
Go to solution

Hi,

I'm trying to do a search.  I use a PHP library to handle the cURL calls. It works fine for creating a folder for instance.

Since the error is specifically about "options" parameter, I assume the call is done correctly, if it wasn't I assume I would get an error about something else, or even a missing "query" parameter?

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

@James_T wrote:
.., I assume the call is done correctly, if it wasn't I assume I would get an error about something else, or even a missing "query" parameter?

Better, don't assume anything! 👆 I can't be certain, what actually you have done. Seems you have posted in OP your HTTP query. 🧐 Is this correct? If so, there are multiple errors! I'm guessing most of them are copy/paste errors when you prepared the post.

To be sure, what we're talking about, post exact structure of your HTTP request/response and/or the code you are using (not something like, as is posted now). Better catch your HTTP request/response, so we would be sure exactly what's going on and what's the error. 😉

James_T
Helpful | Level 6
Go to solution

Below is my complete code. And here is the result:

 

Error in call to API function "files/search_v2": options: expected array, got string

 

 

$token = "....";
$options = array("path" => "/", "max_results" => 10);
$options["file_categories"] = "folder";
$parameters = array("query" => "searchPhrase", "options" => $options);

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

$curlOptions = array(
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => json_encode($parameters),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_VERBOSE => true,
    CURLOPT_SSL_VERIFYHOST => false,
    CURLOPT_SSL_VERIFYPEER => false
);

try {

    $ch = curl_init('https://api.dropboxapi.com/2/files/search_v2');
    curl_setopt_array($ch, $curlOptions);

    $response = curl_exec($ch);
    //var_dump($response);
    curl_close($ch);

} catch (Exception $e) {

    trigger_error(
        sprintf(
            'Curl failed with error #%d: %s',
            $e->getCode(),
            $e->getMessage()
        ),
        E_USER_ERROR
    );
}

 

 

Some more debugging:

echo json_encode($parameters, JSON_PRETTY_PRINT);

{
    "query": "cat",
    "options": {
        "path": "\/folder",
        "max_results": 10,
        "file_categories": "folder"
    }
}
Error in call to API function "files/search_v2": options: expected array, got string

That sure looks like an array to me, so I don't understand why it says it's a string...

James_T
Helpful | Level 6
Go to solution

Found the problem... the option file_categories needs to be an array as well.

Need more support?