Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
427 views
in Technique[技术] by (71.8m points)

powershell - Getting file from Adobe Sign REST API

I am trying to use Adobe's REST API for Adobe Sign (https://secure.na1.echosign.com/public/docs/restapi/v6), to download files and upload them to a SharePoint site.

I can use the /agreements/{agreementId}/combinedDocument/url resource path to get the file's download URL.

$response = Invoke-RestMethod -Method GET -UseBasicParsing -Uri "https://api.na4.documents.adobe.com/api/rest/v6/agreements/{agreementId}/combinedDocument/url" -Headers $headers
$webclient = New-Object System.Net.WebClient
$webclient.DownloadFile($response.url, c:est.pdf)

Then I can successfully download the .pdf to my file system. When I open the file, its contents are displayed as expected (no password prompt). However, I would like to skip the "create a file on my hard drive" step. So I started looking at /agreements/{agreementId}/combinedDocument, which should return the raw file.

The response looks like this (truncated):

%∩┐╜∩┐╜∩┐╜∩┐╜ 1 0 obj <</Author(∩┐╜2∩┐╜╔ò∩┐╜┘?∩┐╜∩┐╜V∩┐╜Q ∩┐╜∩┐╜l(∩┐╜s N∩┐╜Ye ∩┐╜∩┐╜∩┐╜]∩┐╜]∩┐╜v}∩┐╜∩┐╜H∩┐╜∩┐╜{∩┐╜)∩┐╜)/CreationDate(∩┐╜2∩┐╜╔ò∩┐╜┘?∩┐╜∩┐╜V∩┐╜Q . . . 4D?"?g!??bc?????a?hM??vlNe ???5-?p?? ?+ ?? 2?<??r!s????e???YQl,?t?v?gTE?????景?=??y?I?Jr?7?dn?q
?P>2??x?1?u?!?hDm??dP/m?|T.??>?k&?T????? {&?v??b???O?????D22?5???R?7?=?x3?R?C?LF????y?F?q #??? [?AO??Ij?0r??%??k?"e24?d??f>?k&?T??????3l??r-( mb?2????/?fV<?8?z| ??:?M????ar?:?F?ZON?bbg>???n?O?H??} ?7?;L?? ???????f??j0I?k?t?|4-0?1?Z?-? ??}??????I?o?? ????i`??3??o??Y.?k??/]?yC)r??q?????? O? e??9?64?????>?????J?Xkay?? ??JEl?LC??1?,~??d?>,4@??(|??Z?????s?T??m???-??/??&Z? ?,???1b??sdy????雄??v????q?EZ47?W?DR???m????c?p??N??y?_??T"y??d?6w . . . 7b5f2121d1b05903ca11e5b7e0dbeed4483f673c9636b89053f39a0cb7ff4809a136bfd2b99a719af18fe37c91c10eeb7b5a55eb9e4ed373d1ba9639eadc04405a465dddae380fecbbde60a2063a1182ce2c3a01f34207ef4631b291ae030dc72d4e1cc04bd759899e6bea7667b89308207223082050aa00302010202100a915e54fd303bf3fe783ec40e3abccb300d06092a864886f70d01010b0500306c310b300906035504061302555331233021060355040a131a41646f62652053797374656d7320496e636f72706f7261746564311d301b060355040b131441646f6265205472757374205365727669636573311930170603550403131041646f626520526f6f74204341204732301e170d3136313132393030303030305a170d3431313132383233353935395a3068310b300906035504061302555331233021060355040a131a41646f62652053797374656d7320496e636f72706f7261746564311d301b060355040b131441646f6265205472757374205365727669636573311530130603550403130c41646f62652043445320434130820222300d06092a864886f70d01010105000382020f003082020a0282020100bf52b1677cb144e1cefd04deb67ba3eeb7fc95411f6ec0ae1d4dd024c8182765b1328f1620b9a4aa2dee3d33693feeccc00abc5823d2019c78e6e673c33f52f7dd74e6f86d44342425adb00c1cce1792af750b9b6c6fce58c5c964d8778e0b940d2f4aa5bec0229a92baae0b61d2c813cc5e5335906a5ffed0519ea3b1cd57e689ca3874475158f64ae41fed16b2485d0231ccce0c947c7234398321b326335cbf46b3873efef4b26eb40f28cfc5561276486c1ea09c424993b8ceec44b162141bb17dbbed6c532b0bb57a5b7ca6358c04460e973082bffbc9c7dff533c098f69fd0a8d97ca12640da64c12962687d4054962c28a56af3ebdcce92d131c3a5506d349308c17e24251dfc47a99e41b858004f0840d23372b923509b3d4f727bb40bbb9a291927aa227a44bb57b960a421fb5da978cd5a686e67a8d6b40edca431221dd7a5c93d8bae58086788efac7b1cf7bd769e927e68aa1cc544fe3abe26334fc56b1606494c94b32de399ae4d97b8ddc50f865b3685a67505676f543fd39a1c995b151d524dc7969b598c2d39d613eb714077e5380864985833e936ce026c293a6841b618a0015fb599100d38ec281ce5d16227e47dac83d1ab6a8e8a3ecb7ec0f139f33f069d44ea5402401820f0811dca362079ed106c363a553d5be4d6e94c8e496b9126780be420f5bdd6546d5a0a923872a40393565de7acc02fd43d0203010001a38201c2308201be30120603551d130101ff040830060101ff0201003081e406 . . . 0000054133 00000 n 0000071627 00000 n 0000000000 65535 f 0000071662 00000 n trailer <</Root 13 0 R/Info 1 0 R/Encrypt 36 0 R/ID[<57771F73142824582991AF5BFD2>]/Size 37>> startxref 71920 %%EOF

"Great", I thought. I can just convert that to a memory stream and upload it to SharePoint. Unfortunately, when I do this:

$response = Invoke-RestMethod -Method GET -UseBasicParsing -Uri "https://api.na4.documents.adobe.com/api/rest/v6/agreements/{agreementId}/combinedDocument" -Headers $headers
$memStream = [System.IO.MemoryStream]([System.Text.Encoding]::UTF8.GetBytes($response))
Add-PnPFile -FileName "test.pdf" -Folder "/Shared Documents" -Stream $memStream

I can see the file in SharePoint, but when I try to open it, I am prompted for a password (there is no password on the file downloaded using /url). Also, the resulting .pdf is not the same size as the one I downloaded using the /agreements/{agreementId}/combinedDocument/url resource path.

So my questions are twofold. In no particular order, "where is this password coming from?" and "how do I take the raw file and output it to a file?"

Thanks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...