title: When retrieving a Stripe invoice from their API, how do I expand an object to retrieve credit card details and other info?
body: <p>I have a Google Apps Script that accesses the Stripe API and retrieves data from a Stripe invoice <a href="https://stripe.com/docs/api/invoices/retrieve" rel="nofollow noreferrer">reference</a> and adds the data to a Google Sheet. </p>
  
  <p>Stripe mentioned that I can expand an object to get more info <a href="https://stripe.com/docs/api/expanding_objects" rel="nofollow noreferrer">expanding an object reference</a>. But I'm fairly new to using APIs so I'm not sure how to do this. </p>
  
  <p>I think the reason I'm stuck is because I'm pulling the invoice data from a URL (i.e. <a href="https://api.stripe.com/v1/invoices/xxxxxxxxxxxxxxxxxxxxxxxxxx" rel="nofollow noreferrer">https://api.stripe.com/v1/invoices/xxxxxxxxxxxxxxxxxxxxxxxxxx</a>). I'm not sure how to modify the URL to expand an object (or where I should do this in the code below).</p>
  
  <p>For example, I want to expand the "Charge" object to include more details about the payment. Data I'd want to get from the charge object would be the card type (ex: Visa), expiry, last four digits. I would likely do the same thing with the Customer object, to access customer details regarding the invoice.</p>
  
  <p>Here's the Google Apps Script I'm using right now:</p>
  
  <pre><code>function onOpen() {
    var ui = SpreadsheetApp.getUi();
    ui.createMenu('Stripe')
      .addItem('Retrieve Invoice Data','getInvoiceObj')
      .addToUi();
  }
  
  function getInvoiceObj() 
    {
      var apiKey, content, options, response, secret, url;
  
      //API Key
      secret = "rk_live_xxxxxxxxxxxxxxxxxxxxxxxxxx";
      apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
  
      //Stripe API invoice URL 
      url = "https://api.stripe.com/v1/invoices/xxxxxxxxxxxxxxxxxxxxxxxxxx";
  
  
      options = {
        "method" : "GET",
        "headers": {
          "Authorization": "Bearer " + secret 
        },
        "muteHttpExceptions":true
      };
  
      response = UrlFetchApp.fetch(url, options);
  
      //Push data to Sheet from invoice. **Writes over existing Sheet data**
      content = JSON.parse(response.getContentText());
      var sheet = SpreadsheetApp.getActiveSheet();
  
      //Retrieves currency type and adds to Sheet
      sheet.getRange(5,2).setValue([content.currency.toUpperCase()]);
  
      //Invoice amount due
      sheet.getRange(3,2).setValue([content.amount_due]);
  
      //Invoice date
      sheet.getRange(1,2).setValue([content.date]);
  
      //Invoice period begin
      sheet.getRange(6,2).setValue([content.lines.data[0].period.start]);
  
      //Invoice period end
      sheet.getRange(7,2).setValue([content.lines.data[0].period.end]);
  
      //Number of licenses
      sheet.getRange(10,2).setValue([content.lines.data[0].quantity]);
  
      //Invoice number
      sheet.getRange(13,2).setValue([content.number]);
  </code></pre>