DocuSign API - GetEnvelopeDocuments - get file size without downloading? - docusignapi

According to : https://developers.docusign.com/docs/esign-rest-api/reference/envelopes/envelopedocuments/list/
The EnvelopeDocument model should have "sizeBytes" property on it.
However, I'm making calls to GET https://demo.docusign.net/restapi/v2.1/accounts/{{accountId}}/envelopes/{{envelopeId}/documents
and the payload does not have it.
I also tried hitting HEAD https://demo.docusign.net/restapi/v2.1/accounts/{{accountId}}/envelopes/{{envelopeId}/documents/{{documentId}
to see if I could read the headers without the actual content but that I receive a 404 NOT FOUND so it must not be supported.
The only way I can see to accomplish this would be to hit the download file endpoint directly, reading the content-length header, and then cancelling the request before streaming any data from it.
Is there a better way to do this?

The only way to do this would be to make a get envelope call
GET https://demo.docusign.net/restapi/v2.1/accounts/{{accountId}}/envelopes/{{envelopeId}/documents
Then in the headers, you will find Content-Length, this is the file size

Reached out to DocuSign and they confirmed there's no way to do this other than to hit the download endpoint and read the content length header.
After some experimentation i found this doesnt really work either because the Content Length header is not always accurate from their api. The only way I can see to do it is to download the entire file into memory and take a count of the bytes, or keep track of the byte count as you stream it to its destination.

Related

UTF-8 handling in the Distance Matrix API

I'm trying to write a VBA code that interacts with the Google's Distance Matrix Api, and returns me the distance between two points. The problem is, when I try to use latin letters (like ã), it returns a Invalid Destination error:
<status>INVALID_REQUEST</status>
<error_message>Invalid request. Invalid 'destinations' parameter.</error_message>
</DistanceMatrixResponse>
The Url I'm using is this:
https://maps.googleapis.com/maps/api/distancematrix/xml?units=metric&origins=Fortaleza&destinations=São+Paulo&key=" & myAPIK
Do you guys know any way to get around this?
But when I use UTF-8 code instead of the word itself, it returns me the distance that I wanted:
https://maps.googleapis.com/maps/api/distancematrix/xml?units=metric&origins=Fortaleza&destinations=S%C3%A3o+Paulo&key=" & myAPIK
I also already tried putting the language (pt-BR) in the Url, but it didn't work.
You're going to want to look at how the actual web page works.
Open the web page in Chrome, then view the Request Traffic in DevTools (F12), it will be on the network tab.
You'll have to find the request in the sidebar, filtering by XHR will help.
When you find the request itself, it will show you how it's encoded. It's unlikely that Latin is the transfer-encoding parameter, and UTF-8 is probably being filtered before the request is sent via JavaScript normalization of your input. But unless you examine the API in DevTools you wont know for sure.
Also if you're just using QueryString (aka the part of the API parameter in the url) to interact with the API, there is a urlencode probably happening. You can see using this website how this works, with Sao Paulo. And you probably need to 'sanitize' your input using an urlencode function before post/get the API.

Open new tab with POST method

I want to create a new tab and send data to it in a POST request from my chrome extension. I could use a GET request, but the data I am going to send could be arbitrarily long, and I want to JSON encode it(which also means I cannot use forms). I've only found two questions on SO about this, but both of them are talking about using a form, which is not desirable.
The reason I want to do this is because I want to request further input from the user before I do what I do with the data. I am totally lost here and have no idea how to do this, hence I can not add any code samples I've tried.
If I cannot do this with a URL, I could inject a script into the page and have a popup, but that is something of a last resort.
Any ideas on how this could be done?

Instagram - Obtaining data in realtime

I am trying to get the recent post from a particular location. using this url.
https://api.instagram.com/v1/media/search?lat=34.0500&lng=-118.2500&distance=50&MAX_ID=max_id&access_token=XXXX
So when I use this URL for the first time, I get 20 results. I obtain the max ID from the list of 20 results and modify my url .
But when I use the modified URL, I obtain the same result as the first one.
How do I go about solving this?
Contrary to what I thought, the media search endpoint doesn't return a pagination object. Sorry. It also doesn't support the min_id/max_id parameters, which is why you are having problems..
If you want to get different data you are going to have to use the time based request parameter MIN_TIMESTAMP. However it looks like that parameter doesn't work for that endpoint either (though the documentation says it is supported). Indeed, a quick search on the internet reveals it might be a long standing bug with the api.

Pure Node.js file upload (multipart POST) without using a framework

The third-party libraries "node-formidable" and "express" come with the ability to handle multipart POST requests (e.g. with a file upload form), but I don't want to use any third-party code. How do I make the file upload process in pure JavaScript on Node.js?
There are very few resources in this regard. How can this be done? Thank you, love is.
Just to clarify because it seems some people are angry that the other answer didn't help much: There is no simple way of doing this without relying on a library doing it for you.
First, here's an answer to another question trying to clarify what happens on a POST file upload: https://stackoverflow.com/a/8660740/2071242
To summarize, to parse such an upload, you'll first need to check for a Content-Type header containing "multipart/form-data" and, if one exists, read the boundary attribute within the header.
After this, the content comes in multiple parts, each starting with the boundary string, including some additional headers and then the data itself after a blank line. The browser can select the boundary string pretty freely as long as such byte sequence doesn't exist in the uploaded data (see the spec at https://www.rfc-editor.org/rfc/rfc1867 for details). You can read in the data by registering a callback function for the request object's data event: request.on('data', callback);
For example, with boundary "QweRTy", an upload might look something like this:
POST /upload HTTP/1.1
(some standard HTTP headers)
Content-Type: multipart/form-data; boundary=QweRTy
--QweRTy
Content-Disposition: form-data; name="upload"; filename="my_file.txt"
Content-Type: text/plain
(The contents of the file)
--QweRTy--
Note how after the initial headers two dashes are added to the beginning of each boundary string and two dashes are added to the end of the last one.
Now, what makes this challenging is that you might need to read the incoming data (within the callback function mentioned above) in several chunks, and there are no guarantees that the boundary will be contained within one chunk. So you'll either need to buffer all the data (not necessarily a good idea) or implement a state machine parser that goes through the data byte by byte. This is actually exactly what the formidable library is doing.
So after having similar considerations, what I personally decided to do is to use the library. Re-implementing such a parser is pretty error-prone and in my opinion not worth the effort. But if you really want to avoid any libraries, checking the code of formidable might be a good start.
This is a bit old question, but still quite relevant.
I have been looking for a similar solution and no luck. So decided to do my own which might come handy to some other users.
GIST: https://gist.github.com/patrikbego/6b80c6cfaf4f4e6c119560e919409bb2
Nodejs itself recommends (as seen here) formidable, but I think that such a basic functionality should be provided by Nodejs out of the box.
I think you need to parse form by yourself if you don't want to use any modules very much. When uploading a file, the form will be in multipart/form-data format, which means your request content will be divided by a string that is generated randomly by your browser. You need to read this string at the beginning of the form, try to load data and find this string, then parse them one by one.
For more information about multipart/form-data you can refer http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2
I think the best solution is to use formidable. It handles vary scenarios and works prefect I think.

Excel file as HTTP post method response

In my application, I use GET method to get a Excel file back. The url actually contains the parameters that server needs to generate the Excel file. However, sometimes, the parameters may become so long (more then 2000 characters).
I am considering using POST method, but it does not seem that POST method can return a document. Am I right?
Nop, how you request, say GET, PUT and POST, doesn't necessarily affect the server you response.
How to make the response depends on the program on server. If you want to send a binary file after a POST request is totally cool.
Just take a look at sites like megaupload, rapidshare, etc. All of them will send you a file after you POST the recaptcha code.

Resources