1
Solved

Problem with empty body in HTTP Request

I think I found a bug. I tried to get information about my Dropbox account: (documentation)

Task: Get Dropbox Space Usage

A1: HTTP Request [
     Method: POST
     URL: https://api.dropboxapi.com/2/users/get_current_account
     Headers: Authorization:Bearer %token
     Content-Type: application/json
     Timeout (Seconds): 30
     Trust Any Certificate: On
     Automatically Follow Redirects: On
     Structure Output (JSON, etc): On
     Continue Task After Error:On ]

A2: Flash [
     Text: %http_data
     Long: On
     Continue Task Immediately: On
     Dismiss On Click: On ]

%token, of course is set in task's settings. But I got an error:

18.25.12/E add wait type EasyAction2 time 2147483647
18.25.12/E add wait type EasyAction2 done
18.25.12/E add wait task
18.25.12/E Error: 1
18.25.12/E Error in call to API function "users/get_current_account": request body: could not decode input as JSON

So I put brackets {} in body, and got another error:

18.26.11/E add wait type EasyAction1 time 2147483647
18.26.11/E add wait type EasyAction1 done
18.26.11/E add wait task
18.26.11/E Error: 1
18.26.11/E Error in call to API function "users/get_current_account": request body: expected null, got value

How to deal with it?

1 reply

I think the problem is that you're setting 

Content-Type: application/json

when the API doesn't expect a body at all.

Can you try removing that header?

A

I tried to leave

Authorization:Bearer %token

in Headers only. Unfortunately, without success. 

13.32.46/E add wait type EasyAction1 time 2147483647
13.32.46/E add wait type EasyAction1 done
13.32.46/E add wait task
13.32.47/E Error: 1
13.32.47/E Error in call to API function "users/get_current_account": Bad HTTP "Content-Type" header: "application/x-www-form-urlencoded". Expecting one of "application/json", "application/json; charset=utf-8", "text/plain; charset=dropbox-cors-hack".

Could you try setting it to "text/plain; charset=dropbox-cors-hack" then?

A
Screenshot of action's settings

15.21.58/E add wait type EasyAction1 time 2147483647
15.21.58/E add wait type EasyAction1 done
15.21.58/E add wait task
15.21.59/E Error: 1
15.21.59/E Error in call to API function "users/get_current_account": request body: could not decode input as JSON

Weird! What about just "text/plain;"? Maybe try to get in touch with the Dropbox people to see what exactly they're expecting?

A

With PHP works like a charm:

<?php
include("CurlRequest.php");
$url = "https://api.dropboxapi.com/2/users/get_space_usage";
$headers = ["Authorization: Bearer <token>"];
$curl = new CurlRequest(['url' => $url, 'headers' => $headers, 'method' => "POST"]);
$content = $curl->get();
$obj = json_decode($content, true);
var_dump($obj); // array(2) {["used"]=> int(12761476) ["allocation"]=> array(2) { [".tag"]=> string(10) "individual" ["allocated"]=> int(2147483648) } }

This is a class I using for: https://github.com/azekt/PHP/blob/main/CurlRequest.php

Ok, got it, you have to send an empty Content-Type for it to work :P

So, add a line like

Content-Type:

to your headers and it should work!

A

I don't why, but... it works!!! Thank you!!!

Great! 😁 It's weird that the API would explicetly only allow an empty Content-Type...I haven't seen another API that did that 😅 Glad it works!

Topic is closed for comments