Hi All, Has anyone here worked on an integration b...
# integrations
x
Hi All, Has anyone here worked on an integration between Netsuite and Dropbox? Running into a real pain of an error and I’ve exhausted my google abilities. Sending a https POST request to dropbox to get the current account info. According to what I found online you need to send a POST with a null body. But no matter what I keep getting this error: "Error in call to API function "users/get_current_account": request body: could not decode input as JSON" Here is my https request and headers:
Copy code
const getCurrentAccountHeader = {
                        "Content-Type": 'application/json',
                        "Authorization": 'Bearer ' + accessToken,
                        "Dropbox-API-Select-Admin": ADMIN_USER
                    };
                    var getCurrentAccountResponse = https.request({
                        method: <http://https.Method.POST|https.Method.POST>,
                        url:"<https://api.dropboxapi.com/2/users/get_current_account>",
                        headers: getCurrentAccountHeader,
                        body: "null"
                    });
I know for a fact my accessToken is correct. I successfully got member info. I’ve tried all variations in the body: null, “null”, {}, ‘{}’, JSON.stringify(null), JSON.stringify(‘null’) I tried removing the “Content-Type” and NetSuite gives me an unexpected error if I do that. Anyone have any experience with this? Ready to pull my hair out...
e
body: JSON.stringify({})
POST requires the body to be stringified
x
Tried that but still get a 400 error
body: "Error in call to API function "users/get_current_account": request body: expected null, got value"
b
its asking for nothing in the body, not the string "null"
x
I put it exactly as @Eric B said to and got the "request body: expected null, got value" error
Copy code
var getCurrentAccountResponse = https.request({
                        method: https.Method.POST,
          url:"<https://api.dropboxapi.com/2/users/get_current_account>",
                        headers: getCurrentAccountHeader,
                        body: JSON.stringify({})
                    });
b
whats the output of JSON.stringify({})
x
I don't have a way of seeing what dropbox is receiving. i believe they removed their app logging for the time being. but if i log debug before the request it is {} typeof is string
b
as in you want to log the output of JSON.stringify({}) on your side before you send it
and then ask yourself, is the output equivalent to null, which is what dropbox is expecting
if you dont know what null is, you want to look that up before starting
x
I initially tried
Copy code
const body = null;
const getCurrentAccountHeader = {
                        "Content-Type": 'application/json',
                        "Accept": 'application/json',
                        "Authorization": 'Bearer ' + accessToken,
                        "Dropbox-API-Select-Admin": ADMIN_USER
                    };
                    var getCurrentAccountResponse = https.request({
                        method: <http://https.Method.POST|https.Method.POST>,
                        url: "<https://api.dropboxapi.com/2/users/get_current_account>",
                        headers: getCurrentAccountHeader,
                        body: body
                    });
body outputs as But then I get "Error in call to API function "users/get_current_account": request body: could not decode input as JSON" Ok it needs JSON so I try this
Copy code
const body = JSON.stringify(null);
                    const getCurrentAccountHeader = {
                        "Content-Type": 'application/json',
                        "Accept": 'application/json',
                        "Authorization": 'Bearer ' + accessToken,
                        "Dropbox-API-Select-Admin": ADMIN_USER
                    };
                    var getCurrentAccountResponse = https.request({
                        method: <http://https.Method.POST|https.Method.POST>,
                        url: "<https://api.dropboxapi.com/2/users/get_current_account>",
                        headers: getCurrentAccountHeader,
                        body: body
                    });
Body is null
Copy code
"Error in call to API function "users/get_current_account": request body: could not decode input as JSON"
b
your first request has nothing for the request body, which is what dropbox expects for its api
you also added a content type
which tells dropbox to parase your body as json, which it will fail to do, giving you your error
the body of the second request is the string "null", which is not the same as the concept of null, which is what the api expects
x
Copy code
const getCurrentAccountHeader = {
                        "Authorization": 'Bearer ' + accessToken,
                        "Dropbox-API-Select-Admin": ADMIN_USER
                    };
                    var getCurrentAccountResponse = https.request({
                        method: <http://https.Method.POST|https.Method.POST>,
                        url: "<https://api.dropboxapi.com/2/users/get_current_account>",
                        headers: getCurrentAccountHeader
                    });
I saw forums mention to not include the the content type and I tried that too. I get:
Copy code
"Error in call to API function "users/get_current_account": Bad HTTP "Content-Type" header: "application/x-www-form-urlencoded; charset=UTF-8".  Expecting one of "application/json", "application/json; charset=utf-8", "text/plain; charset=dropbox-cors-hack"
There was even suggestions to force the content type to be blank
Copy code
const getCurrentAccountHeader = {
                        "Content-Type": "",
                        "Authorization": 'Bearer ' + accessToken,
                        "Dropbox-API-Select-Admin": ADMIN_USER
                    };
                    var getCurrentAccountResponse = https.request({
                        method: <http://https.Method.POST|https.Method.POST>,
                        url: "<https://api.dropboxapi.com/2/users/get_current_account>",
                        headers: getCurrentAccountHeader,
                    });
That results in an netsuite unexpected error
Copy code
type: "internal error",
      code: "UNEXPECTED_ERROR",
      details: "An unexpected SuiteScript error has occurred",
And Yes I tried all 3 content types... "Content-Type": 'application/json', "Content-Type": 'application/json; charset=utf-8' Give the expected
Copy code
"Error in call to API function "users/get_current_account": request body: could not decode input as JSON"
"Content-Type": 'text/plain; charset=dropbox-cors-hack' Results in a Netsuite unexpected error
Copy code
type: "internal error",
      code: "UNEXPECTED_ERROR",
      details: "An unexpected SuiteScript error has occurred",
b
netsuite is pretty picky on content types
there is a list of supported content types, that dropbox-cors-hack charset is unlikely to pass
netsuite also wont allow you to not send a content-type
it has default that it will send for you
you will have to send a content-type header, probably application/json
and then find a body that is acceptable to suitescript and dropbox
you would be looking for things like ' null '
which is like null, but has spaces, json doesnt care about spaces between tokens, and suitescript doesnt associate ' null ' with null
x
' null ' worked! Thank you @battk 🙏