I am trying to create a PUT request in POSTMAN . I am passing request body formdata, where I browse and select a json file "test.json" which contains request in json format.
I have updated the Content-Type as application/json.
But it's throwing following error.
"Input string
'----------------------------919570725980811960289934' is not a valid
number. Path '', line 1, position 52."
The content of the Json File is as follows
{
"id":2,
"ipAddress":"0.0.0.0",
"port":50667,
"status":0,
"dataManagerSourceName":"aaab"
}
PFB the screenshots
Request with headers
Request Body form data section
Related
For some reason, when I send JSON formatted data through Postman as raw text, I have no issues. When I send the exact same data through Postman as raw JSON (the difference should only be that the content-type header is application/json instead of application/text), I end up with my double quotes stripped and my strings switched to single quotes.
Original payload example (Postman sends this):
{ "id": "blahblahbloo", "time": "hammer" }
Unintended transformation (NextJS receives this):
{ id: 'blahblahbloo', time: 'hammer' }
To be clear, I get the exact same thing (which is what I expect) when I send as raw text via Postman:
// Postman sends this and NextJs receives this when set to raw text
{ "id": "blahblahbloo", "time": "hammer" }
I'm not explicitly doing anything to read the content-type and transform the data. My endpoints with this issue is a NextJS Dynamic Route: https://nextjs.org/docs/api-routes/dynamic-api-routes
Next.js API routes have a built-in bodyParser middleware that will parse the incoming request's body based on its Content-Type header.
From the API Middlewares documentation (emphasis is mine):
API routes provide built in middlewares which parse the incoming
request (req). Those middlewares are:
req.cookies - An object containing the cookies sent by the request. Defaults to {}
req.query - An object containing the query string. Defaults to {}
req.body - An object containing the body parsed by content-type, or null if no body was sent
Sending the payload as application/json will have the API route convert the req.body to a JavaScript object, hence striping the double-quotes.
While the bodyParser middleware is automatically enabled by default, you can disable it if you want to consume the body yourself.
// In the API route
export const config = {
api: {
bodyParser: false
}
}
I want send json data from odoo controller.For that i have created below controller
from odoo.http import Response
import json
#http.route('/api/json_get_request',auth='public',type='json',methods=["GET"],csrf=False)
def printjson(self,**kw):
headers={'content-type':'application/json'}
return Response(json.dumps({"test":"json string"}),headers=headers)
but accessing http://localhost:8089/api/json_get_request in postman gives me Invalid json data then I have check postman console in that response header -> Content-Type: "text/html" is shown.
Not understand after sending data in the json type why json data not recieved.
After accessing http://localhost:8089/api/json_get_request as http request on postman gives me correct json data.
Please give me suggestion
Thanks in advance
First thing method that handle 'json' request should return a dictionary directly:
#http.route('/api/json_get_request', auth='public', type='json', csrf=False)
def printjson(self, **kw):
return {'attribute': 'test'}
this will return a result like this:
{
"jsonrpc": "2.0",
"id": null,
"result": {
"attribute": "test"
}
}
You are having this error because you didn't send any json data with the request.
You could test your code using the requests module:
>>> import requests
>>> import json
>>> url = 'http://localhost:8069/api/json_get_request'
>>> data = {'params': {'test': 100}}
>>> headers={'content-type':'application/json'}
>>> requests.get(url, data=json.dumps(data), headers=headers)
<Response [404]>
It gives me this error because there is no database selected, and I have more than one database.
If you have only one database you see the correct result.
but when you test it from Postman extension I used RESTED
Because I'm all ready logged to Odoo the method was executed successfully , Just look for a better postman extension or search how to send json data with your current postman. You need to send some json data in the request.
I have a SoapUI REST (i.e. non-SOAP) mock service that returns a response for a POST request.
The request and response both contain JSON content.
At the moment, I can get it to return a static response and that works fine, but I want some of the values in the response to be dynamically sourced from the request.
So if I have this request:
{
"the_request":{
"abc":"123",
}
How can I get the value of "abc" copied in the response?
Investigation has lead me to believe I can do this via including a variable in the response, something like:
Response:
{
"the_response":{
"value_from_request":"${#MockResponse#Request#the_request#abc}",
"other":"stuff",
}
And then implementing a script to populate the variable in the response, via the Script tab.
How can I then populate this with data from the request?
Currently SoapUI just generates an empty value
"value_from_request":"",
Tried using mockRequest.requestContent in the Script tab, but have not found how to obtain the "123" value from it.
OK, worked this out. So the response message can simply reference a variable in the requestContext like so:
Response:
{
"the_response":{
"value_from_request":"${the_value}",
"other":"stuff",
}
And a groovy script can be used to parse the JSON request content and populate "the_value" or whatever you like in the requestContext:
// Parse the JSON request.
def requestBody = new groovy.json.JsonSlurper().parseText(mockRequest.getRequestContent())
// Set up "the_value" from the request message.
requestContext.the_value = requestBody.the_request.abc
// Bit of logging so can see this in the "script log" tab.
log.info "Value extracted from request: ${requestContext.the_value}"
I think the script should be like this
def requestBody = new groovy.json.JsonSlurper().parseText(mockRequest.getRequestContent())
context.setProperty("the_value",requestBody.the_request.abc)
I am using Extjs 5.1.3. I have post request with params as-
{"root":{"countryId":"458","ruleId":"3386","ruleName":"Test1 \\","ruleType":"CELL_STORE","opType":"DETAILS"}}
I am creating ajax request as-
Ext.Ajax.request({
method: 'POST',
url: appurl.fetchRuleDetails,
params: win.jsonData,
callback: function(option, success, response){
})
})
From server side, response is coming as-
{
"rules":[
{
"countryId":"458",
"ruleId":"3386",
"ruleName":"Test1 \\",
"ruleType":"CELL_STORE",
"ruleParts":[
{
"seq":"1",
"attrId":"6",
"attrName":"Store Type",
"op":"=",
"val":"dsafdaf",
"charType":"GLOBAL_CHAR"
}
]
}
],
"Status":{
"StatusFlag":true,
"StatusCode":"SUCCESS",
"StatusMessage":"SUCCESS"
}
}
But in Ajax request's callback function, we are receiving response.responseText as-
Request Media Type[application/json] Error! Request Body is not JSON format.
My guess is like issue is because of rulename value as "Test1 \".
So can someone please help me whats missing.
The error message is not an ExtJS error message. If you receive an ExtJS error related to invalid JSON, it will look like this:
Uncaught Error: You're trying to decode an invalid JSON String: TestTest
My best guess is that the error message comes from the server, because it expects you to send your request as JSON. Right now you are sending it as FormData. To send the request as JSON, you have to put your object in the jsonData config and leave the params config undefined:
Ext.Ajax.request({
method: 'POST',
url: appurl.fetchRuleDetails,
jsonData: win.jsonData,
callback: function(option, success, response){
})
})
For future questions regarding server-client communication, please keep in mind that you should first check in your browser network tab what you send to the server and what the response from the server really is.
I am working on GRAILS-ReactJs based project which involves a scenario where I need to send the RESUME and the JSON data in one POST call.
However, I am able to send file in one call but the data I am getting is null.
I am using Grails-3 at my server side and receiving the POST request as multipart file. I want both JSON and Multipart file object to be combined in one object to send to the server and want to receive the file and the JSON data both at the server side.
I have tried changing the content type of the header but ut doesn't work.
You can't post JSON data along with the file or any other attachment. You can post it as form data to your back end. The form data is passed as a multi-part data to the server with relevant boundaries. Here's a sample code for your reference. You may pass json data along with the formData as key, value pairs.
export function postAttachment (fileData, fileName) {
let formData = new FormData()
formData.append('prop1', 'value1')
formData.append('prop2', 'value2')
formData.append('upload', fileData, fileName)
return fetch('/your/endpoint', {
headers: {
'Accept': 'application/json',
'header1': 'headerValue1'
},
method: 'POST',
body: formData
})
}
Hope this helps. Happy Coding !