POSTMAN - Version 10.12.0
I am trying to call a REST API via POST and I need to pass an image as a parameter. I tried form-data to pass parameters but getting following error.
{
“error”: {
“code”: “REQUEST_ERROR”,
“message”: “Malformed Request.”,
“details”: [
{
“code”: “JSON_SYNTAX_EXCEPTION”,
“message”: “The syntax of the JSON document is not valid.”
}
]
}
}
I found that ‘data’ is the issue and it gives the error basically.
I am not sure how to pass other payload attributes except the image in form-data page.
There are several media fields in that example, however, all of them are showing a string data type. (As I would expect for a JSON request).
You can’t send a binary file using raw\JSON.
The example isn’t really showing what needs to be added here.
I’m guessing (and its just a guess) that the media file needs to be added as a base64 encoded string as you can’t send binary data outside of form data. MediaText allows 64000 characters (as the other fields would be too small for a base64 string).
Need much more information on the API. That request example is pretty poor.
I believe the problem is not with the image. I found that even if you add a single attribute/value pair to the form-data, you get the same error.
Have gone through lots of forums and tried to send standard text attributes as different ways but getting the same error.
Option 1: as data (note: Data is NOT an attribute in the payload)
key
data
value
{“Name”: “Testing”,“Description”: “My Description”,“MediaItemType”: “Image”,“PrivateMediaItem”: true,“Repository”: “Database”}
Do you have any instructions for that API that specifically tells you to use form-data?
The screenshot shows that the request body schema is application/json, which means raw\JSON in Postman which you say is working apart from the image.
Therefore I would expect this to cause an error if you try and use form-data.
JSON requests are basically text. Therefore I’m not expecting you to be able to attach a binary file to this request in Postman.
The usual process would be to base64 encode the file (which would create a large text string) and that can be included in the JSON body (but its not obvious from your sample if this API can even do that).
Therefore, can you advise what API is this using?
Can you please link to the documentation if that is possible.
I believe this is a very simple payload but for some reason it is not working for even application/json for some reason in this version.
Just forget about the optional image.
form-data should accept application/json.
please refer following link.
I will do my own investigation as to see why form data is not working for a simple json payload.