Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

New Post: Formatting a POST request to create a new Dropbox folder.

$
0
0
To create an empty folder, without any files, I would suggest using the "/fileops/create_folder" URL

The error code "Bad Request" in the response implies that the one of the input parameters sent is incorrect.
As per the dropbox documentation, the root and path parameter-value pairs are to be passed as query parameters in the HTTP URL, not in the request body.

Did you look at the URL that is being passed to C++Rest http_client, i.e what is the value of "sb" here: http_client client(sb);?
If it is something like this: "https://api.dropbox.com/1/fileops/create_folder?oauth_consumer_key=key1&oauth_nonce=nounce1&oauth_timestamp=1384815906&oauth_version=1.0&oauth_signature_method=PLAINTEXT&oauth_signature=signature1&oauth_token=token1",
you can clearly notice that the root and path query params are not present here.

Next step would be to add these query parameters to the URL being constructed. You can use the uri_builder::append_query() API to add these parameters to the URI.
The below code will create a folder named "newfolder" under the "dropbox" root:
    uri url(L"https://api.dropbox.com/1/fileops/create_folder");
    std::shared_ptr<OAuth> oAuthObj = std::make_shared<OAuth>();    
    auto signatureParams = 
        oAuthObj->CreateOAuthSignedParameters(url.to_string(),
        L"POST",
        NULL,
        consumerKey,
        consumerSecret,
        creds->Token(),
        creds->TokenSecret()
        );  

    std::wstring sb = oAuthObj->OAuthBuildSignedHeaders(url);  // NOTE: sb does not contain the root and path parameter values YET!!!! 

    uri_builder ub(sb);
    ub.append_query(L"root", L"dropbox");  
    ub.append_query(L"path", L"newfolder");
    sb = ub.to_string();

    http_request req;           
    http_client client(sb);     
    req.set_method(methods::POST);          
    return client.request(req)
        .then([](pplx::task<http_response> previousTask)
    { // Handle the response, look at the status code etc.
    }
The code sample provided at "Bringing RESTful Services to C++ Developers" is an illustration on how one can interact with dropbox REST service using the C++ REST SDK. It may not cover all the cases, hence I recommend understanding and debugging the sample to ensure that the correct values are being set and passed to the http_client.

Thanks
Kavya.

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>