PowerShell-带有文本和文件的Indoke -RestMethod

发布于 2025-02-06 04:09:47 字数 1856 浏览 4 评论 0原文

我正在尝试通过PowerShell Invoke-restmethod cmdlet发送REST

API

Object
status_code: 400
message: "Invalid document list"

呼叫此请求使用PowerShell,因为它将完美地集成了我目前正在使用具有Windows Form GUI的语言进行的程序。

我正在向沙盒环境发送一些测试调用,这是我当前的代码(我显然正在省略令牌和其他机密信息):

$filePath = 'C:\test\ITFormAPITest.pdf';
$SandboxURL = "https://api.sandbox.signaturit.com/v3/signatures.json"
$headers = @{"Authorization"="Bearer myTOKEN"}
$Body = @{
"recipients[0][name]"="myNAME";
"recipients[0][email]"="myEMAILADDRESS";
"files[0]"= $filePath;
"subject"="Subject Test";
"body"="Please review and sign this. Thanks!"}

Invoke-RestMethod -WebSession $session -Uri $SandboxURL -Method "POST" -Body $Body -Headers $headers -ContentType "application/x-www-form-urlencoded"

Signaturit是一种工具,允许通过电子邮件发送文档以向收件人请求数字签名。我能够通过Postman发送API请求,可以在其中指定密钥类型(文件或文本),但我不知道如何指定PowerShell中的类型,这就是为什么在发送REST API调用时,我的文件参数实际上是对的。作为文本参数,请参见下面的屏幕截图:

”在此处输入图像描述

有建议吗?我试图联系他们的支持,但他们似乎没有人知道如何使用PowerShell做到这一点。谢谢

请参阅下面的链接,介绍如何使用API​​以及如何注册沙箱: Signaturit API Instructions: https://docs.signaturit.com/api/latest#signatures_create_sign 沙盒注册页面: https://app.sandbox.sign.signaturit.com/en/register/个人 SandBox Env​​iremnt访问令牌位置: https://dashboard.sandboard.signboard.signerit.com/ en/#/设置/集成

I am trying to sent a Rest API Call via PowerShell Invoke-RestMethod Cmdlet but I keep getting BAD REQUEST 400 response:

RESPONSE

Object
status_code: 400
message: "Invalid document list"

I need to make this request using PowerShell because it would integrate perfectly a program I am currently working on in this language that has a windows form GUI.

I am sending some test calls to a sandbox environment and this is my current code (I am obviously omitting token and other confidential information):

$filePath = 'C:\test\ITFormAPITest.pdf';
$SandboxURL = "https://api.sandbox.signaturit.com/v3/signatures.json"
$headers = @{"Authorization"="Bearer myTOKEN"}
$Body = @{
"recipients[0][name]"="myNAME";
"recipients[0][email]"="myEMAILADDRESS";
"files[0]"= $filePath;
"subject"="Subject Test";
"body"="Please review and sign this. Thanks!"}

Invoke-RestMethod -WebSession $session -Uri $SandboxURL -Method "POST" -Body $Body -Headers $headers -ContentType "application/x-www-form-urlencoded"

Signaturit is a tool that allows to send document via email to request a digital signature from the recipient. I was able to send API requests via Postman where I can specify the key type (file or text) but I do not know how to specify the type in PowerShell and that is why when sending a rest api call, my file parameters is actually parsed as a text parameters, see screenshot below:

enter image description here

Any advice? I have tried to contact their support but they have nobody seems to know how to do this using PowerShell. Thanks

Please see links below on how to use the API and how to register for the sandbox:
Signaturit API Instructions: https://docs.signaturit.com/api/latest#signatures_create_sign
Sandbox Registration Page: https://app.sandbox.signaturit.com/en/register/personal
Sandbox Environemnt Access Token Location: https://dashboard.sandbox.signaturit.com/en/#/settings/integrations

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奶茶白久 2025-02-13 04:09:47

得益于我的一个亲爱的朋友的头脑风暴,他设法找到了解决方法。我不知道我可以在PowerShell脚本中包括一个卷曲代码,这就是我所做的:

curl.exe `
-X POST `
-H "Authorization: Bearer ACCESS_TOKEN" `
-F "recipients[0][name]=RECIPIENT_NAME" `
-F "recipients[0][email]=RECIPIENT_EMAIL" `
-F "subject=SUBJECT_EMAIL" `
-F "body=BODY_EMAIL" `
-F "files[0]=@C:\PATH\FILE_TO_UPLOAD.EXT" `
URL_FOR_THE_API_CALL

Managed to find myself a workaround thanks to the brainstorming with a dear friend of mine. I did not know that I could just include a cURL code in my PowerShell script and that is what I did:

curl.exe `
-X POST `
-H "Authorization: Bearer ACCESS_TOKEN" `
-F "recipients[0][name]=RECIPIENT_NAME" `
-F "recipients[0][email]=RECIPIENT_EMAIL" `
-F "subject=SUBJECT_EMAIL" `
-F "body=BODY_EMAIL" `
-F "files[0]=@C:\PATH\FILE_TO_UPLOAD.EXT" `
URL_FOR_THE_API_CALL
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文