Process json result from Twilio - twilio

I currently retrieve the alerts for voice and sms messages from Twilio as a json column. using this tsql code,
SELECT [ReceivedDateTime]
,MsgSid = JSON_VALUE(payload, '$.resource_sid')
,WebhookURL = JSON_VALUE(payload, '$.webhook.request.url')
,ToState = JSON_VALUE(payload, '$.webhook.request.parameters.ToState')
,AlertTime = JSON_VALUE(payload, '$.webhook.request.parameters.Timestamp')
,Direction = JSON_VALUE(payload, '$.webhook.request.parameters.Direction')
,SequenceNumber = JSON_VALUE(payload, '$.webhook.request.parameters.SequenceNumber')
,ToNumber = JSON_VALUE(payload, '$.webhook.request.parameters.To')
,ToCity = JSON_VALUE(payload, '$.webhook.request.parameters.ToCity')
,CallStatus = JSON_VALUE(payload, '$.webhook.request.parameters.CallStatus')
,FromNumber = JSON_VALUE(payload, '$.webhook.request.parameters.From')
,AccountSid = JSON_VALUE(payload, '$.webhook.request.parameters.AccountSid')
,TwilioReason = JSON_VALUE(payload, '$.response.headers.X-Twilio-Reason')
,AlertDate = JSON_VALUE(payload, '$.webhook.response.headers.Date')
FROM [dbo].[TwilioAlerts]
I can query this file until I get to the section that contains a dash in the name. Trying to pull in the X-Twilio-Reason, I get the error: JSON path is not properly formatted. Unexpected character '-' is found at position 20. How can I reference this in tsql?
This is the json I trying to query:
{
"resource_sid": "",
"service_sid": null,
"error_code": "15003",
"more_info": {
"Msg": "HTTP retrieval failure",
"statusCallback": "",
"ErrorCode": "15003",
"LogLevel": "WARN"
},
"webhook": {
"type": "application/json",
"request": {
"url": "",
"method": "POST",
"headers": {},
"parameters": {
"Called": "+",
"ToState": "TX",
"CallerCountry": "US",
"Timestamp": "Fri, 22 Nov 2019 14:33:23 +0000",
"Direction": "outbound-api",
"CallbackSource": "call-progress-events",
"CallerState": "TX",
"ToZip": "78742",
"SequenceNumber": "1",
"CallSid": "",
"To": "+",
"CallerZip": "",
"ToCountry": "US",
"CalledZip": "",
"ApiVersion": "2010-04-01",
"CalledCity": "",
"CallStatus": "ringing",
"From": "+",
"AccountSid": "",
"CalledCountry": "US",
"CallerCity": "",
"ToCity": "AUSTIN",
"Caller": "+",
"FromCountry": "US",
"FromCity": "",
"CalledState": "TX",
"FromZip": "",
"FromState": "TX"
}
},
"response": {
"status_code": null,
"headers": {
"X-Twilio-WebhookAttempt": "1",
"X-Twilio-Reason": "Response does not contain content type",
"Content-Length": "464",
"Date": "Fri, 22 Nov 2019 14:33:23 GMT",
"Content-Type": "text/html"
},
"body":"Twilio was unable to fetch content from: https://appointmentwave.com/ProdAWHandler/events/voice\nError: Error reading response: Response does not contain content type\nAccount SID: ACc9eea08b61d774d5dfc07c91aa690466\nSID: CA6e2b878c4e1e5d2ec3733d52b2c2b2fa\nRequest ID: 6ae4e44b-f6cb-4ca3-a057-6067024f943a\nRemote Host: appointmentwave.com\nRequest Method: POST\nRequest URI: https://appointmentwave.com/ProdAWHandler/events/voice\nSSL
Version: TLSv1.2\nURL Fragment: true"}}}
Any answer as to how to pull "X-Twilio-Reason" ?

Try adding double-quotes around the section with dashes in the name.
,TwilioReason = JSON_VALUE(payload, '$.response.headers."X-Twilio-Reason"')

Related

Paypal sandbox cancel webhook not working

The webhook for a subscription activation BILLING.SUBSCRIPTION.ACTIVATED in the Paypal's sandbox works very well.
Nevertheless, when I'm trying to cancel the subscription from a customer sandbox account, no webhook post is received.
It should be BILLING.SUBSCRIPTION.CANCELLED.
In fact, the status is "pending" from the sandbox admin account:
Does it wait until the subscription's end date in order to send the cancellation?
Or does it wait a few hours for safety reasons?
Here are the details from the paypal sandbox web site:
{
"id": "WH-3BV96304FY002321K-38Y64104YL460680C",
"create_time": "2022-07-04T17:51:34.874Z",
"resource_type": "subscription",
"event_type": "BILLING.SUBSCRIPTION.CANCELLED",
"summary": "Subscription cancelled",
"resource": {
"quantity": "1",
"subscriber": {
"email_address": "valid_adress#yahoo.fr",
"payer_id": "X3FWGFE2SAXUL",
"name": {
"given_name": "Anyname",
"surname": "Walker"
},
"shipping_address": {
"address": {
"address_line_1": "Great st 25",
"admin_area_2": "New York",
"admin_area_1": "NY",
"postal_code": "10002",
"country_code": "US"
}
}
},
"create_time": "2022-07-04T17:49:00Z",
"plan_overridden": false,
"shipping_amount": {
"currency_code": "USD",
"value": "0.0"
},
"start_time": "2022-07-04T17:46:51Z",
"update_time": "2022-07-04T17:51:25Z",
"billing_info": {
"outstanding_balance": {
"currency_code": "USD",
"value": "0.0"
},
"cycle_executions": [
{
"tenure_type": "REGULAR",
"sequence": 1,
"cycles_completed": 1,
"cycles_remaining": 0,
"current_pricing_scheme_version": 1,
"total_cycles": 0
}
],
"last_payment": {
"amount": {
"currency_code": "USD",
"value": "3.99"
},
"time": "2022-07-04T17:49:01Z"
},
"failed_payments_count": 0
},
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-6BR7NSX98KLF",
"rel": "self",
"method": "GET",
"encType": "application/json"
}
],
"id": "I-6BR7NSX98KLF",
"plan_id": "P-5XR3459593FMK2CYGA",
"status": "CANCELLED",
"status_update_time": "2022-07-04T17:51:25Z"
},
"status": "PENDING",
"transmissions": [
{
"webhook_url": "https://www.myapp.com/webhook",
"http_status": 440,
"reason_phrase": "HTTP/1.1 200 Connection established",
"response_headers": {
"Server": "gunicorn",
"Connection": "keep-alive",
"Content-Length": "5",
"Date": "Mon, 04 Jul 2022 18:15:52 GMT",
"Content-Type": "text/html; charset=utf-8",
"Via": "1.1 google"
},
"transmission_id": "02cba350-fbc2-9abc-d537a3be4540",
"status": "PENDING",
"timestamp": "2022-07-04T17:52:03Z"
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-3BV96304FY002321K-38Y64104YL460680C",
"rel": "self",
"method": "GET",
"encType": "application/json"
},
{
"href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-3BV96304FY002321K-38Y64104YL460680C/resend",
"rel": "resend",
"method": "POST",
"encType": "application/json"
}
],
"event_version": "1.0",
"resource_version": "2.0"
}
Pending means pending delivery to the subscribed webhook URL. The event ocurred, and delivery to the URL was attempted, but that URL did not respond with an HTTP 200 success message for the webhook to be marked as successfully delivered. In fact, according to the details logged in your question:
"webhook_url": "https://www.myapp.com/webhook",
"http_status": 440,
That URL instead responded with an HTTP 440 status
Assuming the URL is correct and that you changed it to "myapp" for this question, the issue is that you need to debug the endpoint/code at that URL so that it responds with a 200 success status when webhook deliveries are posted to it. Then their status will stop being Pending.

Bad Request "ErrorExecuteSearchStaleData" in Microsoft Graph API - Search for Mails

We are using Microsoft Graph Search API to search through our O365 emails. Since the search only allows 25 results per request for mails. (see https://learn.microsoft.com/en-us/graph/api/resources/search-api-overview?view=graph-rest-beta#page-search-results)
We figured to work around this by batching our search request like this:
POST https://graph.microsoft.com/beta/$batch
{
"requests": [
{
"url": "/search/query",
"method": "POST",
"id": "MyMails-0",
"body":
{
"requests": [
{
"entityTypes": ["message"],
"query":
{
"query_string":
{
"query": "some search text"
}
},
"from": 0,
"size": 25
}
]
},
"headers":
{
"Content-Type": "application/json"
}
},
{
"url": "/search/query",
"method": "POST",
"id": "MyMails-1",
"body":
{
"requests": [
{
"entityTypes": ["message"],
"query":
{
"query_string":
{
"query": "some search text"
}
},
"from": 25,
"size": 25
}
]
},
"headers":
{
"Content-Type": "application/json"
}
},
{
"url": "/search/query",
"method": "POST",
"id": "MyMails-2",
"body":
{
"requests": [
{
"entityTypes": ["message"],
"query":
{
"query_string":
{
"query": "some search text"
}
},
"from": 50,
"size": 25
}
]
},
"headers":
{
"Content-Type": "application/json"
}
},
{
"url": "/search/query",
"method": "POST",
"id": "MyMails-3",
"body":
{
"requests": [
{
"entityTypes": ["message"],
"query":
{
"query_string":
{
"query": "some search text"
}
},
"from": 75,
"size": 25
}
]
},
"headers":
{
"Content-Type": "application/json"
}
}
]
}
This works usually well, but in some cases the API returns something like this:
{
"id": "MyMails-2",
"status": 400,
"headers":
{
"Link": "<https://developer.microsoft-tst.com/en-us/graph/changes?$filterby=beta,RemoveDeprecatedUnderscoreProperty&from=2021-12-01&to=2022-01-01>;rel=\"deprecation\";type=\"text/html\",<https://developer.microsoft-tst.com/en-us/graph/changes?$filterby=beta,RemoveDeprecatedUnderscoreProperty&from=2021-12-01&to=2022-01-01>;rel=\"deprecation\";type=\"text/html\",<https://developer.microsoft-tst.com/en-us/graph/changes?$filterby=beta,RemoveDeprecatedUnderscoreProperty&from=2021-12-01&to=2022-01-01>;rel=\"deprecation\";type=\"text/html\"",
"Deprecation": "Tue, 14 Dec 2021 23:59:59 GMT",
"Sunset": "Sat, 31 Dec 2022 23:59:59 GMT",
"Cache-Control": "no-cache",
"Content-Type": "application/json"
},
"body":
{
"error":
{
"code": "BadRequest",
"message": "\r\n An exception occurred\r\n Lss call failed with status code 400. \"Exchange service returned error ErrorExecuteSearchStaleData: Please reissue the query with rowOffset = 0. The specified rowoffset is '50', but the results are stale.\".",
"innerError":
{
"date": "2022-01-25T09:58:53",
"request-id": "75def95f-a857-427d-a8b4-ee2792329e87",
"client-request-id": "75def95f-a857-427d-a8b4-ee2792329e87"
}
}
}
}
I noticed the deprecation note in the header, however I can't find anything about it. Neither about the actual exception.
What am I missing?
[workaround]
Thanks for the hint #user2250152.
This heavily reduced the issue by splitting the request into two requests, while the second is able to request more than 25 mails at a time:
POST https://graph.microsoft.com/beta/$batch
{
"requests": [
{
"url": "/search/query",
"method": "POST",
"id": "MyMails-0",
"body": {
"requests": [
{
"entityTypes": [
"message"
],
"query": {
"query_string": {
"query": "some search text"
}
},
"from": 0,
"size": 25
}
]
},
"headers": {
"Content-Type": "application/json"
}
},
{
"url": "/search/query",
"method": "POST",
"id": "MyMails-1",
"body": {
"requests": [
{
"entityTypes": [
"message"
],
"query": {
"query_string": {
"query": "some search text"
}
},
"from": 25,
"size": 200
}
]
},
"headers": {
"Content-Type": "application/json"
}
}
]
}
The error with stale results can happen time to time.
You can decrease the number of batch requests to reduce a chance that the error with stale results will occur.
For the first page "from": 0 the max size is 25. But for the next page "from": 25 you can increase the page size to 200.
I've tested the search query with "from": 25 and "size": 200 and it returns 200 results.
Resources:
Page search results

Reply sent email by Gmail API

Currently I'm trying to create send and reply using gmail api, in documentation here
Refernces and In-Reply-To must be set in compliance with the RFC 2822 standard, the problem is when I try to get References and In-Reply-To from specified id like below:
`{
"id": "16183e0822247c79",
"threadId": "16183e0822247c79",
"labelIds": [
"SENT"
],
"snippet": "terkait",
"historyId": "1640387",
"internalDate": "1518335984000",
"payload": {
"partId": "",
"mimeType": "multipart/mixed",
"filename": "",
"headers": [
{
"name": "Received",
"value": "from 1059028371380 named unknown by gmailapi.google.com with HTTPREST; Sat, 10 Feb 2018 23:59:44 -0800"
},
{
"name": "Date",
"value": "Sat, 10 Feb 2018 23:59:44 -0800"
},
{
"name": "From",
"value": "jaisanas2#gmail.com"
},
{
"name": "To",
"value": "jaisanas3#gmail.com"
},
{
"name": "Message-Id",
"value": "\u003cCA+8aSZeXMOETdH8NYtd18UWk5eiQnvT0oEnEWy_1HL6mJPuKjw#mail.gmail.com\u003e"
},
{
"name": "Subject",
"value": "terkait"
},
{
"name": "Mime-Version",
"value": "1.0"
},
{
"name": "Content-Type",
"value": "multipart/mixed; boundary=\"--==_mimepart_5a7ff7f050e3_3263ffa0ceb1cc020ea\"; charset=UTF-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "7bit"
}
],
"body": {
"size": 0
},
"parts": [
{
"partId": "0",
"mimeType": "multipart/alternative",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "multipart/alternative; boundary=\"--==_mimepart_5a7ff7f05063_3263ffa0ceb1cc01916\"; charset=UTF-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "7bit"
}
],
"body": {
"size": 0
},
"parts": [
{
"partId": "0.0",
"mimeType": "text/html",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/html; charset=UTF-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "7bit"
}
],
"body": {
"size": 14,
"data": "PHA-dGVya2FpdDwvcD4="
}
}
]
}
]
},
"sizeEstimate": 929
}`
When you see the result there are no headers In-Reply-To and Refernces, my questions is it is possible to reply email using API ?
Here is my code in ruby:
client = google_client user_id
token = Token.find_by_user_id(user_id)
access_token = token.access_token
gmail = Google::Apis::GmailV1::GmailService.new
gmail.authorization = client
message = Mail.new
message.date = Time.now
message.subject = "Re: #{subject}"
message.from = token.email
message.to = "#{to}"
# message.thread_id = "#{thread_id}"
message.message_id = "\u003cCA+8aSZeXMOETdH8NYtd18UWk5eiQnvT0oEnEWy_1HL6mJPuKjw#mail.gmail.com\u003e"
message.part content_type: 'multipart/alternative' do |part|
part.html_part = Mail::Part.new(body: "#{body}", content_type: 'text/html; charset=UTF-8')
end
msg = message.encoded
message_object = Google::Apis::GmailV1::Message.new(raw:message.to_s, thread_id: thread_id, content_type: 'message/rfc822')
gmail.send_user_message('me', message_object)
This code successfully send email in the same thread, but not reply email, here is what looks like inside my gmail sent emails:
As you can see, message with body lauv does not reply message terkait instead I just sent email lauv, my question is how to reply email?
Here you need to set In-Reply-To and References headers. If there is only one email in the thread use the message_id as In-Reply-To and References

How to send this type of parameter to server call in swift 3.0

I need to send this below parameters to a server in swift 3.0. How can I build the request parameters?
"step_1": [
{
"name": "",
"mobile": "",
"line_1": "",
"line_2": "",
"city": "",
"state": "",
"pincode": "",
"fax": "",
"gst": "",
"owner_name": "",
"dob": "",
"anniversary": ""
}
]
For upper json data below is Dictionary code:
let param = [["name": "abc",
"mobile": "123",
"line_1": "line_1",
"line_2": "line_2",
"city":"xyz",
"state":"abc",
"pincode":"000",
"fax":"123",
"gst":"gst",
"ownwer_name":"ownwer_name",
"dob":"xx-xx-xxxx",
"anniversary":"xx-xx-xxxx"]]
//Print data
print(param[0]["name"] as! String)
Hi I'm not sure if it will work, but anyway, try this
let params: ["step_1": [["name": "Some name",
"mobile": "12345678",
"line_1": "line_1 stuff",
"...": "..."]]]

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

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"];

Resources