title: How do I get domestic shipping rates via the USPS API using Google Apps Script?
body: <p>Upon loading this link, which is composed of the user ID provided by USPS and details regarding the package, in my browser</p>
  
  <pre><code>Link: http://production.shippingapis.com/ShippingAPITest.dll?API=RateV4&amp;XML=&lt;RateV4Request USERID="[userid]"&gt;&lt;Revision/&gt;&lt;Package ID="1ST"&gt;&lt;Service&gt;PRIORITY&lt;/Service&gt;&lt;ZipOrigination&gt;02211&lt;/ZipOrigination&gt;&lt;ZipDestination&gt;90210&lt;/ZipDestination&gt;&lt;Pounds&gt;5&lt;/Pounds&gt;&lt;Ounces&gt;2&lt;/Ounces&gt;&lt;Container&gt;RECTANGULAR&lt;/Container&gt;&lt;Size&gt;LARGE&lt;/Size&gt;&lt;Width&gt;15&lt;/Width&gt;&lt;Length&gt;30&lt;/Length&gt;&lt;Height&gt;15&lt;/Height&gt;&lt;Girth&gt;55&lt;/Girth&gt;&lt;/Package&gt;&lt;/RateV4Request&gt;
  </code></pre>
  
  <p>I am returned with the correct result (below)</p>
  
  <pre><code>&lt;RateV4Response&gt;
    &lt;Package ID="1ST"&gt;
      &lt;ZipOrigination&gt;02211&lt;/ZipOrigination&gt;
      &lt;ZipDestination&gt;90210&lt;/ZipDestination&gt;
      &lt;Pounds&gt;5&lt;/Pounds&gt;
      &lt;Ounces&gt;2&lt;/Ounces&gt;
      &lt;Container&gt;RECTANGULAR&lt;/Container&gt;
      &lt;Size&gt;LARGE&lt;/Size&gt;
      &lt;Width&gt;15&lt;/Width&gt;
      &lt;Length&gt;30&lt;/Length&gt;
      &lt;Height&gt;15&lt;/Height&gt;
      &lt;Zone&gt;8&lt;/Zone&gt;
      &lt;Postage CLASSID="1"&gt;
        &lt;MailService&gt;Priority Mail 2-Day&amp;lt;sup&amp;gt;&amp;#8482;&amp;lt;/sup&amp;gt;&lt;/MailService&gt;
        &lt;Rate&gt;86.65&lt;/Rate&gt;
      &lt;/Postage&gt;
    &lt;/Package&gt;
  &lt;/RateV4Response&gt;
  </code></pre>
  
  <p>However, when trying to load the API from a function in Google Apps Script editor using the following block of code:</p>
  
  <pre><code>function xmlLoader(){
    var pounds = 5;
    var ounces = 2;
    var userid = "[userid]";
    var url = "http://production.shippingapis.com/ShippingAPI.dll";
    var options =
      {
        "API" : "RateV4",
        "XML" : "&lt;RateV4Request USERID=\"" + userid + "\"&gt; \
                   &lt;Revision/&gt; \
                   &lt;Package ID=\"1ST\"&gt; \
                     &lt;Service&gt;PRIORITY&lt;/Service&gt; \
                     &lt;ZipOrigination&gt;02211&lt;/ZipOrigination&gt; \
                     &lt;ZipDestination&gt;90210&lt;/ZipDestination&gt; \
                     &lt;Pounds&gt;" + pounds + "&lt;/Pounds&gt; \
                     &lt;Ounces&gt;" + ounces + "&lt;/Ounces&gt; \
                     &lt;Container&gt;RECTANGULAR&lt;/Container&gt; \
                     &lt;Size&gt;LARGE&lt;/Size&gt; \
                     &lt;Width&gt;15&lt;/Width&gt; \
                     &lt;Length&gt;30&lt;/Length&gt; \
                     &lt;Height&gt;15&lt;/Height&gt; \
                     &lt;Girth&gt;55&lt;/Girth&gt; \
                   &lt;/Package&gt; \
                 &lt;/RateV4Request&gt;"
      };
  
    var response = UrlFetchApp.fetch(url, options);
    Logger.log(response.getContentText());
  };
  </code></pre>
  
  <p>This is the error I am returned with,</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
    &lt;Error&gt;
      &lt;Number&gt;80040B19&lt;/Number&gt;
      &lt;Description&gt;XML Syntax Error: Please check the XML request to see if it can be parsed.&lt;/Description&gt;
      &lt;Source&gt;USPSCOM::DoAuth&lt;/Source&gt;
    &lt;/Error&gt;
  </code></pre>
  
  <p>Any assistance would be greatly appreciated</p>