Parsing SoundCloud - Change API Call, not receiving JSON data? - ios

I'm playing around with the SoundCloud iOS tutorial and have been changing the API calls to get different information.
However, I can't seem to get any JSON back for a call I make to the API when I try to do a GET request on the URL https://api.soundcloud.com/me/activities/tracks/affiliated.json. The GET request works in the API console. Other GET requests work too, so I'm thinking that it's the definitely the way I'm asking for information in Xcode.
Here's the "Money" part of the program - gets the data, parses, creates a new view controller that has an array as a property with the response.
SCRequestResponseHandler handler;
handler = ^(NSURLResponse *response, NSData *data, NSError *error) {
NSError *jsonError = nil;
NSJSONSerialization *jsonResponse = [NSJSONSerialization
JSONObjectWithData:data
options:0
error:&jsonError];
if (!jsonError && [jsonResponse isKindOfClass:[NSArray class]]) {
UIStoryboard *sb = self.storyboard;
SCTTrackListViewController *trackListVC;
trackListVC = [sb instantiateViewControllerWithIdentifier:#"TLVC"];
trackListVC.tracks = (NSArray *)jsonResponse;
// Am I getting JSON back for tracks/affiliated.json ?
NSLog(#"json %#",(NSArray *)jsonResponse);
[self presentViewController:trackListVC
animated:YES
completion:nil];
}
};
NSString *resourceURL = #"https://api.soundcloud.com/me/activities/tracks/affiliated.json";
[SCRequest performMethod:SCRequestMethodGET
onResource:[NSURL URLWithString:resourceURL]
usingParameters:nil
withAccount:account
sendingProgressHandler:nil
responseHandler:handler];
}
If I use NSString *resourceURL = #"https://api.soundcloud.com/me/tracks.json"; or NSString *resourceURL = #"https://api.soundcloud.com/me/favorites.json"; then I get a list of tracks returned in JSON. If I use the one in the code example, I get no response - total silence.
The JSON response I get for https://api.soundcloud.com/me/favorites.json is in the form of
[
{
"kind": "track",
"id": 112547469,
"created_at": "2013/09/26 06:50:06 +0000",
"user_id": 294371,
"duration": 4499751,
"commentable": true,
"state": "finished",
"original_content_size": 143977742,
"sharing": "public",
"tag_list": "Funk Disco",
"permalink": "the-boogie-down",
"streamable": true,
"embeddable_by": "all",
"downloadable": false,
"purchase_url": null,
"label_id": null,
"purchase_title": null,
"genre": "Boogie",
"title": "The Boogie Down",
"description": "1.\tWar - The World Is A Ghetto (Suonho Edit)\r\n\r\n2. \tWhiskey Barons - The Same Love\r\n\r\n3.\tRayko - Broadway\r\n\r\n4.\tNicholas - Talking About Love\r\n\r\n5.\tBen E. King - Supernatural Thing (Fingerman Edit)\r\n\r\n6.\tGazeebo - Scaredy Cat\r\n\r\n7.\tFingerman - Fat Like You Know\r\n\r\n8.\tWillie Beaver - Party Time (Karim Edit)\r\n\r\n9.\tDeadly Sins - I Can Feel It\r\n\r\n10.\tFingerman - Tootin\r\n\r\n11.\tRocco Raimundo - Give Me Your Love\r\n\r\n12.\tLuther Vandross - Never Too Much\r\n\r\n13.\tKool & The Gang - Get Down On It (Rocco Raimundo Edit)",
"label_name": "",
"release": "",
"track_type": "",
"key_signature": "",
"isrc": "",
"video_url": null,
"bpm": null,
"release_year": null,
"release_month": null,
"release_day": null,
"original_format": "mp3",
"license": "all-rights-reserved",
"uri": "https://api.soundcloud.com/tracks/112547469",
"user": {
"id": 294371,
"kind": "user",
"permalink": "web_d",
"username": "webd",
"uri": "https://api.soundcloud.com/users/294371",
"permalink_url": "http://soundcloud.com/web_d",
"avatar_url": "https://i1.sndcdn.com/avatars-000011907556-1k1cgw-large.jpg?3eddc42"
},
"user_playback_count": 1,
"user_favorite": true,
"permalink_url": "http://soundcloud.com/web_d/the-boogie-down",
"artwork_url": "https://i1.sndcdn.com/artworks-000058671332-jzz9uc-large.jpg?3eddc42",
"waveform_url": "https://w1.sndcdn.com/qA5zJCmDqO46_m.png",
"stream_url": "https://api.soundcloud.com/tracks/112547469/stream",
"playback_count": 69,
"download_count": 0,
"favoritings_count": 1,
"comment_count": 0,
"attachments_uri": "https://api.soundcloud.com/tracks/112547469/attachments"
},
whilst the response for https://api.soundcloud.com/me/activities/tracks/affiliated.json goes:
{
"collection": [
{
"type": "track",
"created_at": "2013/10/08 20:14:16 +0000",
"origin": {
"kind": "track",
"id": 114421587,
"created_at": "2013/10/08 18:20:21 +0000",
"user_id": 144598,
"duration": 340616,
"commentable": true,
"state": "finished",
"original_content_size": 13624479,
"sharing": "public",
"tag_list": "",
"permalink": "faden-away",
"streamable": true,
"embeddable_by": "all",
"downloadable": false,
"purchase_url": null,
"label_id": null,
"purchase_title": null,
"genre": "Funk",
"title": "Faden Away",
"description": "",
"label_name": "",
"release": "",
"track_type": "",
"key_signature": "",
"isrc": "",
"video_url": null,
"bpm": null,
"release_year": null,
"release_month": null,
"release_day": null,
"original_format": "mp3",
"license": "all-rights-reserved",
"uri": "https://api.soundcloud.com/tracks/114421587",
"user": {
"id": 144598,
"kind": "user",
"permalink": "stonesthrow",
"username": "Stones Throw Records",
"uri": "https://api.soundcloud.com/users/144598",
"permalink_url": "http://soundcloud.com/stonesthrow",
"avatar_url": "https://i1.sndcdn.com/avatars-000001771161-2x04bn-large.jpg?3eddc42"
},
"user_playback_count": 1,
"user_favorite": false,
"permalink_url": "http://soundcloud.com/stonesthrow/faden-away",
"artwork_url": "https://i1.sndcdn.com/artworks-000059640743-qtexag-large.jpg?3eddc42",
"waveform_url": "https://w1.sndcdn.com/NBZ15f1BZ4cV_m.png",
"stream_url": "https://api.soundcloud.com/tracks/114421587/stream",
"playback_count": 29756,
"download_count": 0,
"favoritings_count": 1587,
"comment_count": 138,
"attachments_uri": "https://api.soundcloud.com/tracks/114421587/attachments",
"sharing_note": {
"text": "",
"created_at": "2013/10/08 20:14:16 +0000"
}
},
"tags": "affiliated"
},
{
"type": "track",
"created_at": "2013/10/08 14:26:00 +0000",
"origin": {
"kind": "track",
"id": 112820793,
"created_at": "2013/09/27 21:39:16 +0000",
"user_id": 1520490,
"duration": 290926,
"commentable": true,
"state": "finished",
"original_content_size": 12579855,
"sharing": "public",
"tag_list": ""MUSEUM OF LOVE" "DFA RECORDS" "PAT MAHONEY" "LCD SOUNDSYSTEM" "THE JUAN MACLEAN" JEE DAY DFA",
"permalink": "museum-of-love-monotronic",
"streamable": true,
"embeddable_by": "all",
"downloadable": false,
"purchase_url": "https://itunes.apple.com/album/monotronic-single/id711563768",
"label_id": null,
"purchase_title": "DIGITAL SINGLE",
"genre": "",
"title": "Museum of Love - Monotronic",
"description": "Museum Of Love\n"Monotronic"\n\nDFA2390\n\nfirst single "Down South" available here: http://store.dfarecords.com/products/dfa2389",
"label_name": "DFA Records",
"release": "DFA2390",
"track_type": "original",
"key_signature": "",
"isrc": "",
"video_url": "http://www.youtube.com/watch?v=K2E6oK7tN5w",
"bpm": null,
"release_year": 2013,
"release_month": 10,
"release_day": 8,
"original_format": "mp3",
"license": "all-rights-reserved",
"uri": "https://api.soundcloud.com/tracks/112820793",
"user": {
"id": 1520490,
"kind": "user",
"permalink": "dfa-records",
"username": "DFA Records",
"uri": "https://api.soundcloud.com/users/1520490",
"permalink_url": "http://soundcloud.com/dfa-records",
"avatar_url": "https://i1.sndcdn.com/avatars-000002067008-el39h6-large.jpg?3eddc42"
},
"user_playback_count": 1,
"user_favorite": false,
"permalink_url": "http://soundcloud.com/dfa-records/museum-of-love-monotronic",
"artwork_url": "https://i1.sndcdn.com/artworks-000058798982-ogzv3j-large.jpg?3eddc42",
"waveform_url": "https://w1.sndcdn.com/0m0pwUhjvenc_m.png",
"stream_url": "https://api.soundcloud.com/tracks/112820793/stream",
"playback_count": 10047,
"download_count": 0,
"favoritings_count": 309,
"comment_count": 18,
"attachments_uri": "https://api.soundcloud.com/tracks/112820793/attachments",
"sharing_note": {
"text": "",
"created_at": "2013/09/27 21:39:16 +0000"
}
},
"tags": "affiliated"
},
I'm trying to store the response in an NSArray, and I think that might be the issue... can someone point me in the right direction to get the JSON for affiliated.json? Is the response of the second JSON a dictionary? Do I need to store the response for that one differently? I thought I could store a dictionary in an NSArray...

The reason I was getting back nothing was due to this line: NSLog(#"json %#",(NSArray *)jsonResponse); where I was casting jsonResponse as an NSArray. This worked in the first instance because the response was an array, but in the second instance the response was a dictionary. Pretty obvious now that I think about it. I changed that line to (NSDictionary *)jsonResponse and all was well.
After I received the JSON data, this was also a good way to experiment with the different ways to dig into the nested info in the data. For instance, I created a dictionary to hold jsonResponse. I could get the info for the key I wanted in a couple of ways:
dictionary[#"user"][#"avatar_url] would get the nested value for avatar_url which was itself nested in user.
I could also do this by calling [dictionary valueForKeyPath:#"user.avatar_url"];

Related

Shopify products/delete webhook only returns ID

My ruby on rails app is supposed to do some things whenever a product is deleted. According to Shopify's website here the response to products/delete is supposed to be a JSON object with information such as the product_id associated with the product that was deleted:
{
"id": 788032119674292922,
"title": "Example T-Shirt",
"body_html": null,
"vendor": "Acme",
"product_type": "Shirts",
"created_at": null,
"handle": "example-t-shirt",
"updated_at": "2021-07-01T14:08:43-04:00",
"published_at": "2021-07-01T14:08:43-04:00",
"template_suffix": null,
"published_scope": "web",
"tags": "example, mens, t-shirt",
"admin_graphql_api_id": "gid:\/\/shopify\/Product\/788032119674292922",
"variants": [
{
"id": 642667041472713922,
"product_id": 788032119674292922,
"title": "",
"price": "19.99",
"sku": "example-shirt-s",
"position": 0,
"inventory_policy": "deny",
"compare_at_price": "24.99",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "Small",
"option2": null,
"option3": null,
"created_at": null,
"updated_at": null,
"taxable": true,
"barcode": null,
"grams": 200,
"image_id": null,
"weight": 200.0,
"weight_unit": "g",
"inventory_item_id": null,
"inventory_quantity": 75,
"old_inventory_quantity": 75,
"requires_shipping": true,
"admin_graphql_api_id": "gid:\/\/shopify\/ProductVariant\/642667041472713922"
},
{
"id": 757650484644203962,
"product_id": 788032119674292922,
"title": "",
"price": "19.99",
"sku": "example-shirt-m",
"position": 0,
"inventory_policy": "deny",
"compare_at_price": "24.99",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "Medium",
"option2": null,
"option3": null,
"created_at": null,
"updated_at": null,
"taxable": true,
"barcode": null,
"grams": 200,
"image_id": null,
"weight": 200.0,
"weight_unit": "g",
"inventory_item_id": null,
"inventory_quantity": 50,
"old_inventory_quantity": 50,
"requires_shipping": true,
"admin_graphql_api_id": "gid:\/\/shopify\/ProductVariant\/757650484644203962"
}
],
"options": [
{
"id": 527050010214937811,
"product_id": 788032119674292922,
"name": "Title",
"position": 1,
"values": [
"Small",
"Medium"
]
}
],
"images": [
{
"id": 539438707724640965,
"product_id": 788032119674292922,
"position": 0,
"created_at": null,
"updated_at": null,
"alt": null,
"width": 323,
"height": 434,
"src": "\/\/cdn.shopify.com\/shopifycloud\/shopify\/assets\/shopify_shirt-39bb555874ecaeed0a1170417d58bbcf792f7ceb56acfe758384f788710ba635.png",
"variant_ids": [
],
"admin_graphql_api_id": "gid:\/\/shopify\/ProductImage\/539438707724640965"
}
],
"image": null
}
However, whenever I go to test it by actually deleting a product in the Shopify Admin interface, I'm only getting the id in my response. Anybody know why this is happening? My setup for the other webhooks is the exact same and I'm not having any other issues.
Seems like this is an open issue on the shopify_api gem for version 2021-01. I don't think you are doing anything wrong. It looks like nobody has responded in a while to the issue, you might want to try to upgrade to another version to see if they fixed it in any of the newer versions.
EDIT: According to a post from 3/2017 the expected behaviour from deleted endpoints is to only return the ID of the resource that was deleted. This could be why the issue on Github is being ignored.

json data stripe webhook

Im trying to implement stripe webhooks in my rails app. The webhook send this json data.
{ "created": 1326853478, "livemode": false, "id": "evt_00000000000000", "type": "invoice.payment_succeeded", "object": "event", "request": null, "pending_webhooks": 1, "api_version": "2017-06-05", "data": {
"object": {
"id": "in_00000000000000",
"object": "invoice",
"amount_due": 500,
"application_fee": null,
"attempt_count": 1,
"attempted": true,
"charge": "_00000000000000",
"closed": true,
"currency": "usd",
"customer": "cus_00000000000000",
"date": 1501950408,
"description": null,
"discount": null,
"ending_balance": 0,
"forgiven": false,
"lines": {
"data": [
{
"id": "sub_BLXcTSekdHflq5",
"object": "line_item",
"amount": 500,
"currency": "usd",
"description": null,
"discountable": true,
"livemode": true,
"metadata": {
},
"period": {
"start": 1507246341,
"end": 1509924741
},
"plan": {
"id": "Subscriber",
"object": "plan",
"amount": 500,
"created": 1501901993,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {
},
"name": "Subscriber",
"statement_descriptor": "WatchBuddie Stream sub",
"trial_period_days": null
},
"proration": false,
"quantity": 1,
"subscription": null,
"subscription_item": "si_1AyqWnFr5iCt1Tv7n23zDLOM",
"type": "subscription"
}
],
"total_count": 1,
"object": "list",
"url": "/v1/invoices/in_1AnV6yFr5iCt1Tv7PnqZ0EUA/lines"
},
"livemode": false,
"metadata": {
},
"next_payment_attempt": null,
"paid": true,
"period_end": 1501950408,
"period_start": 1501950408,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"subscription": "sub_00000000000000",
"subtotal": 500,
"tax": null,
"tax_percent": null,
"total": 500,
"webhooks_delivered_at": 1501950409
} } }
webhook method
def webhooks
begin
event_json = JSON.parse(request.body.read)
event_object = event_json['data']['object']
#refer event types here https://stripe.com/docs/api#event_types
case event_json['type']
when 'invoice.payment_succeeded'
#Update the total subscription total
#Send in email to the user telling them that they resubbed
logger.debug event_object['lines']['id']
end
My question is how do I get the "id": "sub_BLXcTSekdHflq5" I tried
logger.debug event_object['lines']['id']
It doesn't seem to be working what am I doing wrong? I'm sure its just a syntax thing that I am not understanding.
Thanks for all the help!
Figured it out the lines data was in a hash so you had to iterate over it. This is what I did for anyone who comes across this.
event_object['lines']['data'].each{ |i|
sub_id = i['id']
logger.debug sub_id
}

I m getting json data for title in UTF 8 format, then how solve it?

I am getting this,
"title": "=?UTF-8?Q?=E2=80=9CUber=E2=80=99s_Complicit_Board=E2=80=9D_published_?= =?UTF-8?Q?in_Monday_Note_by_Jean-Louis_Gass=C3=A9e?=", //here
I m receiving following josn data,
{
"updated_at": "2017-06-27 13:45:23",
"user_name": "noreply#medium.com",
"first_name": "",
"last_name": "",
"email": "noreply#medium.com",
"profile_pic": "https://secure.gravatar.com/avatar/1f98a43dd7d8f9568b557c7f03fe854e?s=80&r=g&d=identicon",
"ticket_number": "AAAA-0000-0001",
"id": 2,
"title": "=?UTF-8?Q?=E2=80=9CUber=E2=80=99s_Complicit_Board=E2=80=9D_published_?= =?UTF-8?Q?in_Monday_Note_by_Jean-Louis_Gass=C3=A9e?=",
"created_at": "2017-06-27 13:45:23",
"department_name": "Support",
"priotity_name": "Low",
"priority_color": "#00a65a",
"sla_plan_name": "Low",
"help_topic_name": "Support query",
"ticket_status_name": "Open",
"department_id": 1,
"user_dpt": null,
"attachment": 0,
"overdue_date": "2017-06-27 18:45:23"
},
{
"updated_at": "2017-06-27 13:45:19",
"user_name": "help#teamtreehouse.com",
"first_name": "Treehouse",
"last_name": "",
"email": "help#teamtreehouse.com",
"profile_pic": "https://secure.gravatar.com/avatar/84541406cf3c552347f8e31cef7d32ce?s=80&r=g&d=identicon",
"ticket_number": "AAAA-0000-0000",
"id": 1,
"title": "=?UTF-8?Q?=C2=A0New_skills", // here also
"created_at": "2017-06-27 13:45:19",
"department_name": "Support",
"priotity_name": "Low",
"priority_color": "#00a65a",
"sla_plan_name": "Low",
"help_topic_name": "Support query",
"ticket_status_name": "Open",
"department_id": 1,
"user_dpt": null,
"attachment": 0,
"overdue_date": "2017-06-27 18:45:19"
}
]
}
That is the "encoded-word" encoding from RFC 2047.
There is an online decoder here: http://dogmamix.com/MimeHeadersDecoder/
libetpan can decode it (see mailmime_encoded_word_parse
in https://github.com/dinhviethoa/libetpan/blob/master/src/low-level/mime/mailmime_decode.c). That is pretty heavyweight if you only care about this field. You could write a decoder yourself based on the RFC instead.
You need to decode the title string, so check the below code.
NSString *encodedString =#"?UTF-8?Q?=C2=A0New_skills";
NSData *decodedData = [[NSData alloc] initWithBase64EncodedString: encodedString options:0];
NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];
NSLog(#"%#", decodedString);
NSLog(#"Decoded String: %#",decodedString);

SurveyMonkey: Where is the text of my respondent's response?

I'm new to the SurveyMonkey API and it hasn't been too difficult to get payloads back from API calls, but right now I'm trying to get back what responses a specific respondent gave.
I have a survey which has two respondents, the first question on the survey asks the user to enter three pieces of information: Their Name, an ID and today's date.
So, if I do a call to get_survey_details, I can see the questions just fine. For example
obj.pages[0].questions[0].answers[0].answerid: "xxxxxxxx" //some long ID
obj.pages[0].questions[0].answers[0].text: "Enter Your Name"
obj.pages[0].questions[0].answers[0].type: "row"
There's a couple more pieces of information in that object, like whether the question is visible, etc., but these seem to be the pertinent pieces to the question I have.
So! I make another call to get_responses using the same survey_id and respondent_id (there's only two so actually I get them both).
In the resulting payload I get an array of 2 objects (one to hold each respondents responses). So I look in the first (obj[0]) and I see an array of questions and the respondent id. Fine. I look in the questions array and I see one object for each question and in each of those an answers object.
so that's:
obj[0].questions[0].answers[0].col: "yyyyyy" //some long ID
obj[0].questions[0].answers[0].row: "nnnnnn" //some other long ID
No response text. just this row/col business.
At this point, I'm super-confused (which is like regular confused, but with a cape). Where the heck are the respondents actual responses?
What the heck does "row" and "column" reference? Do I have to do some other API call with the row and/or column in order to get the text of the respondent's response?
I've looked through the documentation (and will continue to do so after posting this) and through stackoverflow to see if anyone else has asked this before. There was one question that came close, but really they were just forgetting to pair 'get_responses' with 'get_survey_details'. I'm doing that, but am still lost as ever. And I don't see any documentation really explaining in detail how this row/column concept works for mapping responses to the text of the response. :/
I know this is a really long-winded question, but I'm just so confused as to how to actually get responses out of this API. :(
Thanks for reading.
The text for a given response should come through under the "text" key. e.g. for a survey that only consists of an essay style question:
{
"status": 0,
"data": [
{
"respondent_id": "123456",
"questions": [
{
"answers": [
{
"text": "This is an essay style answer.",
"row": "0"
}
],
"question_id": "78910"
}
]
}
]
}
"row" and "col" literally reference the row and column of an answer - e.g. in a matrix question, there will be a list of rows for different questions ("what did you think of the hotel?") and ratings ("bad, okay, great") - and each answer is a combination of these. For a regular multiple choice question there will be multiple rows and only one column.
Calling "get_responses" with the correct respondent_id should provide you with the text response that you want. It's only the fixed details of the answer stored in the survey itself you should have to look up (provided in get_survey_details).
Using GET : /surveys/{survey_id}/details, we can get the corresponding question Ids along with the answer Ids.
{
"pages": [
{
"href": "https://api.surveymonkey.net/v3/surveys/87263608/pages/260492760",
"description": "",
"questions": [
{
"sorting": null,
"family": "matrix",
"subtype": "rating",
"required": {
"text": "This question requires an answer.",
"amount": "0",
"type": "all"
},
"answers": {
"rows": [
{
"visible": true,
"text": "",
"position": 1,
"id": "10788526669"
}
],
"choices": [
{
"description": "Not at all likely",
"weight": -100,
"id": "10788526670",
"visible": true,
"is_na": false,
"text": "Not at all likely - 0",
"position": 1
},
{
"description": "",
"weight": -100,
"id": "10788526671",
"visible": true,
"is_na": false,
"text": "1",
"position": 2
},
{
"description": "",
"weight": -100,
"id": "10788526672",
"visible": true,
"is_na": false,
"text": "2",
"position": 3
},
{
"description": "",
"weight": -100,
"id": "10788526673",
"visible": true,
"is_na": false,
"text": "3",
"position": 4
},
{
"description": "",
"weight": -100,
"id": "10788526674",
"visible": true,
"is_na": false,
"text": "4",
"position": 5
},
{
"description": "",
"weight": -100,
"id": "10788526675",
"visible": true,
"is_na": false,
"text": "5",
"position": 6
},
{
"description": "",
"weight": -100,
"id": "10788526676",
"visible": true,
"is_na": false,
"text": "6",
"position": 7
},
{
"description": "",
"weight": 0,
"id": "10788526677",
"visible": true,
"is_na": false,
"text": "7",
"position": 8
},
{
"description": "",
"weight": 0,
"id": "10788526678",
"visible": true,
"is_na": false,
"text": "8",
"position": 9
},
{
"description": "",
"weight": 100,
"id": "10788526679",
"visible": true,
"is_na": false,
"text": "9",
"position": 10
},
{
"description": "Extremely likely",
"weight": 100,
"id": "10788526680",
"visible": true,
"is_na": false,
"text": "Extremely likely - 10",
"position": 11
}
]
},
"visible": true,
"href": "https://api.surveymonkey.net/v3/surveys/87263608/pages/260492760/questions/1044924866",
"headings": [
{
"heading": "How likely is it that you would recommend XYZ to a friend or colleague?"
}
],
"position": 1,
"validation": null,
"id": "1044924866",
"forced_ranking": false
},
{
"sorting": null,
"family": "single_choice",
"subtype": "vertical",
"required": null,
"answers": {
"choices": [
{
"visible": true,
"text": "High Interest",
"position": 1,
"id": "10788529403"
},
{
"visible": true,
"text": "Long process",
"position": 2,
"id": "10788529404"
},
{
"visible": true,
"text": "Low XYZ Amount",
"position": 3,
"id": "10788529405"
},
{
"visible": true,
"text": "Lot of Documents",
"position": 4,
"id": "10788529406"
},
{
"visible": true,
"text": "Bad customer service",
"position": 5,
"id": "10788529407"
}
]
},
"visible": true,
"href": "https://api.surveymonkey.net/v3/surveys/87263608/pages/260492760/questions/1044925207",
"headings": [
{
"heading": "What is the most important issue which we need to address for overall a better service?"
}
],
"position": 2,
"validation": null,
"id": "1044925207",
"forced_ranking": false
}
],
"title": "",
"position": 1,
"id": "260492760",
"question_count": 2
}
],
}
We can use these ids to decipher the answer we get after fetching responses using get response API(Bulk or each respondent).
For eg:,
If my survey has two questions, like
Then after fetching the responses we get a json like this:
{
"total_time": 34,
"href": "https://api.surveymonkey.net/v3/collectors/94630092/responses/5120000552",
"custom_variables": {},
"ip_address": "182.76.20.30",
"id": "5120000552",
"logic_path": {},
"date_modified": "2016-12-01T11:01:11+00:00",
"response_status": "completed",
"custom_value": "LAI100023",
"analyze_url": "http://www.surveymonkey.com/analyze/browse/EvaBWWcU9K1XTH_2FFFBTfFul4ge94MwVWvBk0eAFDJ3c_3D?respondent_id=5120000552",
"pages": [
{
"id": "260492760",
"questions": [
{
"id": "1044924866",
"answers": [
{
"choice_id": "10788526677",
"row_id": "10788526669"
}
]
},
{
"id": "1044925207",
"answers": [
{
"choice_id": "10788529404"
}
]
}
]
}
],
"page_path": [],
"recipient_id": "2743199128",
"collector_id": "94630092",
"date_created": "2016-12-01T11:00:37+00:00",
"survey_id": "87263608",
"collection_mode": "default",
"edit_url": "http://www.surveymonkey.com/r/?sm=SfTljxZSoBFvaRUeGSI6L813qctjfG_2FDCVcqCks7CDc4TcJC_2BNHqmPYD7NNTcvST",
"metadata": {
"contact": {
"first_name": {
"type": "string",
"value": "John"
},
"last_name": {
"type": "string",
"value": "Doe"
},
"email": {
"type": "string",
"value": "neeta#xyz.com"
}
}
}
}
We can map the questions and answers using their IDs in this response with the ids we got from survey details. For open ended text questions, we get direct typed responses.

Render json to Grails domain list object

If there is one record in request.json the below code works
class BookController {
def save = {
def book = new Book(JSON.parse(yourJson))
book.save(flush:true)
}
}
But how to get bookList if there is multiple records in my request.JSON like:
[{
"id": 3,
"name": "MYNAME",
"description": "test",
"category": 1,
"venue": null,
"status": "Published",
"deleted": false,
"pricingPolicy": null
}, {
"id": 6,
"name": "YZ",
"description": "test6",
"category": 2,
"venue": null,
"status": "Unpublished",
"deleted": false,
"pricingPolicy": null
}, {
"id": 9,
"name": "YZ",
"description": "test6",
"category": 1,
"venue": null,
"status": "Published",
"deleted": false,
"pricingPolicy": null
}]
request.JSON.each{ new Book( it ).save() }
should do

Resources