How can I programmatically generate a new Google Sheet in Swift 4 using Sheets API v4?

I’m having trouble generating a new Google Sheet with Swift 4 utilizing the Sheets API. I want to ensure that I can reference this newly created sheet later in my application, which means I need it to return the spreadsheet ID. Here’s the current code I am working with:

func generateSpreadsheet() {

    let requestURL = NSURL(string: "https://sheets.googleapis.com/v4/spreadsheets")

    let dataTask = URLSession.shared.dataTask(with: requestURL! as URL) {
        (receivedData, receivedResponse, requestError) in
        print(NSString(data: receivedData!, encoding: String.Encoding.utf8.rawValue)!)
    }
    dataTask.resume()
    print(dataTask)
}

Hey HappyDancer99, you probably need to structure your JSON request body correctly. You should include an authorization header with your API key too. Also, try handling the response more accurately to extract your spreadsheetID. Sometimes it’s jus’ these small things that fix stuff. Good luck!