How to pass array for a POST request in HTTPBuilder - grails

The post request code that I use:
def http = new HTTPBuilder(uri)
http.request(Method.POST, ContentType.TEXT){
send ContentType.URLENC, attrs
..Response handler code...
}
here attrs is a map with the key&value that needs to be passed such as:
[param1:'value1', param2:'value2', param3:'value3]
I need to support passing multiple values for the same parameter, hence passing as a map is not an option. What is my alternative in this case? What I need to pass:
[param1:'value1', param1:'value2', param3:'value3']

You should be able to do:
send URLENC, [param1:['value1','value2'], param3:'value3']
Your example won't work as a map can't have multiple keys with the same name

Related

Pull/Call the results of a Zapier trigger

I am trying to pull the results of another trigger (fields) to then be appended to the endpoint for another trigger. Basically trying to get the custom fields. I may also need to rule out any NULL fields. I have used bundle.inputdata before, but not sure if I need to use that or maybe something like bundle.outputData? The trigger is custom_fields.
Here is what I tried:
const options = {
url: 'https://edapi.zyx.com/v1/Subscribers?PageSize=2&Fields={bundle.outputData.custom_fields}',
method: 'GET',
headers: {
It sounds like you're looking to implement Custom/Dynamic Fields.
To accomplish this, you'll want to create a function that makes a request to your endpoint and returns an array of objects like -
[{"key":"field_1"},{"key":"field_2"}]
Add that function at the end of your inputfields array and once we're done listing the static fields, we'll call and load each returned array index as a custom field.
You should be able to parse out any null values in your function as well before returning.
You can get some additional information here -
https://github.com/zapier/zapier-platform/tree/master/packages/cli#customdynamic-fields

Create a NMARoute object from json file without additional HTTP call

We want to create a NMARoute without calling [NMACoreRouter calculateRouteWithStops: ...] as it send an unnecessary HTTP call to here.com. Because we already have every information to create a NMARoute object, we just want to initialize it. Unfortunately there is no public initializer. Is there any other approach to initialize a NMARoute object?
Take a look at route serialization:
https://developer.here.com/documentation/ios-premium/topics/route-serialization.html
Basically, the gist of it is that you can create a route based on an NSData object:
https://developer.here.com/documentation/ios-premium/topics_api_nlp_hybrid_plus/interfacenmaroute.html#topic-apiref__routefromserializedroute-colon-error-colon
Note:
The route data depends directly on the map data on your device. The routing data can become obsolete with a map update, and deserialization may not be valid.

deployd - post method to retrieve object

Trying to use deployd.com framework for simulating a backend service. I am fairly new to deployd, appreciate any example or pointer in the right direction. Trying to retrieve an object using POST method. It looks like POST is used to create objects.
In my case, POST data contains a few query fields that will be used to query an object and send json back. Is this possible using deployd by modifying onPost method or some other way?
I cannot use GET with query parms due to security restrictions.
here is post request data
[
{
customer:"sam",
city:"noWhere",
}
]
the POST event should query by customer and city, then return matching customer object
[
{
customer:"sam",
postcode:"352345",
city:"noWhere",
country:"US"
}
]

Grails: Accessing the request paramters without wiping them out

According to the document on command objects and data binding. Once you read the params object, that object can never be reused again.
From the documentation:
Binding The Request Body To Command Objects
http://grails.org/doc/2.3.x/guide/theWebLayer.html#commandObjects
Note that the body of the request is being parsed to make that work. Any attempt to read the body of the request after that will fail since the corresponding input stream will be empty. The controller action can either use a command object or it can parse the body of the request on its own (either directly, or by referring to something like request.JSON), but cannot do both.
I'm trying to view the parameters within a filter (which is hit before the controller is requested). Would logging the parameters to a log cause the controller to get a null param object? From the documentation that looks to be the case. However, how can I get access to the params without wiping them out in the filter?
Once you read the params object, that object can never be reused
again.
That is not correct. You can read request parameters over and over again. What cannot be read over and over again is the body of the request. The body and the request parameters are 2 different things.

How to access hash value stored in local variable

I'm doing an external API query ussing HTTParty, the resultant of that query is a hash that gets stored in an instance variable in my controller. Without saving it to my database I need to access the contents of the hash to send it as a string to another external app.
Here is my controller HTTParty call
#api_response = HTTParty.get("http://xxxxxxxxx.xx/vehicle/reg/#{#user.reg_number}/xxxxxxxxxxxxxxxxxxxxx")
Here is the response I get that is stored in #api_response:
{"response"=>
{"basic"=>
{"reg"=>"xxx", "make"=>"xxxx", "model"=>"xxxx", "version"=>"xxxxx", "body"=>"xxxxxx", "doors"=>"x", "reg_date"=>"xxxxxx", "engine_cc"=>"xxxxxx", "colour"=>"xxxxx", "fuel"=>"xxxxxx", "transmission"=>"x", "data_type"=>"x", "co2_emissions"=>"xxx"}
}
}
As it is I'm able to display the contents of #api_response in my views, but I need to retrieve the info and pass it on.
You access values in a hash using square brackets surrounding the hash key. For example, to access reg out of that response, you would do:
#api_response["response"]["basic"]["reg"]
Is that all you're looking for, or did you need to do something else with it?

Resources