如何使用Python在Autentique API中上载文件?

2024-10-02 00:26:09 发布

您现在位置:Python中文网/ 问答频道 /正文

1条回答
网友
1楼 · 发布于 2024-10-02 00:26:09

必须首先在Autentique上创建帐户和API密钥

在沙箱中上载文件并将其发送到电子邮件进行签名。它返回文档的id和名称

使用卷曲

  curl -H "Authorization: Bearer <TOKEN>" https://api.autentique.com.br/v2/graphql \
  -F operations='{"query": "mutation CreateDocumentMutation($document: DocumentInput! $signers: [SignerInput!]! $file: Upload!) {createDocument(sandbox: true, document: $document, signers: $signers, file: $file) {id name }}", "variables": { "document": {"name": "<DOCUMENT_NAME>"}, "signers": [{"email": "<FROM_EMAIL>","action": "SIGN"}], "file": null } }' \
  -F map='{ "0": ["variables.file"] }' \
  -F 0=@<FULL_PATH_FILE>

使用aiogqlc

https://github.com/DoctorJohn/aiogqlc

import asyncio
from aiogqlc import GraphQLClient

endpoint = "https://api.autentique.com.br/v2/graphql"

headers = {
    "Authorization": "Bearer <TOKEN>"
}

client = GraphQLClient(endpoint, headers=headers)

async def create_document():
    query = """
      mutation CreateDocumentMutation(
        $document: DocumentInput!
        $signers: [SignerInput!]!
        $file: Upload!
        ) {
        createDocument(
        sandbox: true,
        document: $document,
        signers: $signers,
        file: $file) 
        {
          id
          name
          }
        }"""

    variables = {
        "document": {
            "name": "<DOCUMENT_NAME>"
        },
        "signers": [{
            "email": "<FROM_EMAIL>",
            "action": "SIGN"
        }],
        "file": open('<FULL_PATH_FILE>', 'rb'),
    }

    response = await client.execute(query, variables=variables)
    print(await response.json())


if __name__ == '__main__':
    asyncio.get_event_loop().run_until_complete(create_document())

有关更多语言实现:https://github.com/jaydenseric/graphql-multipart-request-spec#implementations

相关问题 更多 >

    热门问题