I'm working on an application that uses Ushahidi to return an array of JSON objects using a HTTP GET request. I would like to use two parameters in the request. These parameters are category id and max id. In the URL below the first parameter is &by=catid&id=2 and the second is &by=maxid&id=499. The example below will only read the last parameter entered. So the catid parameter would be ignored.
http://fixyourstreet.ie/api?task=incidents&by=catid&id=2&by=maxid&id=499
Why will this request only return JSON objects by the last parameter entered rather than both parameters?
Any help would be much appreciated.
Those requests typically get parsed as key-value dictionaries by web servers.
This means the "by" parameter can only have one value when your request is processed and responded to. You will have to make 2 subsequent requests if you need all these values :
http://fixyourstreet.ie/api?task=incidents&by=catid&id=2
http://fixyourstreet.ie/api?task=incidents&by=maxid&id=499
Related
I'm trying to get data from my limesurvey and wonder why in API request I need to pass id: 1 as the third body parameter.
{method:'get_session_key',params:['myusername','mypassword'],id:1}
If I omit id or pass id:0, I will get the response data with an empty string. I can put any positive and negative integers there and I don't know exactly why it is required.
I'm following instructions on RemoteControl 2 API
That's the request id.
On the jsonRPCClient (component outside of LS) code it is fixed to 1.
I think it is part of a standard to use notifications, which are not used on LS API.
So, just fix it to 1 :)
I am testing the photos.batchGet endpoint.
Per the API docs, it takes two URL parameters "view" and "photoIds". When I try the photoIds parameter, the request only works with one photoId. Using multiple photoIds fails.
I tried using a delimeter between the photoIds in the string (by using a comma, pipe, and space). I also tried not using a delimeter at all. Not using a delimeter returns a response for the last photoId in the string, but not for any of the other photoIds. In short, none of my requests appear to be working. Am I doing something wrong?
Also, depending on server configuration, I think it's recommended for the URL length to be under 2,000 characters. Anything above 30 photoIds would create URLs longer than this.
That being said, maybe it would be better to make this a POST request that accepts a JSON request body? Just a thought, but think this would be better suited. A lot of our tours are above 30 scenes, and we even had a tour with 700 scenes!
The description of the batchGet function was updated. Per the documentation you should pass photoIds as a string and the URL query parameter should be photoIds=<id1>&photoIds=<id2>.
I'm using JMeters to automate API testing to/from our database using basic CRUD methodology. After the record creation, I'm trying to perform 3 different types of Reads (think CRRRUD). :)
Read 1 - Retrieve by ID
HTTP (GET) the base URL is appended with the saved record ID.
http..../crud/tableName/${newRecordId}
This returns
Read 2 - Retrieve by field type with no defined value
HTTP (POST) the base URL is extended with a "search" as the end. A Key is defined ("name") with no value.
http..../crud/tableName/search
Parameter Name = name
Value = {undefined}
This returns all records within the table whose field ("name") is not null.
Read 3 - Retrieve by field type with a defined value
HTTP (POST) the base URL is extended with a "search" as the end. A Key is defined ("name") with the value generated during the creation request.
http..../crud/tableName/search
Parameter Name = name
Value = Metropolis
This, too, returns ALL of the records within the table instead of just the record(s) whose name = Metropolis.
This 3rd Retrieve works properly when using a REST client, (e.g., Postman, Advanced REST Client, etc.) when defining the Key|Value pair as "name|Metropolis". So it must be something within JMeter that I'm missing.
Any insight is appreciated!
There is only one correct answer: compare what's being sent by REST Client and JMeter using sniffer tool (i.e. Wireshark), detect the differences and configure JMeter accordingly.
Just a guess: given you mentioned "API" an "REST" words maybe you need to pass it as JSON like:
{"name":"Metropolis"}
as a single parameter value
or in formatted way (in case if server checks Content-Length and/or wants the request to be properly formatted)
You may also need to add HTTP Header Manager in order to send Content-Type header with the value of application/json. See Testing SOAP/REST Web Services Using JMeter guide for more details.
Here is my query string
https://api.meetup.com/2/open_events?country=us&state=ca&city=sanfrancisco&category=34&page=10&group_photo&sign=true&&sign=true
I'm having no success reaching the group_photo resource.
In the docs they say:
group_photo
Returned when fields request parameter contains "group_photo".
Represents photo for the group hosting the event
I tried changing group_photo to group_photo=true but that didn't help.
Here's the console if you wanna test it
From the Meetup API documentation:
fields: Request that additional fields (separated by commas) be
included in the output
and
group_photo: Returned when fields request parameter contains
"group_photo". Represents photo for the group hosting the event
so you must add fields=group_photo and the call you gave above would be be something like:
https://api.meetup.com/2/open_events?country=us&state=ca&city=sanfrancisco&category=34&page=10&fields=group_photo&sign=true&sign=true
What is the correct response on a GET request for multiple objects where one or more of them does not exist? e.g.:
http://domain.net/event-list/?ids=1&ids=5&ids=3
where object with id 5 does not exist. Should I return a list with just objects 1 and 3 or should I return some kind of error? What is the correct response?
Also I wonder If the behaviour should be any different if the request is POST. For instance:
$.post('domain.net/events/bulk-edit/?ids=1&ids=5&ids=3', { public: true });
Should I just perform operation for the objects that exist or do not perform operation at all and return an error?
I know there are some debates if non-empty querystrings are ok for POST requests. I think they are alright just for this particular case where you request a subset of objects to do something with them.
Okay, I gave it some thoughts and here is what I believe were the right thing to do.
This is a bit of a headache since you're requesting multiple objects at once which is usually a WebDAV-thing, bringing wonders such as the 207/Multistatus response with it. Let me start of with saying that I think your query string has the wrong format. I think it really should look like this:
?ids[]=1&ids[]=5&ids[]=3
Now about responses on a GET request. I believe the following response codes were the right ones:
200 if any object could be found by id
400 on a missing or empty ids query parameter (unless you think no ids should translate into get all objects)
404 if none of the given ids match any object
If you want to notify the client that the request couldn't be satisfied in parts, you are free to send a Warning header along (cf RFC 2616, sec 14.46). However, if you really want to do it absolutely rightâ„¢, here's how to deal with requests where not every id is valid:
If all ids could be used to load an object, send the 200/Ok response code
If there are any ids that could not be used to load an object, redirect via 301/Moved Permanently to a new URL sans the offending ids param(s)
As for the POST request: It is my understanding that you'd like to set multiple events as public in one go? If so, I'd really change the order: Send a POST to http://domain.net/events/publish and send the ids in the post body.