Luchdaich suas Faidhle mar Theamplaid
Tha an stiùireadh seo a’ toirt seachad turas tron phròiseas làn airson teamplaid a chruthachadh agus PDF, ìomhaigh, no faidhle Word a luchdachadh suas airson a chleachdadh mar an teamplaid sgrìobhainn agad ann an Legalesign.
Dè Dh’ionnsaicheas Tu
Aig deireadh an stiùiridh seo, bidh fios agad mar a:
- Cruthaich teamplaid ùr ann am buidheann Legalesign agad
- Faigh ID an teamplaide agus URL luchdachadh suas bhon fhreagairt mutation
- Luchdaich suas an fhaidhle tùsail agad chun an teamplaide
- Dèan cinnteach gu robh an luchdachadh suas soirbheachail
Riatanasan Ro-làimh
Mus tòisich thu, dèan cinnteach gu bheil agad:
- Cunntas Legalesign le cothrom air API
- Do shlighean dearbhaidh (faic ar stiùireadh dearbhaidh)
- PDF, ìomhaigh, no faidhle Word deiseil airson luchdachadh suas (àrd-chuinge 50MB)
- ID do bhuidheann (an àite-obrach far a bheil thu airson an teamplaid a chruthachadh)
An Pròiseas Làn
Ceum 1: Cruthaich Teamplaid
An toiseach, cruthaich teamplaid falamh ann an Legalesign. Bidh seo a’ tilleadh an dà chuid an ID teamplaide agus URL luchdachadh suas ro-chlàraichte airson luchdachadh suas PDF. Gus seo a dhèanamh feumaidh tu ruith mutation GraphQL, ma rinn thu seo roimhe, faic an Ro-ràdh air GraphQL.
Dè tha Teamplaid?
Is e teamplaid structar sgrìobhainn ath-chleachdadh ann an Legalesign. Cho luath ‘s a luchdicheas tu PDF gu teamplaid, faodaidh tu:
- Raointean ainm-sgrìobhaidh agus raointean foirm a chur ris
- A chur gu iomadh neach-faighinn
- Ath-chleachdadh airson luchd-sgrìobhaidh eadar-dhealaichte
Mutation GraphQL
mutation CreateTemplate($input: templateCreateInput!) {
createTemplate(input: $input) {
id
uploadUrl
}
}
Caibidealan Input
{
"input": {
"groupId": "grpYourGroupAPIId",
"title": "Employment Contract Template"
}
}
Mìneachadh air Paramadairean
- groupId: ID base 64 den bhuidheann/ àite-obrach agad (faodaidh tu seo a thoirt bhon URL anns a’ Chonsòl https://console.legalesign.com/)
- title: Ainm mìnichte airson do teamplaid (faodaidh tu seo atharrachadh nas fhaide air adhart)
Ceum 2: Tarraing a-mach ID an teamplaide agus URL luchdachadh suas
Bidh am mutation a’ tilleadh nithean templateCreateOutput. Sàbhail an raon id agus an sreang uploadUrl.
Freagairt eisimpleir:
{
"data": {
"createTemplate": {
"id": "dHBsYjQ5YTg5NWQtYWRhMy0xMWYwLWIxZGMtMDY5NzZlZmU0MzIx",
"uploadUrl": "https://s3.amazonaws.com/bucket/path?signature=..."
}
}
}
Is e sreang air a chòdachadh base64 a th’ anns an ID teamplaid. Sàbhail an dà luach bho na freagairtean. Tha am uploadUrl beag-ùine agus bu chòir a chleachdadh gu luath.
Ceum 3: Luchdaich suas do PDF
Cleachd am uploadUrl a thill gus do fhaidhle PDF a luchdachadh suas gu dìreach gu S3. Bidh seo eadar-dhealaichte a rèir do thogalach leasachaidh. Anns an eisimpleir javascript againn chleachd sinn fetch ach faodaidh tu libhrarian eile a chleachdadh a’ gabhail a-steach aws-amplify.
Eisimpleirean Obrach Làn
- JavaScript
- Python
- C#
import fs from 'fs';
const AUTH_TOKEN = '<token-from-authentication-guide>';
const uploadPdfTemplate = async (groupId, title, pdfFilePath) => {
const graphqlEndpoint = 'https://graphql.uk.legalesign.com/graphql';
// Step 1: Create the template
console.log('Creating template...');
const createResponse = await fetch(graphqlEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${AUTH_TOKEN}`
},
body: JSON.stringify({
query: `
mutation CreateTemplate($input: templateCreateInput!) {
createTemplate(input: $input) {
id
uploadUrl
}
}
`,
variables: {
input: {
groupId: groupId,
title: title
}
}
})
});
const createResult = await createResponse.json();
const templateId = createResult.data.createTemplate.id;
const uploadUrl = createResult.data.createTemplate.uploadUrl;
console.log('Template created with ID:', templateId);
// Step 2: Upload the PDF
console.log('Uploading PDF...');
const fileData = fs.readFileSync(pdfFilePath);
const uploadResponse = await fetch(uploadUrl, {
method: 'PUT',
body: fileData,
headers: {
'Content-Type': 'application/pdf'
}
});
if (!uploadResponse.ok) {
throw new Error(`Upload failed: ${uploadResponse.statusText}`);
}
console.log('PDF uploaded successfully!');
return {
success: true,
templateId: templateId,
title: title
};
};
// Usage example
uploadPdfTemplate(
'grpYourGroupId',
'Employment Contract',
'./contract.pdf'
).then(result => {
console.log('Complete!', result);
}).catch(error => {
console.error('Error:', error);
});
Chan eil feum air eisimeileachd a bharrachd — tha Node.js 18+ a’ toirt a-steach fetch nad fhìor ghnàth-shuidheachadh.
import requests
from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport
def upload_pdf_template(graphql_endpoint, auth_token, group_id, title, pdf_file_path):
transport = RequestsHTTPTransport(
url=graphql_endpoint,
headers={'Authorization': auth_token}
)
client = Client(transport=transport, fetch_schema_from_transport=True)
# Step 1: Create the template
print('Creating template...')
create_mutation = gql('''
mutation CreateTemplate($input: templateCreateInput!) {
createTemplate(input: $input) {
id
uploadUrl
}
}
''')
create_result = client.execute(
create_mutation,
variable_values={
'input': {
'groupId': group_id,
'title': title
}
}
)
template_id = create_result['createTemplate']['id']
upload_url = create_result['createTemplate']['uploadUrl']
print(f'Template created with ID: {template_id}')
# Step 2: Upload the PDF
print('Uploading PDF...')
with open(pdf_file_path, 'rb') as f:
file_data = f.read()
response = requests.put(
upload_url,
data=file_data,
headers={'Content-Type': 'application/pdf'}
)
if response.status_code != 200:
raise Exception(f'Upload failed: {response.status_code}')
print('PDF uploaded successfully!')
return {
'success': True,
'templateId': template_id,
'title': title
}
if __name__ == '__main__':
result = upload_pdf_template(
'https://graphql.uk.legalesign.com/graphql',
'Bearer YOUR_TOKEN',
'grpYourGroupId',
'Employment Contract',
'./contract.pdf'
)
print('Complete!', result)
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using GraphQL;
using GraphQL.Client.Http;
using GraphQL.Client.Serializer.Newtonsoft;
using Newtonsoft.Json.Linq;
public class PdfTemplateUploader
{
private readonly GraphQLHttpClient graphQLClient;
public PdfTemplateUploader(string graphqlEndpoint, string authToken)
{
graphQLClient = new GraphQLHttpClient(graphqlEndpoint, new NewtonsoftJsonSerializer());
graphQLClient.HttpClient.DefaultRequestHeaders.Add("Authorization", authToken);
}
public async Task<UploadResult> UploadPdfTemplate(
string groupId,
string title,
string pdfFilePath)
{
// Step 1: Create the template
Console.WriteLine("Creating template...");
var createMutation = new GraphQLRequest
{
Query = @"
mutation CreateTemplate($input: templateCreateInput!) {
createTemplate(input: $input) {
id
uploadUrl
}
}
",
Variables = new
{
input = new
{
groupId = groupId,
title = title
}
}
};
var createResponse = await graphQLClient.SendMutationAsync<dynamic>(createMutation);
string templateId = createResponse.Data.createTemplate.id;
string uploadUrl = createResponse.Data.createTemplate.uploadUrl;
Console.WriteLine($"Template created with ID: {templateId}");
// Step 2: Upload the PDF
Console.WriteLine("Uploading PDF...");
using var httpClient = new HttpClient();
var fileBytes = await File.ReadAllBytesAsync(pdfFilePath);
var content = new ByteArrayContent(fileBytes);
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf");
var putResponse = await httpClient.PutAsync(uploadUrl, content);
if (!putResponse.IsSuccessStatusCode)
{
throw new Exception($"Upload failed: {putResponse.StatusCode}");
}
Console.WriteLine("PDF uploaded successfully!");
return new UploadResult
{
Success = true,
TemplateId = templateId,
Title = title
};
}
}
public class UploadResult
{
public bool Success { get; set; }
public string TemplateId { get; set; }
public string Title { get; set; }
}
class Program
{
static async Task Main(string[] args)
{
var uploader = new PdfTemplateUploader(
"https://graphql.uk.legalesign.com/graphql",
"Bearer YOUR_TOKEN"
);
var result = await uploader.UploadPdfTemplate(
"grpYourGroupId",
"Employment Contract",
"./contract.pdf"
);
Console.WriteLine($"Complete! Template ID: {result.TemplateId}");
}
}
Dè thachras às dèidh Luchdachadh suas?
Cho luath ‘s a thèid do PDF a luchdachadh suas, bidh Legalesign gu fèin-ghluasadach a’:
- A’ sgrùdadh airson bhìoras - A’ dèanamh cinnteach gu bheil am faidhle sàbhailte
- A’ dearbhadh no a’ tionndadh an fhaidhle - A’ dèanamh cinnteach gu bheil PDFan dligheach, no a’ tionndadh faidhlichean air an toirt taic, leithid sgrìobhainnean Word agus ìomhaighean, gu PDF
- A’ tarraing a-mach fiosrachadh duilleag - A’ faighinn cunntas agus meudan duilleag
- A’ pròiseasadh an fhaidhle - A’ dèanamh adhartachadh airson sealladh agus ainm-sgrìobhadh
- A’ stòradh gu tèarainte - A’ gluasad gu stòradh seasmhach
Bidh am pròiseas seo mar as trice a’ gabhail beagan dhiogan. Cho luath ‘s a bhios e deiseil, tha an teamplaid agad deiseil airson a chleachdadh!
Sgrùdaich Adhartas Luchdachadh suas
Gus faighinn air ais fios air ais fìor-ùine mun phròiseas luchdachadh suas (sganadh, dearbhadh, crìoch), cleachd subscriptions. Faic Sgrùdadh Adhartas Luchdachadh suas le Subscriptions.
Mar roghainn eile, dèan suirbhidh air raon fileUploaded den teamplaid gus am bi e a’ tilleadh true:
query CheckUploadStatus($id: ID!) {
template(id: $id) {
id
fileUploaded
}
}
A’ Cuir ris Ainm-sgrìobhaidhean agus Raointean
Ma tha thu airson com-pàirtichean agus suidheachadh raointean a fèin-ghluasad, faodaidh tu an faidhle tùsail ullachadh mus càradh thu e ann an grunn dhòighean:
- Tags teacsa - Cuir tags teacsa Legalesign a-steach don sgrìobhainn tùsail gus com-pàirtichean, raointean ainm-sgrìobhaidh, agus raointean foirm a chruthachadh gu fèin-ghluasadach rè pròiseasadh. Faic mìneachadh API REST anns an tòiseachadh luath agus an leabhar iomraidh airson an tionndaidh tags teacsa.
- Raointean PDF ceangailte - Ma tha raointean foirm cheangailte agad mar-thà anns a’ PDF, faodaidh Legalesign an cleachdadh mar phàirt den obair luchdachadh suas agus ullachadh teamplaide.
Ceumannan an Ath
A-nis gu bheil teamplaid agad le PDF, faodaidh tu:
- Cuir ris raointean ainm-sgrìobhaidh - Cleachd an mutation
createTemplateElementgus raointean a chur ris - Cruthaich dreuchdan - Mìnich cò a bhios a’ sgrìobhadh an sgrìobhainn
- Cuir gu son - Cleachd an mutation
sendgus a chuir gu luchd-faighinn
Cùisean Cumanta agus Fuasglaidhean
Mearachd “Chan eil cead”
Dèan dearbhadh gu bheil ID do bhuidheann ceart agus gu bheil thu air dearbhadh le cunntas ceart.
Mearachd “Tha am faidhle ro mhòr”
Briogrioch an PDF agad — is e 50MB an èiginn as àirde.
URL Luchdachadh suas air a Dh’fhalbh
Cleachd am uploadUrl a thill bho createTemplate gu luath. Ma bhios e a’ crìonadh mus luchdich thu suas, iarr URL ùr le ceist upload a’ cleachdadh ID an teamplaide a chaidh a shàbhaladh.
Mearachd “PDF mì-dhligheach”
Fosgail am PDF ann an leughadair PDF airson dearbhadh gu bheil e dligheach, an uair sin às-àrd no ath-sàbhail e.