title: How to assign UrlFetchApp with basic authorization to button?
body: <p>I created function in Google Apps Script, that works well when I run it in Google Apps Script. Output data returns to Google Sheets.</p>
  
  <pre><code>function testFunction11() {
    var rng = SpreadsheetApp.getActiveRange();
    var encodedAuthInformation = Utilities.base64Encode("username:key");
    var headers = {"Authorization" : "Basic " + encodedAuthInformation};
    var params = {
      'method': 'GET',
      'muteHttpExceptions': true,
      'headers': headers
    };
    var res = UrlFetchApp.fetch("https://api.apiservice.com/api/v1/xxx?fields=somefields", params);
    Logger.log(res.getContentText());
    rng.setValue(res);
  }
  </code></pre>
  
  <p>Output in cell:</p>
  
  <pre><code>[
    {
      "id": xxx,
      "createdDate": "2019-02-01T04:54:00Z",
      "reference": "XXX"
    },
  etc
  </code></pre>
  
  <p>Then I assign script to button, 'testFunction11'.
  And when I click button, it returns</p>
  
  <pre><code>{
    "message": "An error has occurred."
  }
  </code></pre>
  
  <p>It looks like response from API server.</p>
  
  <p>My only hypothesis is that google sheet's button adds some headers, User-Agent or content-type to request, which not allowed in API server. And after some search, I guess I can't reassign User-Agent in request. Is that something right or I do it wrong?</p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>Headers for each case <code>console.log(UrlFetchApp.getRequest(url, params))</code>:
  When clicking button in spreadsheet:</p>
  
  <pre><code>{headers={Authorization=Basic XXXXXXXXQVU6MWVhODlmZmFkN2U3NGNjOGJkOTc1YTE1ZjVhNTE3MzE=, X-Forwarded-For=178.xx.my.ip}, method=get, payload=, followRedirects=true, validateHttpsCertificates=true, useIntranet=false, contentType=null, url=https://api.apisite.com/api/v1/SalesOrders?fields=Id,Createddate,Reference&amp;where=Createddate%3E2019-02-01T00:00:00Z}
  </code></pre>
  
  <p>And for script:</p>
  
  <pre><code>{headers={Authorization=Basic XXXXXXXXQVU6MWVhODlmZmFkN2U3NGNjOGJkOTc1YTE1ZjVhNTE3MzE=}, method=get, payload=, followRedirects=true, validateHttpsCertificates=true, useIntranet=false, contentType=null, url=https://api.apisite.com/api/v1/SalesOrders?fields=Id,Createddate,Reference&amp;where=Createddate%3E2019-02-01T00:00:00Z}
  </code></pre>
  
  <p>So the button only adds <code>X-Forwarded-For</code>.</p>
  
  <p>When I tried manually add <code>X-Forwarded-For: 'unknown'</code> there are error like this</p>
  
  <pre><code>There are attribute with impossible value: Header:X-Forwarded-For
  </code></pre>
  
  <p>Text of error in russian, so sorry for maybe not accurate translating. It's fun, because when I added <code>Test: unknown</code> in same way, there are no error, but obviously not working. Looks like google don't allow to change this value.</p>
  
  <p>Will try different headers in postman and maybe confirm that this header is the cause of the error. Thank you @TheMaster</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>I tried different headers via Postman. So, result is when I add to headers <code>X-Forwarded-For</code> key with any value, it return <code>"message": "An error has occurred."</code>
  When I don't add this key, it works well.  </p>
  
  <p>So, the question is any way to disable adding this header via Google Apps Script. It seems like not.</p>