-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriter API.postman_collection.json
More file actions
525 lines (525 loc) · 19.1 KB
/
Writer API.postman_collection.json
File metadata and controls
525 lines (525 loc) · 19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
{
"info": {
"_postman_id": "05aa877a-414d-4e03-80cf-fa25c838321f",
"name": "Writer API",
"description": "The **Write API** is a lightweight and scalable microservice designed to streamline the **massive generation of documents via API**. This project addresses a key challenge in the **legal contract signing process for products offered by Apimarket**, providing a seamless, automated, and secure solution.\n\nBuilt with cutting-edge technologies, the Write API leverages:\n\n- **Python**: To power document generation, parsing, API logic, and secure authentication processes.\n \n- **Jinja2**: For efficient variable injection and rendering in document templates, enabling high customization.\n \n- **YAML**: To define document logic, structure, and validation rules in a clear and human-readable format.\n \n\nThe service has been crafted without a graphical user interface (GUI) to maintain its lightweight architecture and high customizability. It runs in **Docker containers**, ensuring portability, scalability, and ease of deployment in diverse environments.\n\nWith its minimal design and powerful capabilities, the Write API offers a flexible and efficient way to automate the creation of contracts and other documents, ensuring consistency, accuracy, and compliance across large-scale operations.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "8823093"
},
"item": [
{
"name": "Authentication",
"item": [
{
"name": "Create Account",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"id\": 1,\n \"email\": \"hh.abdiel@gmail.com\",\n \"password\": \"@Charlie14\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8007/auth/signup",
"protocol": "http",
"host": [
"localhost"
],
"port": "8007",
"path": [
"auth",
"signup"
]
}
},
"response": [
{
"name": "Welcome Copy",
"originalRequest": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"id\": 1,\n \"email\": \"hh.abdiel@gmail.com\",\n \"password\": \"@Charlie14\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8007/auth/signup",
"protocol": "http",
"host": [
"localhost"
],
"port": "8007",
"path": [
"auth",
"signup"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "date",
"value": "Fri, 17 Jan 2025 01:46:12 GMT"
},
{
"key": "server",
"value": "uvicorn"
},
{
"key": "content-length",
"value": "38"
},
{
"key": "content-type",
"value": "application/json"
}
],
"cookie": [],
"body": "{\n \"id\": 1,\n \"email\": \"hh.abdiel@gmail.com\"\n}"
}
]
},
{
"name": "Login",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.collectionVariables.set(\"access_token\", pm.response.json().access_token);"
],
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"exonhos@gmail.com\",\n \"password\": \"@Charlie14\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8007/auth/login",
"protocol": "http",
"host": [
"localhost"
],
"port": "8007",
"path": [
"auth",
"login"
]
}
},
"response": [
{
"name": "Create Account Copy",
"originalRequest": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"hh.abdiel@gmail.com\",\n \"password\": \"@Charlie14\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8007/auth/login",
"protocol": "http",
"host": [
"localhost"
],
"port": "8007",
"path": [
"auth",
"login"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "date",
"value": "Fri, 17 Jan 2025 01:49:11 GMT"
},
{
"key": "server",
"value": "uvicorn"
},
{
"key": "content-length",
"value": "160"
},
{
"key": "content-type",
"value": "application/json"
}
],
"cookie": [],
"body": "{\n \"access_token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwiZXhwIjoxNzM3MDgyMTUyfQ.npKWMwxXmg5SGvbXrWvuc77uE-7bAYLSVGAuXA03xgc\",\n \"token_type\": \"bearer\"\n}"
}
]
}
],
"description": "### Authentication in Write API\n\nThe **Write API** uses a secure token-based authentication system to protect its endpoints and ensure only authorized users can access its features. Below is a detailed explanation of how authentication works and how to interact with the API.\n\n### Authentication Mechanism\n\nTo authenticate with the Write API, include a **bearer token** in the `Authorization` header of your HTTP requests. This token verifies your identity and grants access to the API based on your assigned permissions.\n\n#### Header Example:\n\n```\nAuthorization: Bearer <your_api_token>\n\n ```\n\n#### Example Using `curl`:\n\n```\ncurl -H \"Authorization: Bearer H3PLMKJKIVATLDPWHJH3AGWEJPFU5GRT\" \\\n http://localhost/document-templates/contrato_idse_pro/parameters\n\n ```\n\n#### Example Using Python:\n\n``` python\nimport requests\nheaders = {'Authorization': 'Bearer H3PLMKJKIVATLDPWHJH3AGWEJPFU5GRT'}\nresponse = requests.get(\n 'http://localhost/document-templates/{template_id}/parameters',\n headers=headers\n)\nif response.status_code == 200:\n print(response.json())\nelse:\n print(f\"Error: {response.text}\")\n\n ```\n\n**Note**: Bearer tokens often expire after a set period. Ensure you handle token expiration appropriately by requesting a new token or refreshing it if your token management system supports it.\n\n---\n\n### API Responses\n\nMost API endpoints return responses in **JSON format**. For example, calling the endpoint `/document-templates/contrato_idse_pro/parameters` might return:\n\n``` json\n[\n {\n \"name\": \"usuario\",\n \"type\": \"string\",\n \"required\": true\n },\n {\n \"name\": \"fecha\",\n \"type\": \"string\",\n \"required\": true\n },\n {\n \"name\": \"razon_social\",\n \"type\": \"string\",\n \"required\": true\n }\n]\n\n ```\n\nThese responses provide all necessary information about required parameters, their types, and validation rules.\n\n---\n\n### Making POST Requests\n\nWhen calling POST endpoints, you must provide the required parameters in the **body** of the request. The recommended format is **JSON**, which simplifies the process of sending complex data structures.\n\n#### Example POST Request Using `curl`:\n\n```\ncurl --location 'http://localhost:8007/document-templates/{template_id}/generate' \\\n--header 'Content-Type: application/json' \\\n--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIyIiwiZXhwIjoxNzM3MDkxNjU3fQ.Q5KxltB8kr5zvDCffw-hD4fK8MCzOvSGJmGZR792nC0' \\\n--data '{\n \"usuario\": \"Juan Pérez\",\n \"razon_social\": \"COCA COLA COMPANY S.A. DE C.V.\",\n \"fecha\": \"Jueves, 16 de enero de 2025\"\n}'\n\n ```\n\n#### Example POST Request Using Python:\n\n``` python\nimport requests\nurl = 'http://localhost:8007/document-templates/{template_id}/generate'\nheaders = {\n 'Content-Type': 'application/json',\n 'Authorization': 'Bearer <your_api_token>'\n}\ndata = {\n \"usuario\": \"Juan Pérez\",\n \"razon_social\": \"COCA COLA COMPANY S.A. DE C.V.\",\n \"fecha\": \"Jueves, 16 de enero de 2025\"\n}\nresponse = requests.post(url, headers=headers, json=data)\nprint(response.json())\n\n ```\n\n#### Special Case: File Uploads\n\nIf your POST request includes file uploads, you must use the `multipart/form-data` format instead of JSON:\n\n```\ncurl --location 'http://localhost:8007/upload' \\\n--header 'Authorization: Bearer <your_api_token>' \\\n--form 'file=@/path/to/your/template.yaml'\n\n ```\n\nBy following these practices, you can securely interact with the Write API and integrate it seamlessly into your workflows."
},
{
"name": "Parameters",
"item": [
{
"name": "Get Parameters",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:8007/document-templates/contrato_idse_pro/parameters",
"protocol": "http",
"host": [
"localhost"
],
"port": "8007",
"path": [
"document-templates",
"contrato_idse_pro",
"parameters"
]
}
},
"response": [
{
"name": "Get Parameters",
"originalRequest": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:8007/document-templates/mi_primer_templates/parameters",
"protocol": "http",
"host": [
"localhost"
],
"port": "8007",
"path": [
"document-templates",
"mi_primer_templates",
"parameters"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "date",
"value": "Fri, 17 Jan 2025 02:06:01 GMT"
},
{
"key": "server",
"value": "uvicorn"
},
{
"key": "content-length",
"value": "162"
},
{
"key": "content-type",
"value": "application/json"
}
],
"cookie": [],
"body": "[\n {\n \"name\": \"nombre_usuario\",\n \"type\": \"string\",\n \"required\": true\n },\n {\n \"name\": \"fecha\",\n \"type\": \"string\",\n \"required\": true\n },\n {\n \"name\": \"direccion\",\n \"type\": \"string\",\n \"required\": false\n }\n]"
}
]
},
{
"name": "Cargar plantilla",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "multipart/form-data",
"type": "text"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "template_id",
"value": "mi_primer_templates",
"type": "text"
},
{
"key": "file",
"type": "file",
"src": "/Users/exonhos/PhpstormProjects/writer/app/yamls/example_flow.yaml"
}
]
},
"url": {
"raw": "http://localhost:8007/document-templates",
"protocol": "http",
"host": [
"localhost"
],
"port": "8007",
"path": [
"document-templates"
]
}
},
"response": [
{
"name": "Cargar plantilla",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "multipart/form-data",
"type": "text"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "template_id",
"value": "mi_primer_templates",
"type": "text"
},
{
"key": "file",
"type": "file",
"src": "/Users/exonhos/PhpstormProjects/writer/app/yamls/example_flow.yaml"
}
]
},
"url": {
"raw": "http://localhost:8007/document-templates",
"protocol": "http",
"host": [
"localhost"
],
"port": "8007",
"path": [
"document-templates"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "date",
"value": "Fri, 17 Jan 2025 02:05:43 GMT"
},
{
"key": "server",
"value": "uvicorn"
},
{
"key": "content-length",
"value": "59"
},
{
"key": "content-type",
"value": "application/json"
}
],
"cookie": [],
"body": "{\n \"message\": \"YAML 'mi_primer_templates' subido con éxito.\"\n}"
}
]
}
],
"description": "The **Parameters Section** of the Write API provides essential details about the inputs required for various operations. Parameters define the structure, validation rules, and expected data types for each endpoint, ensuring accurate and seamless execution of API calls.\n\n- **Structure Definition**: Parameters are dynamically defined in YAML templates, making them highly customizable for different use cases. Each parameter specifies:\n \n - `name`: The name of the parameter.\n \n - `type`: The expected data type (e.g., `string`, `int`, `date`, etc.).\n \n - `required`: Whether the parameter is mandatory or optional.\n \n- **Validation**: The API enforces strict validation rules based on the parameter definitions in the templates, ensuring data consistency and preventing invalid inputs.\n \n- **Ease of Access**: Use endpoints like `/parameters` to retrieve detailed information about the required parameters for specific templates. This feature enhances the API's usability by guiding users in preparing valid input data.\n \n\nFor example, calling the `/parameters` endpoint might return:\n\n``` json\n[\n {\n \"name\": \"usuario\",\n \"type\": \"string\",\n \"required\": true\n },\n {\n \"name\": \"fecha\",\n \"type\": \"date\",\n \"required\": true\n }\n]\n\n ```\n\nBy providing a clear and structured parameter definition, the Write API ensures robust integration and error-free execution for all users."
},
{
"name": "Document Generation",
"item": [
{
"name": "Generate Document",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"usuario\": \"Juan Pérez\",\n \"razon_social\": \"COCA COLA COMPANY S.A. DE C.V.\",\n \"fecha\": \"Jueves, 16 de enero de 2025\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8007/document-templates/contrato_idse_pro/generate",
"protocol": "http",
"host": [
"localhost"
],
"port": "8007",
"path": [
"document-templates",
"contrato_idse_pro",
"generate"
]
}
},
"response": [
{
"name": "Not authenticated",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"nombre_usuario\": \"Juan Pérez\",\n \"direccion\": \"Calle Falsa 123\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8007/document-templates/mi_primer_templates/generate",
"protocol": "http",
"host": [
"localhost"
],
"port": "8007",
"path": [
"document-templates",
"mi_primer_templates",
"generate"
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "json",
"header": [
{
"key": "date",
"value": "Fri, 17 Jan 2025 02:06:49 GMT"
},
{
"key": "server",
"value": "uvicorn"
},
{
"key": "www-authenticate",
"value": "Bearer"
},
{
"key": "content-length",
"value": "30"
},
{
"key": "content-type",
"value": "application/json"
}
],
"cookie": [],
"body": "{\n \"detail\": \"Not authenticated\"\n}"
}
]
}
],
"description": "The **Document Generation Section** of the Write API is the core functionality, allowing users to create highly customized documents from predefined templates. This feature is designed for efficiency, scalability, and flexibility in handling complex workflows, such as legal contract generation.\n\n- **Template-Based Design**: Documents are generated using templates defined in `.docx`, `.md`, or `.html` formats. Templates leverage **Jinja2** to dynamically inject user-provided variables into the document.\n \n- **YAML Configuration**: Each template is associated with a YAML file that defines the template's logic, required parameters, and validation rules. This approach ensures consistency and minimizes errors during document creation.\n \n- **Output Formats**: The API supports generating documents in multiple formats, including:\n \n - **DOCX**: The default format, ideal for further editing.\n \n - **PDF**: For finalized, non-editable documents.\n \n - **HTML**: When a web-based format is required.\n \n- **Massive Document Generation**: The system is optimized for large-scale operations, enabling users to generate thousands of documents efficiently by providing the necessary input data programmatically.\n \n\nBy combining the power of templates, YAML configurations, and dynamic inputs, the Write API simplifies the generation of customized documents, making it an indispensable tool for automation and scalability."
},
{
"name": "Welcome",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:8007",
"protocol": "http",
"host": [
"localhost"
],
"port": "8007"
}
},
"response": []
}
],
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{access_token}}",
"type": "string"
}
]
},
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
}
],
"variable": [
{
"key": "access_token",
"value": "",
"type": "string"
}
]
}