Python 전체 예제
표준 라이브러리에 가까운 requests로 전체 흐름을 구성한 예제입니다.
import os
import requests
API = "https://api.pactery.com/v1"
KEY = os.environ["PACTERY_API_KEY"]
S = requests.Session()
S.headers.update({"Authorization": f"Bearer {KEY}"})
def pactery(method, path, **kw):
r = S.request(method, API + path, **kw)
if not r.ok:
raise RuntimeError(r.json().get("error", {}).get("message", r.status_code))
return r.json()
# 1) 문서 생성
doc = pactery("POST", "/documents", json={
"title": "업무 위탁 계약서",
"content": "<h1>계약서</h1><p>...</p>",
})
# 2) 서명자 지정
signer = pactery("POST", f"/documents/{doc['id']}/participants", json={
"name": "홍길동", "phone": "01012345678", "role": "signer",
})
# 3) 서명 필드 배치
pactery("PUT", f"/documents/{doc['id']}/fields", json={
"fields": [{
"participant_id": signer["id"], "type": "signature",
"page": 1, "x": 0.62, "y": 0.8, "width": 0.25, "height": 0.08,
}],
})
# 4) 발송
pactery("POST", f"/documents/{doc['id']}/send", json={})
print("발송 완료:", doc["id"])