{"action":"created","issue":{"url":"https://api.github.com/repos/planningcenter/developers/issues/126","labels_url":"https://api.github.com/repos/planningcenter/developers/issues/126/labels{/name}","comments_url":"https://api.github.com/repos/planningcenter/developers/issues/126/comments","events_url":"https://api.github.com/repos/planningcenter/developers/issues/126/events","html_url":"https://github.com/planningcenter/developers/issues/126","id":126809929,"number":126,"title":"Is there a better way to retrieve songs from recent plans","user":{"login":"mcolinburch","id":8196872,"avatar_url":"https://avatars.githubusercontent.com/u/8196872?v=3","gravatar_id":"","url":"https://api.github.com/users/mcolinburch","html_url":"https://github.com/mcolinburch","followers_url":"https://api.github.com/users/mcolinburch/followers","following_url":"https://api.github.com/users/mcolinburch/following{/other_user}","gists_url":"https://api.github.com/users/mcolinburch/gists{/gist_id}","starred_url":"https://api.github.com/users/mcolinburch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcolinburch/subscriptions","organizations_url":"https://api.github.com/users/mcolinburch/orgs","repos_url":"https://api.github.com/users/mcolinburch/repos","events_url":"https://api.github.com/users/mcolinburch/events{/privacy}","received_events_url":"https://api.github.com/users/mcolinburch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-15T05:23:37Z","updated_at":"2016-01-15T15:46:14Z","closed_at":null,"body":"Hello, \r\nI am working on a widget to to include on our website & possibly in our mobile app. We would like to display a list of songs we've played grouped by plan date. Something like this:\r\n\r\n>**Jan 10, 2016**\r\n> - Song 1 title, author, copyright, YouTube link \r\n> - Song 2 title, author, copyright, YouTube link\r\n> - Song 3 title, author, copyright, YouTube link\r\n> - Song 4 title, author, copyright, YouTube link\r\n>\r\n> **Jan 3, 2016**\r\n> - Song 5 title, author, copyright, YouTube link \r\n> - Song 6 title, author, copyright, YouTube link\r\n> - Song 7 title, author, copyright, YouTube link\r\n> - Song 8 title, author, copyright, YouTube link\r\n\r\nI have my PHP code working with the PCO API using a personal app id, but it's a bit slow because my code is quite inefficient at the moment. Here is the basic logic I am using - I am hoping there is a better (faster) way to create this list.\r\n\r\nTo start I am returning the JSON data using this call:\r\nhttps://api.planningcenteronline.com/services/v2/service_types/xxxxx/plans?filter=past\r\n\r\nHowever, this returns almost 400 rows and we only want to return the 5 most recent plans.\r\n\r\nTo do this, I am using a very inelegant hack to determine the total number of past plans, then utilizing the **\"offset=XX\"** query string to return the last 5 services.\r\n\r\nAlso, the JSOn returned is listed in ascending order. Is there a way to sort the list in descending order by the ['last_time_at'] attribute? I am resorting the data by dumping the JSON into an array and doing a \"usort\" on the array.\r\n\r\nNow I begin looping through the array of plans, grab the plan ID and make this call to get the plan items:\r\nhttps://api.planningcenteronline.com/services/v2/service_types/57941/plans/xxxxxxx/items?include=song\r\n\r\nThe return list is all item types (not just songs), so I might be using the **include=song** querystring incorrectly. Because it returns **all** plan items, I loop through the item data and only grab the records where **['attributes']['item_type']==\"song\"**.\r\n\r\nI again dump the JSON into an array and perform **another** nested loop and I make **another** API call:\r\nhttps://api.planningcenteronline.com/services/v2/songs/\"xxxxxx\r\n\r\nNow I loop thru the song data and get the title, author & copyright info. I build a new array with the collected data that I will use to write HTML and create a stylized list.\r\n\r\nI still yet need to code a way to work through to the various arrangements & attachments API calls, test if there may be a YouTube attachment and save in my new array if it does. This will require several more API calls.\r\n\r\nMy biggest concern is that the script take almost 10 seconds to execute. It's because of all of the **multiple** nested looping and **multiple** API calls. It's quite ugly, but it is pulling the data we need. I just can't help thinking there has to be a better way than what I have cobbled together.\r\n\r\nThis is my first time working with the PCO API, so I have no doubt I am making this more difficult than it needs to be.\r\n\r\nDoes anyone have any suggestions, advice or hints they might be able to offer?\r\n\r\nFWIW: here is the URL of the returned array:\r\nhttp://salemfields.com/mobile/pco/index.php\r\nThis is data I will use later to create a stylized HTML list. It's still missing the YouTube attachment link.\r\n\r\nThanks so much!\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/planningcenter/developers/issues/comments/171996082","html_url":"https://github.com/planningcenter/developers/issues/126#issuecomment-171996082","issue_url":"https://api.github.com/repos/planningcenter/developers/issues/126","id":171996082,"user":{"login":"seven1m","id":669,"avatar_url":"https://avatars.githubusercontent.com/u/669?v=3","gravatar_id":"","url":"https://api.github.com/users/seven1m","html_url":"https://github.com/seven1m","followers_url":"https://api.github.com/users/seven1m/followers","following_url":"https://api.github.com/users/seven1m/following{/other_user}","gists_url":"https://api.github.com/users/seven1m/gists{/gist_id}","starred_url":"https://api.github.com/users/seven1m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seven1m/subscriptions","organizations_url":"https://api.github.com/users/seven1m/orgs","repos_url":"https://api.github.com/users/seven1m/repos","events_url":"https://api.github.com/users/seven1m/events{/privacy}","received_events_url":"https://api.github.com/users/seven1m/received_events","type":"User","site_admin":false},"created_at":"2016-01-15T15:46:14Z","updated_at":"2016-01-15T15:46:14Z","body":"@mcolinburch Would the following parameters get you closer to what you want?\r\n\r\n```\r\nhttps://api.planningcenteronline.com/services/v2/service_types/xxxxx/plans?filter=past&order=-created_at&per_page=5\r\n```"}}