How to pass dynamic values to a GET API request? - api

The following GET request passes
#GET("api/v1/shades/colors?color=bl")
Call<List<Colors>> getColors();
but the following GET request fails.
#GET("api/v1/shades/colors?color={colorId}")
Call<List<Colors>> getColors(#Path(StringConstants.COLOR_ID) String colorId);
What's the right way to pass a dynamic value to a GET request?
Thank you!

It seems like you are using JaxRS web application. You should use this :
#GET("api/v1/shades/colors")
Call<List<Colors>> getColors(#Query("color") String colorId);
Check this: https://docs.oracle.com/javaee/6/tutorial/doc/gilik.html and this: https://mkyong.com/webservices/jax-rs/jax-rs-queryparam-example/.
Hope it helps !

Use annotation #RequestParam:
#GET("api/v1/shades/colors")
Call<List<Colors>> getColors(#RequestParam String colorId);

Related

How to put array parameter into fromdata with postman

How can I pass this form data in postman?
I have tried this way and did not work
https://stackoverflow.com/a/16104139/6793637
you should check this post and https://laracasts.com/discuss/channels/javascript/formdata-append-javascript-array-jsonstringify-how-to-cast-as-php-array?page=1
i think you should use JSON.parse(FOrmadata.field) in the server to convert the passed formData field to array

Softlayer API: filter image by OS referenceCode

I am trying to filter out my list of images by OS reference code. Here is the url I am trying:
https://api.softlayer.com/rest/v3/SoftLayer_Account/getBlockDeviceTemplateGroups.json?objectMask=mask[flexImageFlag]&objectFilter={'children': {'blockDevices': {'diskImage': {'softwareReferences': {'softwareDescription': {'referenceCode': {'operation': 'REDHAT_6_64'}}}}}}}
But I am kept getting the following error msg:
{"error":"Unable to parse object filter.","code":"SoftLayer_Exception_Public"}
Can anyone help me see what is wrong? Thanks in advance!
Q.Z.
The filter is wrong, but in my tests the filter is not working with the "referenceCode" property; you need to use another property such as name, version or both. See below the examples:
using name and version property
https://api.softlayer.com/rest/v3/SoftLayer_Account/getBlockDeviceTemplateGroups?objectMask=mask[flexImageFlag]&objectFilter={"blockDeviceTemplateGroups": {"children":{"blockDevices":{"diskImage":{"softwareReferences":{"softwareDescription":{"name":{"operation":"CentOS"}, "version":{"operation":"6.3-32"}}}}}}}}
Using only a property (name in this case)
https://api.softlayer.com/rest/v3/SoftLayer_Account/getBlockDeviceTemplateGroups?objectMask=mask[flexImageFlag]&objectFilter={"blockDeviceTemplateGroups": {"children":{"blockDevices":{"diskImage":{"softwareReferences":{"softwareDescription":{"name":{"operation":"CentOS"}}}}}}}}
Regards
Looks like you are using the REST api. The example in the
API reference, suggests that this parameter should be in JSON format:
https://api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests?objectMask=mask[id,hostname]&objectFilter={"datacenter":{"name":{"operation":"dal05"}}}
Your error says "Unable to parse object filter.", so the error is probably just be that your parameter is invalid JSON: The JSON standard only accepts double quotes.
Try replacing
{'children': {'blockDevices': {'diskImage': {'softwareReferences': {'softwareDescription': {'referenceCode': {'operation': 'REDHAT_6_64'}}}}}}}
with the corresponding valid json:
{"children": {"blockDevices": {"diskImage": {"softwareReferences": {"softwareDescription": {"referenceCode": {"operation": "REDHAT_6_64"}}}}}}}

Jmeter Add Variable to CSV Variable

I have a variable ${joinuserid} with integer Value which is generated by Regex Extractor.
If I put the variable directly to HTTP Request. It works.
Now, I have a CSV file with Variable :
connector,element2,elementID
and The CSV File contain :
member,unit,${joinusertid}
It doesn't work, HTTP request will get "${joinusertid}" not the value of ${joinusertid}. Can you help me or give me another advice for my scenario?
Thank you.
Regards,
Stefio
You can use ${__evalVar(query)}
So, ${__evalVar(elementID)} will return the integer value of joinuserid.

Recursive/Exploded uri variable with restlet

Does Restlet support exploded path variable (reference to URI Template RFC)?
An example would be /documents{/path*} where path can be for example "a/b/c/d/e".
This syntax doesn't seem to work with Restlet.
I'm creating a folder navigation api and I can have variable path depth, but I'm trying to have only one resource on the server side to handle all the calls. Is this something I can do with Restlet? I suppose I could create a custom router but if there is another way to do this I would like to know.
Thanks
It is possible to support this using matching modes.
For example:
myRouter.attach("/documents{path}",
MyResource.class).setMatchingMode(Template.START_WITH);
Hope this helps!
I'm doing the following
myRouter.attach("/documents/{path}", MyResource.class).setMatchingMode(Template.START_WITH);
Now I do get inside the resource GET method, but if I request the value of the path variable, I only get the first part (for example, /documents/a/b/c, path returns "a".) I use getRequest().getAttributes().get("path") to retrieve the value. Am I doing something wrong ?
Mathieu

How do I get only the query string in a Rails route?

I am using a route like this
match "/v1/:method" => "v1#index"
My intention here is capture the name of the api method and then send the request to that method inside the controller.
def index
self.send params[:method], params
end
I figured this would send the other parameters as an argument to the method, but it didn't work. So my question is how can I pass the non-method parameters in a query string?
#query_parameters does exactly what you want:
request.query_parameters
It's also the most efficient solution since it doesn't construct a new hash, like the other ones do.
Stolen from the work of a colleague. I find this a slightly more robust solution, since it will work even if there are changes to the path parameters:
params.except(*request.path_parameters.keys)
I sort of solved this problem by doing this:
params.except("method","action","controller")