Getting POST https://content.dropboxapi.com/2/files/get_thumbnail_batch 400 (Bad Request) - dropbox-api

I am trying to fetch data using dbx.getThumbnailsBatch:
const response = await fetch(`https://content.dropboxapi.com/2/files/get_thumbnail_batch`, {
mode: 'no-cors',
method: "POST", // *GET, POST, PUT, DELETE, etc.
headers: {
"Authorization": "Bearer <REDACTED>",
"data": `{\"entries\":[{\"path\":\"${JSON.stringify(folders)}\"}]}`,
"Content-Type": "application/json"
},
});
const json = await response.json();
console.log(json)
And I'm getting these errors:
POST https://content.dropboxapi.com/2/files/get_thumbnail_batch 400 (Bad Request)
Uncaught (in promise) SyntaxError: Unexpected end of input (at App.js:73:1)
at nextImgs (App.js:73:1)
Can anyone tell why is this happening?

Related

Flutter http with authorisation: ClientException (Failed to parse header value)

I have an API that expects a JWT token.
I tested the API with https://hoppscotch.io, here is the query that returns the expected results (no error)
import axios from "axios";
const options = {
method: 'POST',
url: 'https://my_authority/text-message',
headers: {
Authorization: 'Bearer my_token',
'content-type': 'application/json'
},
data: {message: ''}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
And here is the code in Dart that fires the error ClientException (Failed to parse header value):
await http.post(
Uri.parse('$_httpEndpoint/$path'),
headers: {
HttpHeaders.contentTypeHeader: 'application/json',
HttpHeaders.authorizationHeader: 'Bearer my_token',
},
body: jsonEncode(body));
Both queries have the same parameters. I have no clue about the root causes.
Here is requests.headers in locals for IOClient.send when the error fires:
_CompactLinkedCustomHashMap ({content-type: application/json; charset=utf-8, authorization: Bearer my_token})
I don't know why http adds charset=utf-8, and I didn't manage to remove it.
I looked over the internet and didn't find an answer. Most of the similar questions are related to an error in the backend, it is not the case here.

Dio Error : Http Status Error Code [ 405 ] Flutter

I am getting HTTP status error code 405 on sending post requests from the real devices but it's working inside the postman.
The URL is: https://amapp.adtestbed.com/api/post-survey
The following is the form data I am using
FormData formData = FormData.fromMap({
'user_id': id,
'is_collection':
jobDetailsResponseModel.jobData.jobStatus == '8' ? 1 : 0,
'job_id': jobDetailsResponseModel.jobData.id,
'job_no': bookingIdController.text.toString(),
'sender_name': senderNameController.text.toString(),
'reciever_name': recieverNameController.text.toString(),
'sender_phone': senderPhoneController.text.toString(),
'reciever_phone': recieverPhoneController.text.toString(),
'sender_address': senderAddressController.text.toString(),
'reciever_address': recieverAddressController.text.toString(),
'sender_signature_data':
"data:image/jpeg;base64," + base64Imagesendersign,
'receiver_signature_data':
"data:image/jpeg;base64," + base64Imagerecieversign,
'location': currentLocation,
'images[]': uploadimages,
'maked[]': makedlist,
'model[]': modallist,
'rego[]': regolist,
'speedo[]': speedolist,
'is_drivable[]': isdrivablelist,
'goods_inside[]': goodsinsidelist,
'external_condition[]': externalconditionlist,
'interior_condition[]': internalconditionlist,
'survey_image[]': surveyimagelist,
'comments[]': commentlist
});
Here images field is a multipart form list.
And doing requests as follows
final response = await Dio().request(
'https://amapp.adtestbed.com/api/post-survey',
data: formData,
options: Options(
headers: {
"Accept": "application/json",
},
method: 'POST',
),
);
also used the following code to check but still not working
final response = await Dio().post(
'https://amapp.adtestbed.com/api/post-survey',
data: formData,
options: Options(
// headers: {
// // "Accept": "application/json",
// // 'Content-Type': 'application/x-www-form-urlencoded'
// },
method: 'POST',
),
);
When I am sending the form without an images field then it's submitting perfectly and giving 200 status but when I am sending it's with an images field that contains a multipart form list then it's returning 405 status code. End giving the error like the get method not supported only support post method. I also checked the backend code but no error from that's side because it's giving an error before sending the request. I also checked if there were some null data that created errors but not a single field is null.
But when I am doing both cases in postman then it's working fine.
This is the postman link:
https://drive.google.com/file/d/1hTmDC2aQ7vTMxSnzwaeRqd9gv7UbPWhR/view?usp=sharing
These are some images of the postman
https://stackoverflow.com/a/64235806/11623001
Check this out I had a similar issue too before, and I also noticed that you are not adding your authorization token to your header which may explain why you are getting 405 which would mean you can't have access.
I tried to recreate your issue on my end but the authorization token is expired, I'm getting a 401, but here is the code:
void postSome() async {
String base64 =
//This base64 is shortened "data:image/png;base64,...+WZm/et53efvWO6Tuc6rH7kUXy1lxs+/61t7dMg6VAvURAAAAQHMQogDAbE6dlLXtft/F3cuvkJNbetbn7VWrpUUX+mvEtqdHvgAAAABoOf8P3x1uDPELl4UAAAAASUVORK5CYII=";
FormData formData = FormData.fromMap({
'user_id': 139,
'is_collection': "1" == '8' ? 1 : 0,
'job_id': "248",
'job_no': "60036JL#1",
'sender_name': "test",
'reciever_name': "test",
'sender_phone': "1234567890",
'reciever_phone': "1234567890",
'sender_address': "test",
'reciever_address': "test",
'sender_signature_data':
base64,
'receiver_signature_data': base64,
'location': "32, Gopal Nagar, Om Nagar, Gopal Nagar Society, Parvat Patiya, Surat, Gujarat 395010, India\n",
'images[]': "/D:/App/Logicwind/GitLAb/whiteboard-digitization/test_images/w11.jpg",
'maked[]': "test",
'model[]': "test",
'rego[]': "test",
'speedo[]': "123",
'is_drivable[]': "1",
'goods_inside[]': "1",
'external_condition[]': "3",
'interior_condition[]': "3",
'survey_image[]': base64,
'comments[]': "test"
});
final response = await Dio().request(
'https://amapp.adtestbed.com/api/post-survey',
data: formData,
options: Options(
headers: {
'Accept': "application/json",
'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIzIiwianRpIjoiNTlkNzNlZjE4YzcxNGJjMWM1ZjE0ZGQxOWE1OWZmNmQ1YjVhNDViNDIwNzlkODY4ZmJkOGRmNjJlOGM4MDQzNmVjYmIxZjc4MjM5MmZiOGIiLCJpYXQiOjE2MjgxNzY5NTAsIm5iZiI6MTYyODE3Njk1MCwiZXhwIjoxNjU5NzEyOTUwLCJzdWIiOiI0NiIsInNjb3BlcyI6W119.lfnzUvq_LwYtBUQ-t6S_mKXEoM6er6ZzCuTUoHnqz9wwrdLOcu6x9CEixqMRvI-RWtSoiMO5KCYZsgagayGW5slYk6zAAa0V5fCjkRipqqus6mXe6nowtcXs_2V9ucjVoH4Evkb9lFBlE1rlpxKgcGXTcx4UgQs8kjJ5Wm4A8omedza_hUQPN9KUAfhhBDeL9hq-DkC7QbLu_YxnG5g-AETKhbJu8T4HWKqkh9NKGbNlvs1oi_nD81F1w8uSteY-UOgDJyUoGJxzoD6xmEv3J4mkrdr1ZbG88EzTyk3zngwBp9eWcLHhMS2psxArOnOnWusweJJ5uZiWiu2VIL7fWmV5b6G4OCvvkba5eXmw8iAvACACuCGQtOcGdN_euUgyfM9z9a8QbK8M2I-ux4GGY0ejCamFEJZCTwyBCxmLIrP4XjQoeL71WT1YBOgSZwDjA6qrAfL_fLwbEYQYbLIF8fLUmDOWRKBIaJLSVNG2x0Gl5LLXTiTZAzRRtJlSxZ4-Vid4hQJX39lohp-47XPAxvHnNTxiLw_aAG3SruFZ_rtdX4xnNbV3hSI825CD5dBeQC5iE-hiLXDWDXelM_q2fSD1rez62XQZGp1KfvlwowxAWgIghTfSH_E52h6mdoHEo9q73UJNYDz_F9Sj8EOfY3VWtmN6HMmcs4HZht36qX4',
},
method: 'POST',
),
);
print(response.statusCode);
}
It looks like below two fields are files not a form data.
'sender_signature_data': "data:image/jpeg;base64," + base64Imagesendersign
'receiver_signature_data': "data:image/jpeg;base64," + base64Imagerecieversign
You should add those as file fields like this
"sender_signature_data": await MultipartFile.fromFile(sender_signature_path,
filename: fileName, contentType: MediaType(mimee, type))
}),
"receiver_signature_data":await MultipartFile.fromFile(reciever_signature_path,
filename: fileName, contentType: MediaType(mimee, type))
})

I/O error while reading input message; nested exception is java.net.SocketTimeoutException

I can post input data using postman where as if I use the following code it's throwing an I/O error while reading the input message: nested exception is java.net.SocketTimeoutException(400)
$http({
method: "POST",
url: '/user',
headers: {'Content-Type': 'application/json', 'Accept': 'application/json'},
data: updateEmp
}).success(function (response) {
refresh();
}).error(function (response) {
alert(JSON.stringify(response));
//alert("There some problem while fetching.");
});

Creating JIRA issue through angular form

Trying to create an issue from angularjs using rest api throwing 403 forbidden error. New to this, any help would be appreciated.
error:
Response to preflight request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:8080' is therefore not allowed
access. The response had HTTP status code 403.
$http({
method: "POST",
url: 'https://jira.ab.com/rest/api/2/search',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " +
btoa('abc#ab.com' + ":" + '***'));
},
headers: {
'Content-Type': 'application/json'
},
data: JSON.stringify({
jql: {
project: "JQR",
maxResults: 20,
}
})
}).then(function successCallback(response) {
return response.data;
}, function errorCallback() {
console.log("Error calling API")
});

403 forbidden and 400 bad request errors while adding and deleting items to SharePoint list using REST

I'm new to SharePoint development. I'm Trying to develop simple SharePoint App using SharePoint online. I have a List named 'Products' in my site collection. In my app I wrote the following code to add and delete items to that list
function addProduct(product) {
var executor;
executor = new SP.RequestExecutor(appwebUrl);
var url = appwebUrl +"/_api/SP.AppContextSite(#target)/web/lists/getbytitle('Products')/items/?#target='" + hostwebUrl+"'";
executor.executeAsync({
url: url,
method: "POST",
body: JSON.stringify({__metadata: { type: 'SP.Data.ProductsListItem' },
Title: product.ProductName(),
ProductId: product.ProductId(),
ProductName: product.ProductName(),
Price:product.Price()
}),
headers: {
"Accept": "application/json; odata=verbose",
"content-type": "application/json;odata=verbose",
},
success: successProductAddHandler,
error: errorProductAddHandler
});
}
function successProductAddHandler(data) {alert('added successfully') }
function errorProductAddHandler(data, errorCode, errorMessage) { alert('cannot perform action') }
function deleteProduct(product) {
var executor;
executor = new SP.RequestExecutor(appwebUrl);
var url=appwebUrl+"/_api/SP.AppContextSite(#target)/web/lists/getbytitle('Products')/items('" + product.ID() + "')/?#target='" + hostwebUrl + "'";
executor.executeAsync({
url: url,
method: "POST",
headers: {
"IF-MATCH": "*",
"X-HTTP-Method": "DELETE"
},
success: successProductAddHandler,
error: errorProductAddHandler
});`
Im getting 403 error code when I call addProduct,
and 400 error code when I call deleteProduct.
I'm able to get the list items and display.
I tried adding X-RequestDigest": $("#__REQUESTDIGEST").val() but it did not work
If I include "Accept": "application/json; odata=verbose" in a request header for deleteProduct(), and when I call deleteProduct, two requests are going to server
/sites/productsdev/productsapp/_api/contextinfo (getting digest value)
/sites/ProductsDev/ProductsApp/_api/SP.AppContextSite(#target)/web/lists/getbytitle('Products')/items(itemid)/?#target='mysitecollectionurl' (using the digest value returned by the above call for X-RequestDigest)
Whenever you are doing any POST operation in SharePoint 2013 using REST API you have to pass below snippet in header
"X-RequestDigest": $("#__REQUESTDIGEST").val()
eg
headers: { "Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val() }