Empty response after sending request to couchDB - json

I've got problem with CouchDB request. Record from view looks like:
{
"total_rows":79293,
"offset":0,
"rows":[
{"id":"401417608421000",
"key":["2015-08-03T12:07:01+0000"],
"value":0}]
}
request looks like:
http:/ip:port/testDB/_design/reports/_view/experiments?key=["2015-08-03T12:07:01+0000"]
it returns
{
"total_rows":79382,
"offset":0,
"rows":[ ]
}
I read https://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options
and change url to
http:/ip:port/testDB/_design/reports/_view/experiments?key=%5B%222015-08-03T12:0‌​7:01+0000%22%5D
but it didn't helped.
Directly I want to send request with startDate and endDate.

It's the plus sign that is making the query fail. If you encode the url you should at least try to encode the entire parameter, this works for me:
?key=%5B"2015-08-03T12%3A07%3A01%2B0000"%5D
And after a bit of testing I found the plus sign to be the problem, so a prettier key-parameter looks like this and works for me:
?key=["2015-08-03T12:07:01%2B0000"]

Related

Postman: POST request of nested JSON via form-data not working (while via raw-data ok)

I want to POST the following JSON-object via Postman:
{
"title": "test_title",
"date": "2021-12-31",
"attachments": [
{
"name": "test_attachment"
}
]
}
This works perfectly fine, when using Postman's raw input form for the request-body: I get a "201 Created"-response back.
However, when using the form-data to POST the data, I get the error "Invalid data. Expected a dictionary, but got str." (see also screenshot below) What am I doing wrong here? I tried all kind of other versions to enter the attachment-key:value pair but nothing worked so far
I managed to make it work! (note: I added some additional fields compared to the screenshot in question. See below for details:
You did nothing wrong.
If you want to make a request with json object, then you go with raw type (json) in postman.
If you want to upload file, then you use form-data
One more thing, status 201 means the request is succeed, your object has been created.
var express = require('express')
const multer = require('multer')
const upload = multer()
var app = express()
app.use(express.json());
app.post('/test',upload.none(), function (req, res, next) {
res.send(req.body)
})
app.listen(80, function () {
console.log('web server listening on port 80')
})
Above is a sample endpoint which works with both form-data and json , just do a post to http://localhost:80/test with both form data and raw json
you can see both will get parsed correclty
APIs are just abstraction , its like a function that takes in many attribute, how you parse it depends on the implementation ( how the api function is written) .
so answer is "Talk to the developer" on how the API is implemented and what it is supporting
I'm having issue in placing json into form format the way Daniel did in Postman. Need help in figuring out what is it required to place the cascaded json objects into form data format. Please see here that I'm trying to accomplish.
JSON Format (to be filled into Postman form-data section:
{
"primary_object": {
"child_object_1": [{"id": 12345678, "value": "abc"},{"id": 87654321, "value": "xyz"}],
"child_object_2": [
"first_val",
"second_val"
]
}
}

Facebook API - Batch upload photos

I'm trying to batch upload photos and I keep getting a response back from Postman saying "Batch parameter must be a JSON Array" Does anyone see what is wrong with this because it looks like valid json to me. I've been rattling with this for a few hours making minor tweaks trying to get it to upload to no avail. I also have tried encoding the url.
https://graph.facebook.com/v2.11?batch=[{"method":"POST", "relative_url":"https://graph.facebook.com/v2.11/{pageid}/photos?access_token={access-token}", "body":"link_url":"https://{link-to-image}/wmphotos/999995/6d5cc4169bbf4e7dbe31f3739e025412/a572c29dff_640.jpg"}]&access_token={access-token}
Looking at your code, it seems that the JSON object in your batch array is actually malformed. body:link_url:link should be body: {link_url:link}
Bad:
[
{
"method":"POST",
"relative_url":"foo",
"body":"link_url":"link"
}
]
Good:
[
{
"method":"POST",
"relative_url":"foo",
"body":{"link_url":"link"}
}
]

JMeter Variables in JSON request

When I pass an variable in JMeter HTTP request, I'm getting an exception
"Unexpected escape character after back slash"
The request body:
"Draft":{
"id": 123654656,
"draftdata":{\\\"accCat\\\":\\\"207\\\",\\\"accNumber\\\":\\\"656565
\\\",\\\"id\\\":${Var_ID},...}
}
When I send the request, one of the two back-slashes are omitted. I guess the variable ${Var_ID} should be passed in a way that does not conflict with the json body
I don't think you need these \\\ signs
I believe you need to surround ${Var_ID} with quotation marks
Something like:
{
"id": 123654656,
"draftdata": {
"accCat": "207",
"accNumber": "656565 ",
"id": "${Var_ID}"
}
}
You can use online JSON validation tools like Online JSON Viewer to test your JSON payload. Also check out Testing SOAP/REST Web Services Using JMeter article for some initial information on testing REST APIs using JMeter
Maybe making changes like:
{
"Draft": {
"id": 123654656,
"draftdata": {
\"accCat\":\"207\",
\"accNumber\":\"656565\",
\"id\":\"${Var_ID}\",...}
}
I don't see any need to have \ signs, just one will escape original " signs.
The variables, or the request to some function of JMeter, into json body must be passed without quotation marks, something like this:
"Draft":{
"id": 123654656,
"draftdata":{
"accCat":"207",
"accNumber":"656565",
"id":${Var_ID},...}
}
Also yout don't need the backslashes signs. Hope this help.

Is it possible to send an array with the Postman Chrome extension?

I've been using Postman Chrome extension to test out my API and would like to send an array of IDs via post. Is there a way to send something list this as a parameter in Postman?
{
user_ids: ["1234", "5678"]
}
You need to suffix your variable name with [] like this:
If that doesn't work, try not putting indexes in brackets:
my_array[] value1
my_array[] value2
Note:
If you are using the postman packaged app, you can send an array by selecting raw / json (instead of form-data). Also, make sure to set Content-Type as application/json in Headers tab.
Here is example for raw data {"user_ids": ["123" "233"]}, don't forget the quotes!
If you are using the postman REST client you have to use the method I described above because passing data as raw (json) won't work. There is a bug in the postman REST client (At least I get the bug when I use 0.8.4.6).
For me did not work with array[0], array1, .. or array[], array[], ... .
It works more simply:
If you want an array of dicts, try this:
Here is my solution:
use form-data and edit as below:
Key Value
box[] a
box[n1] b
box[n2][] c
box[n2][] d
and you will get an array like this:
{"box":{"0":"a","n1":"b","n2":["c","d"]}}
It is important to know, that the VALUE box is only allowed to contain a numeral value (no specifiers).
If you want to send e.g. an array of "messages" with Postman, each having a list of key/value pairs, enter e.g. messages[][reason] into the KEY box and the value of reason into the VALUE box:
The server will receive:
{"messages"=>[{"reason"=>"scrolled", "tabid"=>"2"}, {"reason"=>"reload", "tabid"=>"1"}], "endpoint"=>{}}
I also had that problem, and solved it by doing the following:
1 - Going to the request header configuration and added the following:
Accept : application/json, text/plain, */*
Content-Type : application/json;charset=UTF-8
2 - To send the json array, I went to raw json format and set the user_ids to array:
user_ids: ["bbbbbbbbbb","aaaaaaaaaa","987654321","123456789"]
Set Body as raw and form the array as follows:
As mentioned by #pinouchon you can pass it with the help of array index
my_array[0] value
my_array[1] value
In addition to this, to pass list of hashes, you can follow something like:
my_array[0][key1] value1
my_array[0][key2] value2
Example:
To pass param1=[{name:test_name, value:test_value}, {...}]
param1[0][name] test_name
param1[0][value] test_value
Go to Header and select Content-Type = application/json then go to body and select raw and then pass an array.
this worked for me. to pass an array of Item object {ItemID,ColorID,SizeID,Quntity}
in headers set
content-type : application/x-www-form-urlencoded
In body select option
x-www-form-urlencoded
and insert data as json array
user_ids : ["1234", "5678"]
This also works for lists within the object:
Id:37
IdParent:26
Name:Poplet
Values[0].Id:1349
Values[0].Name:SomeName
Values[1].Id:1350
Values[1].Name:AnotherName
the equivalent JSON would be:
{
"Id": 37,
"IdParent": 26,
"Name": "Poplet",
"Values": [
{
"Id": 1349,
"Name": "SomeName"
},
{
"Id": 1350,
"Name": "AnotherName"
}
]
}
{
"data" : [
{
"key1" : "value1",
"key2" : "value2"
},
{
"key01" : "value01",
"key02" : "value02"
},
{
"key10" : "value10",
"key20" : "value20"
}
]
}
You can pass like this.
In form-data you can pass a array like this
and in backend you will fetch it like a
"tags"=>["aaaa", "bbb"]
In my case I've to pass two values in a array so I write it two times
Choose either form-data or urlencoded and use the same key "user_ids". The server should receive it as an array.
In form-data,
key value
user_ids[] 1234
user_ids[] 5678
My back-end is written in Ruby on Rails. This is how I sent the array params using Postman. It worked for me.
UPDATE
I'm using x-www-form-urlencoded. I believe it will work too for form-data.
To send an array using form data there's no need to use brackets.
Just send that specific array using the same name in multiple fields.
Like:
my_array:value_1
my_array:value_2
Although this question has already accepted a solution still that solution has a drawback that is we have to repeat the key (Array name) again and again as one key is accepting only one value. Like this:
Imagine we have 10 values or more, should we repeat the same Array name each time? The programmatic answer is NO. Then we should do the following that is a better approach.
Select the form-data as usual
Type Array name in the Key field
Pass the Array in Value field
Like this:
Now, you should be able to send the Array, but wait, this won't be stored in Database like that in my case with MongoDB. So what you have to do is, use the following piece of code to send it like an Array in the Database:
First, we need to parse it using JSON, like this
let user_ids = JSON.parse(body.user_ids);
Now, you can send user_ids variable to database like an Array
That's All!
I tried all solution here and in other posts, but nothing helped.
The only answer helped me:
Adding [FromBody] attribute before decleration of parameter in function signature:
[Route("MyFunc")]
public string MyFunc([FromBody] string[] obj)
Supposing you have the array of object below,
features: [
{
title: { type: String },
type: { type: String },
},
],
To add the values on the form data on the postman, add it this way
features[title]
features[type]
Check also the image below
Here is something that worked for me
{
"user_ids":["[1234, 5678]"]
}
I believe it depends on how the backend is setup most of the time.
N.B Now we are in 2022 if All of the above solutions didn't, just don't panic. pass array name with is value without a bracket and the add it multiple time, just link how the image below is showing. it should work just fine. If It does work, buy me some coffee, hhh
In my case I need to send array of objects, I sent it like this
Request header configuration and added the following
Accept: application/json
You need to suffix your key variable name with []
like key[0][name]
You can insert it in "bulk-edit" mode
Body section in form-data on right side click Bulk Edit and added the following
items[0][prod_id]:174336
items[0][item_weight]:3.400
items[0][item_qty]:1
items[0][item_selected_melting]:92
items[0][item_remarks]:
items[1][prod_id]:12345

Search ElasticSearch via GET using JSON

Anyone know of a way to send a JSON query to an ElasticSearch server via HTTP GET? I know you can POST the JSON content to _search, but POST is not available because this is cross-domain. For example, if my query looks like this:
{
"query": {
"query_string": {
"fields": ["name", "description"],
"query": "Elastic Search"
}
}
}
Which I would convert to something like:
{"query":{"query_string":{"fields":["name","description"],"query":"Elastic Search"}}}
Is there a way to GET server:9200/index/type/_search?content=stringifiedquery or something similar? I've tried q= and content= as well as just passing the content after the ? but nothing seems to work. Anyone have any ideas? Or am I just out of luck?
You can use the source query string parameter to send what would normally be the post body.
See the bottom of this page: http://www.elasticsearch.org/guide/reference/api/