{"action":"created","issue":{"url":"https://api.github.com/repos/MLSDev/TRON/issues/36","repository_url":"https://api.github.com/repos/MLSDev/TRON","labels_url":"https://api.github.com/repos/MLSDev/TRON/issues/36/labels{/name}","comments_url":"https://api.github.com/repos/MLSDev/TRON/issues/36/comments","events_url":"https://api.github.com/repos/MLSDev/TRON/issues/36/events","html_url":"https://github.com/MLSDev/TRON/issues/36","id":230047073,"number":36,"title":"Submitting JSON as body?","user":{"login":"justindunn","id":1703225,"avatar_url":"https://avatars0.githubusercontent.com/u/1703225?v=3","gravatar_id":"","url":"https://api.github.com/users/justindunn","html_url":"https://github.com/justindunn","followers_url":"https://api.github.com/users/justindunn/followers","following_url":"https://api.github.com/users/justindunn/following{/other_user}","gists_url":"https://api.github.com/users/justindunn/gists{/gist_id}","starred_url":"https://api.github.com/users/justindunn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justindunn/subscriptions","organizations_url":"https://api.github.com/users/justindunn/orgs","repos_url":"https://api.github.com/users/justindunn/repos","events_url":"https://api.github.com/users/justindunn/events{/privacy}","received_events_url":"https://api.github.com/users/justindunn/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-05-19T18:04:37Z","updated_at":"2017-05-21T16:17:59Z","closed_at":"2017-05-21T16:17:59Z","body":"I'm trying to submit a JSON post to my local dev server and having issues. I haven't seen much documentation on sending complex parameters or JSON in the body for a POST request in the documentation (unless I'm missing something). I've been browsing through issues with no success unfortunately on how to get this to work, I have a complex bit of JSON that I need to send in a .POST request to my Rails API. Here is the code for sending the JSON\r\n\r\n     `@IBAction func SessionSubmit(_ sender: Any) {\r\n        let selected_session_type = session_type_ids[self.SessionTypePicker.selectedRow(inComponent: 0)]\r\n        let selected_session_duration = session_type_durations[self.SessionTypePicker.selectedRow(inComponent: 0)]\r\n        let dateFormatter = DateFormatter()\r\n        let selected_start_time = DateTimePicker.date\r\n        let start_time = dateFormatter.string(from: DateTimePicker.date)\r\n        let end_time = dateFormatter.string(from: selected_start_time + selected_session_duration.minutes)\r\n        let refreshToken = current_user.refreshToken as String\r\n        let accessToken = current_user.accessToken as String\r\n        let params: [String: Any] = [\"access_token\": accessToken, \"refresh_token\": refreshToken]\r\n        let body: [String: Any] = [\"data\": [\r\n                        \"type\": \"session\",\r\n                        \"attributes\": [\r\n                            \"title\": \"\",\r\n                            \"description\": \"\",\r\n                            \"start\": start_time,\r\n                            \"end\": end_time,\r\n                            \"session_mode\": \"video_session\"],\r\n                            \"relationships\": [\r\n                                \"users\": [\r\n                                    \"data\": [\r\n                                        [\"type\": \"user\",\r\n                                         \"id\": current_user.userId],\r\n                                        [\"type\": \"user\",\r\n                                         \"id\": clientId]\r\n                                    ]\r\n                                ],\r\n                                \"session_type\":[\r\n                                    \"data\": [\r\n                                        \"type\": \"session_type\",\r\n                                        \"id\": selected_session_type\r\n                                        ]\r\n                                    ]\r\n                                ]\r\n                            ]\r\n                        ]\r\n        do {\r\n            let jsonData = try JSONSerialization.data(withJSONObject: body, options: .prettyPrinted)\r\n            print(jsonData)\r\n            let decoded = try JSONSerialization.jsonObject(with: jsonData, options: [])\r\n            print(decoded)\r\n            \r\n            if let dictFromJSON = decoded as? [String:Any] {\r\n                print(dictFromJSON)\r\n                self.sendData(parameters: params, body: dictFromJSON) {\r\n                    self.stopAnimating()\r\n                }\r\n            }\r\n        } catch {\r\n            print(error.localizedDescription)\r\n        }\r\n        startAnimating(GlobalVariables().LoadingSize)`\r\n\r\n       `    func sendData(parameters: [String:Any], body: [String:Any], finished: @escaping () -> Void) {\r\n        DataController().Post(parameters: parameters, path: \"/v1/sessions/\"+current_user.userId).perform(withSuccess: { (FetchedArray) in\r\n            if let SessionTypesArray = FetchedArray.response[\"data\"].array {\r\n                self.session_types += SessionTypesArray \r\n            }\r\n            finished()\r\n        }) { (FetchFailed) in\r\n            AuthenticationController().logout(user: self.current_user)\r\n            self.dismiss(animated: true, completion: {});\r\n            finished()\r\n        }\r\n    }`\r\n\r\nI'm thinking maybe I need to make these embedded in the document and only have my refresh and access tokens as parameters? so I tried working on doing it that way and yet still another road block because of not seeing any ways to add to the body, I know there is appendBody but I'm not sure how that would work either, the json seems to not be flowing to the rails api correctly either \r\n`Started POST \"/v1/sessions/122\" for 127.0.0.1 at 2017-05-19 13:52:32 -0400\r\nError occurred while parsing request parameters.\r\nContents:\r\n\r\naccess_token=90d2befd58912f978dc681f2f0d1eaf3d217dbe25fdac3d1ec4ab45e9bfff41a&data%5Btype%5D=session&data%5Battributes%5D%5Bdescription%5D=&data%5Battributes%5D%5Btitle%5D=&data%5Battributes%5D%5Bend%5D=&data%5Battributes%5D%5Bsession_mode%5D=video_session&data%5Battributes%5D%5Bstart%5D=&data%5Brelationships%5D%5Bsession_type%5D%5Bdata%5D%5Btype%5D=session_type&data%5Brelationships%5D%5Bsession_type%5D%5Bdata%5D%5Bid%5D=379&data%5Brelationships%5D%5Busers%5D%5Bdata%5D%5B%5D%5Btype%5D=user&data%5Brelationships%5D%5Busers%5D%5Bdata%5D%5B%5D%5Bid%5D=122&data%5Brelationships%5D%5Busers%5D%5Bdata%5D%5B%5D%5Btype%5D=user&data%5Brelationships%5D%5Busers%5D%5Bdata%5D%5B%5D%5Bid%5D=6&refresh_token=6b60a52534e1fa2ed436a9542a6c27b7f05e56e7b306f48df12b286b8fe5f624\r\n\r\nJSON::ParserError - 822: unexpected token at 'access_token=90d2befd58912f978dc681f2f0d1eaf3d217dbe25fdac3d1ec4ab45e9bfff41a&data%5Btype%5D=session&data%5Battributes%5D%5Bdescription%5D=&data%5Battributes%5D%5Btitle%5D=&data%5Battributes%5D%5Bend%5D=&data%5Battributes%5D%5Bsession_mode%5D=video_session&data%5Battributes%5D%5Bstart%5D=&data%5Brelationships%5D%5Bsession_type%5D%5Bdata%5D%5Btype%5D=session_type&data%5Brelationships%5D%5Bsession_type%5D%5Bdata%5D%5Bid%5D=379&data%5Brelationships%5D%5Busers%5D%5Bdata%5D%5B%5D%5Btype%5D=user&data%5Brelationships%5D%5Busers%5D%5Bdata%5D%5B%5D%5Bid%5D=122&data%5Brelationships%5D%5Busers%5D%5Bdata%5D%5B%5D%5Btype%5D=user&data%5Brelationships%5D%5Busers%5D%5Bdata%5D%5B%5D%5Bid%5D=6&refresh_token=6b60a52534e1fa2ed436a9542a6c27b7f05e56e7b306f48df12b286b8fe5f624':\r\n  json (1.8.6) lib/json/common.rb:155:in `parse'`\r\n\r\n\r\nany help here would be greatly appreciated guys! thanks in advance!"},"comment":{"url":"https://api.github.com/repos/MLSDev/TRON/issues/comments/302946600","html_url":"https://github.com/MLSDev/TRON/issues/36#issuecomment-302946600","issue_url":"https://api.github.com/repos/MLSDev/TRON/issues/36","id":302946600,"user":{"login":"justindunn","id":1703225,"avatar_url":"https://avatars0.githubusercontent.com/u/1703225?v=3","gravatar_id":"","url":"https://api.github.com/users/justindunn","html_url":"https://github.com/justindunn","followers_url":"https://api.github.com/users/justindunn/followers","following_url":"https://api.github.com/users/justindunn/following{/other_user}","gists_url":"https://api.github.com/users/justindunn/gists{/gist_id}","starred_url":"https://api.github.com/users/justindunn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justindunn/subscriptions","organizations_url":"https://api.github.com/users/justindunn/orgs","repos_url":"https://api.github.com/users/justindunn/repos","events_url":"https://api.github.com/users/justindunn/events{/privacy}","received_events_url":"https://api.github.com/users/justindunn/received_events","type":"User","site_admin":false},"created_at":"2017-05-21T16:17:59Z","updated_at":"2017-05-21T16:17:59Z","body":"Awesome, I think that got it, now I'm having an authentication issue with our server, but I don't think it has anything to do with what we were trying to solve, thanks again for all your help!"}}
{"actor":{"display_login":"justindunn"}}