Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Apps Script UrlFetchApp() with mixed binary and text payload
    primarykey
    data
    text
    <p>I am trying to create a <a href="https://developers.google.com/apps-script/class_urlfetchapp" rel="nofollow">UrlFetchApp()</a> payload from multiple documents for a <a href="http://www.interfax.net/en/dev/rest/reference/2918" rel="nofollow">third-party service</a>. If I follow their example for multiple inline documents, the UrlFetchApp() payload should contain both binary (for each file) and text (to separate the two pieces of content). How to I supply this mixed content to the payload advanced argument?</p> <p>I have successfully done binary only using .getBytes() on a blob as follows:</p> <pre><code>function testfax() { var faxnum = '12125551234'; var url = 'https://rest.interfax.net/outbound/faxes?faxNumber=+'+faxnum; Logger.log('url='+url) Logger.log(" ") var varAuthString = AuthString(); //user function to create HTTP simple authorization header //Logger.log(varAuthString) //Logger.log(" ") var accept = "application/xml"; var meth = 'POST'; var payloadBlob = testDocBlob("For-Testing-Fax"); //user function returns GAS blob mime type "application/pdf" var payload = []; payload = payloadBlob.getBytes(); Logger.log(payload.length) var contentType = "application/pdf" var ContentLen = 0; var headers = { "Accept": accept , "Authorization": "Basic " + varAuthString } //Logger.log("headers= ") //Logger.log(headers) //Logger.log(" ") var options = { "method" : meth, "headers" : headers, "contentType":contentType, "contentLength": ContentLen, "payload" : payload }; //Logger.log("options= ") //Logger.log(options) //Logger.log(" ") var r = UrlFetchApp.fetch(url,options); Logger.log(r.getResponseCode()); Logger.log(r.getContentText()); Logger.log(r.getHeaders()); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload