I am trying to use the Dropbox API get_latest_cursor
and the documentation-explorer states.
For curl I would use the following:
POST /2/files/list_folder/get_latest_cursor
Host: https://api.dropboxapi.com
User-Agent: api-explorer-client
Authorization: Bearer oDNxxxxxxxxxxxxxxxxxxxxxxxxxxetc
Content-Type: application/json
{
"path": "/Apps/Manchester"
}
My code, as I am working in .NET not curl, is:
public ActionResult GetCursor()
{
string accessToken = "oDNxxxxxxxxxxxxxxxxxxxxxxxxxxetc";
var request = (HttpWebRequest)WebRequest.Create("https://api.dropboxapi.com/2/files/get_latest_cursor");
request.Method = "Post";
request.Headers.Add("Authorization", "Bearer " + accessToken);
request.ContentType = "application/json";
//Build the data content
ASCIIEncoding encoding = new ASCIIEncoding();
string stringData = "{\"path\":\"/Apps/Manchester\"}";
byte[] data = encoding.GetBytes(stringData);
request.ContentLength = data.Length;
Stream newStream = request.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
var response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
string responseString = sr.ReadToEnd();
ViewBag.Json = responseString;
return View();
}
I assume I have to add the JSON into the content body as I have done above.
I get the following error:
The remote server returned an error: (400) Bad Request
If I use the Dropbox API Explorer with the above path I get a cursor JSON value returned fine.
Can anyone point out the error of my ways please?
Server Error in '/SurveyDataManager' Application.
The remote server returned an error: (400) Bad Request.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote server returned an error: (400) Bad Request.
Source Error:
Line 61: newStream.Close();
Line 62:
Line 63: var _response = (HttpWebResponse)_request.GetResponse();
Line 64:
Line 65: StreamReader sr = new StreamReader(_response.GetResponseStream());
Source File: d:\Development\SurveyDataManager\SurveyDataManager\Controllers\DropboxAPIController.cs Line: 63
Stack Trace:
[WebException: The remote server returned an error: (400) Bad Request.]
System.Net.HttpWebRequest.GetResponse() +1740
SurveyDataManager.Controllers.DropboxAPIController.GetCursor() in d:\Development\SurveyDataManager\SurveyDataManager\Controllers\DropboxAPIController.cs:63
lambda_method(Closure , ControllerBase , Object[] ) +87
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +265
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35
System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +34
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +60
System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +77
System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +371
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +60
System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +32
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +185
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +53
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +24
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +22
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +68
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +22
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +53
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +39
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +53
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +399
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +137
_request
was a typo, and I know that the error happens on the typo line but it really is not the issue.
Dropbox says the problem is an "unknown API".
It is not files/get_latest_cursor
but list_folder/get_latest_cursor
.