This is a webhook activity I am trying do using postman. The post content is the below json.
{
"model":{
"id":"560a32d2a1dcb7902a7ad596",
"name":"cool features",
"pos":32767.5
},
"action":{
"id":"567537b94332a7d8489a0d26",
"idMemberCreator":"55024f3fdd60428e915d2c2b",
"data":{
"board":{
"shortLink":"SUDki3AR",
"name":"recipe",
"id":"560a31fad96886a87cabf39a"
},
"list":{
"name":"cool features",
"id":"560a32d2a1dcb7902a7ad596"
},
"card":{
"shortLink":"sufSA867",
"idShort":18,
"name":"added",
"id":"567537b94332a7d8489a0d25"
}
},
"type":"createCard",
"date":"2015-12-19T10:55:53.904Z",
}
}
rails strips away the action key value from params. I can only get it using request.raw_post . But it is a string . Is there a way to get the action value in the json in params? String manipulation would be very difficult.
Rails sets the params controller and action on every request, so it overwrites your action.
As you already found out, you can get the request string and as you know it's json, you can parse it (by the way: your json is invalid, an extra , after date):
action = JSON.parse(request.raw_post)['action']
Related
When using the addToGuestCart method of the guestCart API endpoint the selected_variations parameter isn't working. I've tried sending the post data in JSON format with selected_variations being set to an array
containing two variations retrieved from the getInventory endpoint. The API request gives a 200 HTTP response but doesn't return any data, and the item doesn't appear in the Etsy cart. Making the same API call without the selected_variations set works fine. Can you please advise the correct format for including selected_variations in a call to the addToGuestCart endpoint?
This worked for me:
const guestCart_data = {
url: "https://openapi.etsy.com/v2/guests/:guest_id/carts",
method: "POST",
data: {
guest_id: guestId,
listing_id: listingId,
quantity: 1,
selected_variations: `{"47626759898" : "55055453743", "513": "86877352060"}`
// selected_variations: `{"<property_id>" : "<value_ids>", "<property_id>": "<value_ids>"}`
},
};
I am trying to update a Custom field in a envelope that I have already sent.
Request URL: #https://demo.docusign.net/restapi/v2/accounts/1976929/envelopes/21d46fc6-8bbe-4315-b606-47cfd0ee0e3c/custom_fields>
Request Body:
"{\"textCustomFields\": [{\"name\":\"customer_email\",\"value\":\"new_email#new.com\",\"show\":\"true\",\"required\":\"true\"}]}"
Response:
{"textCustomFields"=>
[{"fieldId"=>"10198325521", "name"=>"customer_email", "show"=>"true",
"required"=>"true", "value"=>"new_email#new.com",
"errorDetails"=>
{"errorCode"=>"CUSTOM_FIELD_ALREADY_EXISTS", "message"=>"Field Name:
customer_email"}}], "listCustomFields"=>[]}
I am trying to update the value of custom field 'Customer Email'
the response I get is Custom Field Already exist.
The use case if that if by mistake the envelope has been sent to wrong email, we'd like to update the already sent envelope with this new email and resend it.
I am on Ruby on Rails.
If initially I sent the envelope with a custom text field value old_email#email.com.
Now I would like to see the value changed to new_email#email.com
Are you using a PUT or a POST? Should be a PUT.
Also, you only need to specify "FieldId", "name", and "value".
{
"textCustomFields": [{
"fieldId": "10210399758",
"name": "customer_email",
"value": "new_email#new.com"
}]
}
I wants to send some json parameter from HTML page with text area and I want to send json parameter written in this text area eg format. {"name": "test", "description":"test", "price":100}
But rails consider it as {"{'name' : 'test', 'description' : 'test', 'price' : 100}"=>nil} how do I send json parameter from text area to be readable from rails application.
I think you need to parse that string on server side with JSON.parse
param = '{"name" : "test", "description" : "test", "price" : 100}'
# assume you got the param on server side
json_param = JSON.parse(param)
puts json_param['name']
As you stated in the comment:
You can easily understand from this sample:
<input type='textarea' name='content' value='{"name": "test", "description":"test", "price":100}' id='text_content' />
You just sent a string to Rails in this way.
If you do the submit with a form, you should use different inputs for different params.
If Javascript, maybe jQuery, you can do it with function $.post.
Rails would parse the json for you.
I was looking a way to get a xml data from the server and parse it in a object so i can access that data anywhere in my app. I found many code doing this by creating a model, Store and setting a proxy with XMLReader. Yeah this is good but there is a compulsion of creating store and proxies. Is there any way i can say this is my URL of xml data, get me the parsed xml in an object. I think for getting JSON we have a way like below.
Ext.util.JSONP.request({
url: '<XYZ_URL>',
callbackKey: 'Successcallback',
Successcallback: function(result) {
console.log(result.data);
// Do your thing here
}});
Here we get a JSON data from the server and in the Successcallback function we get the JSON data as an Object in result. I can then save this result object globally and use it or travers through anywhere.
Can i do same thing with the XML data or i will get the XML data as string and then i need to parse it manually?
you can send Ajax request to the given Url and in success report method you can get your Desired data
e.g.
Ext.Ajax.request({
url: 'some_url',
success: function(response, opts) {
// parse the responseText
var data = Ext.util.JSON.decode(response.responseText);
// save the username
localStorage.setItem("name", data.name);
localStorage.setItem("id", data.id);
}
});
I have a form. I am trying to validate it through AJAX GET requests.
So i am trying to send the field values in the GET request data.
$('#uxMyForm').serialize();
the problem it is returning something undecipherable. I have used serialize before. This is totally bizzare.
the return value of serialize is
actionsign_upcontrollersitedataauthenticity_token=oRKIDOlPRqfnRehedcRRD7WXt6%2FQ0zLeQqwIahJZJfE%3D&customer%5BuxName%5D=&customer%5BuxEmail%5D=&customer%5BuxResidentialPhone%5D=&customer%5BuxMobilePhone%5D=&customer%5BuxDateOfBirth%5D=&customer%5BuxAddress%5D=&customer%5BuxResidentialStatus%5D=
i have no idea how to use this.
Thanks
update:
My question is how do i process such a request? like this?
puts params[:data][:customer][:uxName]
my GET request trigger looks like this
$.get('/site/sign_up',{data : $('#uxMyForm').serialize() }, function(data){
alert(data);
});
The above jquery lines generate the request.. on the action method i do the following
render :text => params
when i observe what is sent in the GET,in firebug PARAMS
**data** authenticity_token=oRKIDOlPRqfnRehedcRRD7WXt6%2FQ0zLeQqwIahJZJfE%3D&direct_customer%5BuxName%5D=&direct_customer%5BuxEmail%5D=&direct_customer%5BuxResidentialPhone%5D=&direct_customer%5BuxMobilePhone%5D=&direct_customer%5BuxDateOfBirth%5D=&direct_customer%5BuxAddress%5D=&direct_customer%5BuxResidentialStatus%5D=
the return value that i print in alert has
actionsign_upcontrollersitedataauthenticity_token=oRKIDOlPRqfnRehedcRRD7WXt6%2FQ0zLeQqwIahJZJfE%3D&direct_customer%5BuxName%5D=&direct_customer%5BuxEmail%5D=&direct_customer%5BuxResidentialPhone%5D=&direct_customer%5BuxMobilePhone%5D=&direct_customer%5BuxDateOfBirth%5D=&direct_customer%5BuxAddress%5D=&direct_customer%5BuxResidentialStatus%5D=
How does the form itself look. I have no experience with Ruby on rails - and if it builds the form in a new exciting way - but it looks as if there's only two form elements: authenticity_token and customer - where customer is an array of items. This is the data you posted, but I urldecoded it and put in some linebreaks:
authenticity_token=oRKIDOlPRqfnRehedcRRD7WXt6/Q0zLeQqwIahJZJfE=
&customer[uxName]=
&customer[uxEmail]=
&customer[uxResidentialPhone]=
&customer[uxMobilePhone]=
&customer[uxDateOfBirth]=
&customer[uxAddress]=
&customer[uxResidentialStatus]=
What you could do is to serialize the form to an array and clean it up before sending it using jQuery ajax request. I did something similar once when I had to serialize .net runat-server form elements:
var serializedData = $(form).serializeArray();
for( i=0; i < serializedData.length; i++)
{
// For each item in the array I get the input-field name after the last $ character
var name = serializedData[i].name;
var value = serializedData[i].value;
if( name.indexOf('$') != -1)
name = name.substr( name.lastIndexOf('$')+1 );
serializedData[i].name = name;
}
var ajaxPostData = $.param(serializedData);
So instad of blabla$ABCPlaceHolder$tbxEmail I got tbxEmail in the array. You could do the same to get uxName, uxEmail etc instead of the customer array.
Note then again, however, due to my inexperience with ruby that this may not be the best solution - maybe there's a setting you can change to build the HTML form differently?
Updated:
I'm not sure how ruby works, but after a googling I found you should be able to receive your values using params:customer as an array.
params:customer should contain an array of the values
{:uxName => "", :uxEmail => "" }
I hope that tells you something on how to receive the data. Maybe (warning - wild guess!) like this?
params[:customer][:uxName]