ugcinc 1.0.6 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,16 +5,10 @@ Official TypeScript/JavaScript client for the UGC Inc API.
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm i ugcinc
8
+ npm install ugcinc
9
9
  ```
10
10
 
11
- ## Getting Started
12
-
13
- ### 1. Get Your API Key
14
-
15
- Get your API key at **https://ugc.inc**. You'll need this to authenticate all API requests.
16
-
17
- ### 2. Initialize the Client
11
+ ## Quick Start
18
12
 
19
13
  ```typescript
20
14
  import { UGCClient } from 'ugcinc';
@@ -22,1018 +16,39 @@ import { UGCClient } from 'ugcinc';
22
16
  const client = new UGCClient({
23
17
  apiKey: 'your-api-key-here'
24
18
  });
25
- ```
26
-
27
- **Important:** Keep your API key secure! Never commit it to version control or expose it in client-side code.
28
-
29
- ## API Documentation
30
-
31
- ### Accounts
32
-
33
- The `accounts` object provides methods for managing accounts.
34
-
35
- #### Get Accounts
36
-
37
- Retrieve accounts with optional filters.
38
-
39
- ```typescript
40
- const response = await client.accounts.getAccounts({
41
- tag: 'influencer',
42
- org_group: 'group1',
43
- user_group: 'users1'
44
- });
45
-
46
- if (response.ok) {
47
- console.log(response.data); // Account[]
48
- }
49
- ```
50
-
51
- #### Get Account Statistics
52
-
53
- Get statistics for accounts.
54
-
55
- ```typescript
56
- const response = await client.accounts.getStats({
57
- accountIds: ['account-id-1', 'account-id-2'],
58
- startDate: '2024-01-01',
59
- endDate: '2024-12-31'
60
- });
61
-
62
- if (response.ok) {
63
- response.data.forEach(stat => {
64
- console.log(`Account ${stat.account_id}: ${stat.followers} followers`);
65
- });
66
- }
67
- ```
68
-
69
- #### Refresh Account Statistics
70
-
71
- Fetch live statistics from TikTok/Instagram API and create new stat records.
72
-
73
- ```typescript
74
- const response = await client.accounts.refreshStats({
75
- accountIds: ['account-id-1', 'account-id-2'],
76
- tag: 'influencer'
77
- });
78
-
79
- if (response.ok) {
80
- console.log(`Refreshed stats for ${response.data.length} accounts`);
81
- response.data.forEach(stat => {
82
- console.log(`Account ${stat.account_id}: ${stat.followers} followers`);
83
- });
84
- }
85
- ```
86
-
87
- #### Get Account Status
88
-
89
- Get the status of tasks for a specific account.
90
-
91
- ```typescript
92
- const response = await client.accounts.getStatus({
93
- accountId: 'account-id',
94
- includeCompleted: false
95
- });
96
-
97
- if (response.ok) {
98
- console.log(response.data); // AccountTask[]
99
- }
100
- ```
101
-
102
- #### Update Account Info
103
-
104
- Update account metadata (tag, org_group, user_group).
105
-
106
- ```typescript
107
- const response = await client.accounts.updateInfo({
108
- accountId: 'account-id',
109
- tag: 'influencer',
110
- org_group: 'group1',
111
- user_group: 'users1'
112
- });
113
-
114
- if (response.ok) {
115
- console.log(response.data.message);
116
- console.log(response.data.account); // Updated account
117
- }
118
- ```
119
-
120
- #### Update Account Social Profile
121
-
122
- Update account social profile information (avatar, nickname, bio).
123
-
124
- **Important:** Nicknames can only be updated once every 7 days.
125
-
126
- ```typescript
127
- const response = await client.accounts.updateSocial({
128
- accountId: 'account-id',
129
- nickName: 'New Name',
130
- bio: 'New bio text',
131
- avatarUrl: 'https://example.com/avatar.jpg'
132
- });
133
-
134
- if (response.ok) {
135
- console.log(response.data.message);
136
- } else {
137
- // Error response includes when nickname can be updated again
138
- console.error(response.message);
139
- }
140
- ```
141
-
142
- ### Tasks
143
-
144
- The `tasks` object provides methods for managing tasks.
145
-
146
- #### Get Tasks
147
-
148
- Retrieve tasks with optional filters.
149
-
150
- ```typescript
151
- const response = await client.tasks.getTasks({
152
- accountIds: ['account-id-1'],
153
- startDate: '2024-01-01',
154
- endDate: '2024-12-31',
155
- taskType: 'edit_profile'
156
- });
157
-
158
- if (response.ok) {
159
- console.log(response.data); // Task[]
160
- }
161
- ```
162
-
163
- ### Posts
164
-
165
- The `posts` object provides methods for managing posts.
166
-
167
- #### Get Posts
168
-
169
- Retrieve posts with optional filters.
170
-
171
- ```typescript
172
- const response = await client.posts.getPosts({
173
- accountIds: ['account-id-1'],
174
- startDate: '2024-01-01',
175
- endDate: '2024-12-31'
176
- });
177
-
178
- if (response.ok) {
179
- console.log(response.data); // Post[]
180
- }
181
- ```
182
-
183
- #### Create Slideshow
184
-
185
- Create a slideshow post.
186
-
187
- ```typescript
188
- const response = await client.posts.createSlideshow({
189
- accountId: 'account-id',
190
- imageUrls: [
191
- 'https://example.com/image1.jpg',
192
- 'https://example.com/image2.jpg',
193
- 'https://example.com/image3.jpg'
194
- ],
195
- caption: 'Check out this slideshow!',
196
- musicPostId: 'music-id',
197
- postTime: '2024-12-31T12:00:00Z',
198
- strict: true
199
- });
200
-
201
- if (response.ok) {
202
- console.log(`Post created: ${response.data.id}`);
203
- }
204
- ```
205
-
206
- #### Create Video
207
-
208
- Create a video post.
209
-
210
- ```typescript
211
- const response = await client.posts.createVideo({
212
- accountId: 'account-id',
213
- videoUrl: 'https://example.com/video.mp4',
214
- caption: 'My awesome video!',
215
- musicPostId: 'music-id',
216
- postTime: '2024-12-31T12:00:00Z',
217
- strict: true
218
- });
219
-
220
- if (response.ok) {
221
- console.log(`Post created: ${response.data.id}`);
222
- }
223
- ```
224
-
225
- #### Get Post Statistics
226
19
 
227
- Get statistics for posts.
228
-
229
- ```typescript
230
- const response = await client.posts.getStats({
231
- postIds: ['post-id-1', 'post-id-2'],
232
- startDate: '2024-01-01',
233
- endDate: '2024-12-31'
234
- });
235
-
236
- if (response.ok) {
237
- response.data.forEach(stat => {
238
- console.log(`Post ${stat.post_id}: ${stat.views} views, ${stat.likes} likes`);
239
- });
240
- }
241
- ```
242
-
243
- #### Refresh Post Statistics
244
-
245
- Fetch live statistics from TikTok/Instagram API and create new stat records.
246
-
247
- ```typescript
248
- const response = await client.posts.refreshStats({
249
- postIds: ['post-id-1', 'post-id-2']
250
- });
251
-
252
- if (response.ok) {
253
- console.log(`Refreshed stats for ${response.data.length} posts`);
254
- response.data.forEach(stat => {
255
- console.log(`Post ${stat.post_id}: ${stat.views} views, ${stat.likes} likes`);
256
- });
257
- }
258
- ```
259
-
260
- #### Get Post Status
261
-
262
- Get the status of a specific post.
263
-
264
- ```typescript
265
- const response = await client.posts.getStatus({
266
- postId: 'post-id'
267
- });
268
-
269
- if (response.ok) {
270
- console.log(`Post status: ${response.data.status}`);
271
- }
272
- ```
273
-
274
- ## Response Handling
275
-
276
- All API methods return a response object with the following structure:
277
-
278
- ### Success Response
279
-
280
- ```typescript
281
- {
282
- ok: true,
283
- code: 200,
284
- message: "Success",
285
- data: T // The actual response data
286
- }
287
- ```
288
-
289
- ### Error Response
290
-
291
- ```typescript
292
- {
293
- ok: false,
294
- code: number, // HTTP status code
295
- message: string // Error message
296
- }
297
- ```
298
-
299
- ### Type-Safe Response Handling
300
-
301
- ```typescript
20
+ // Example: Get accounts
302
21
  const response = await client.accounts.getAccounts();
303
22
 
304
23
  if (response.ok) {
305
- // TypeScript knows response.data is Account[]
306
- response.data.forEach(account => {
307
- console.log(account.username);
308
- });
309
- } else {
310
- // TypeScript knows response has code and message
311
- console.error(`Error ${response.code}: ${response.message}`);
312
- }
313
- ```
314
-
315
- ## TypeScript Support
316
-
317
- This package is written in TypeScript and provides full type definitions. All types are exported for your convenience:
318
-
319
- ```typescript
320
- import type {
321
- Account,
322
- Post,
323
- Task,
324
- CreateVideoParams,
325
- ApiResponse
326
- } from 'ugcinc';
327
- ```
328
-
329
- ## Error Handling
330
-
331
- ```typescript
332
- try {
333
- const response = await client.accounts.getAccounts();
334
-
335
- if (!response.ok) {
336
- console.error(`API Error: ${response.message}`);
337
- return;
338
- }
339
-
340
- // Handle success
341
24
  console.log(response.data);
342
- } catch (error) {
343
- console.error('Network or parsing error:', error);
344
- }
345
- ```
346
-
347
- ## Environment Variables
348
-
349
- For production use, store your API key securely using environment variables:
350
-
351
- ```bash
352
- # .env file
353
- UGC_API_KEY=your-api-key-here
354
- ```
355
-
356
- Then in your code:
357
-
358
- ```typescript
359
- import { UGCClient } from 'ugcinc';
360
-
361
- const client = new UGCClient({
362
- apiKey: process.env.UGC_API_KEY!
363
- });
364
- ```
365
-
366
- ---
367
-
368
- ## Complete API Reference
369
-
370
- ### Accounts API
371
-
372
- #### `client.accounts.getAccounts(params?)`
373
-
374
- Retrieve accounts with optional filters.
375
-
376
- **Endpoint:** `POST /accounts`
377
-
378
- **Parameters:**
379
-
380
- | Parameter | Type | Required | Description |
381
- |-----------|------|----------|-------------|
382
- | `tag` | `string` | No | Filter by tag |
383
- | `org_group` | `string` | No | Filter by organization group |
384
- | `user_group` | `string` | No | Filter by user group |
385
-
386
- **Returns:** `ApiResponse<Account[]>`
387
-
388
- Returns an array of Account objects matching the specified filters. If no filters are provided, returns all accounts for your organization.
389
-
390
- **Account Object:**
391
-
392
- ```typescript
393
- {
394
- id: string; // Unique account identifier
395
- type: string; // Account type ('tiktok' or 'instagram')
396
- tag: string | null; // Custom tag for categorization
397
- org_group: string | null; // Organization group identifier
398
- user_group: string | null; // User group identifier
399
- username: string | null; // Account username/handle
400
- nick_name: string | null; // Account display name
401
- pfp_url: string | null; // Profile picture URL
402
- }
403
- ```
404
-
405
- | Field | Type | Description |
406
- |-------|------|-------------|
407
- | `id` | `string` | Unique account identifier |
408
- | `type` | `string` | Account platform type (`'tiktok'` or `'instagram'`) |
409
- | `tag` | `string \| null` | Custom tag for categorization |
410
- | `org_group` | `string \| null` | Organization group identifier for grouping |
411
- | `user_group` | `string \| null` | User group identifier for grouping |
412
- | `username` | `string \| null` | Account username/handle on the platform |
413
- | `nick_name` | `string \| null` | Display name shown on profile |
414
- | `pfp_url` | `string \| null` | URL to account's profile picture |
415
-
416
- **Example:**
417
-
418
- ```typescript
419
- const response = await client.accounts.getAccounts({
420
- tag: 'influencer',
421
- org_group: 'group1'
422
- });
423
- ```
424
-
425
- ---
426
-
427
- #### `client.accounts.getStats(params?)`
428
-
429
- Get account statistics.
430
-
431
- **Endpoint:** `POST /accounts/stats`
432
-
433
- **Parameters:**
434
-
435
- | Parameter | Type | Required | Description |
436
- |-----------|------|----------|-------------|
437
- | `accountIds` | `string[]` | No | Array of account IDs to get stats for |
438
- | `startDate` | `string` | No | Start date (ISO 8601 format) |
439
- | `endDate` | `string` | No | End date (ISO 8601 format) |
440
- | `tag` | `string` | No | Filter by tag |
441
- | `org_group` | `string` | No | Filter by organization group |
442
- | `user_group` | `string` | No | Filter by user group |
443
-
444
- **Returns:** `ApiResponse<AccountStat[]>`
445
-
446
- Returns an array of AccountStat objects containing follower counts, views, likes, and other metrics for the specified accounts and date range.
447
-
448
- **AccountStat Object:**
449
-
450
- ```typescript
451
- {
452
- id: string; // Unique stat record identifier
453
- account_id: string; // Associated account ID
454
- followers: number | null; // Follower count
455
- following: number | null; // Following count
456
- views: number | null; // Total profile views
457
- likes: number | null; // Total likes received
458
- created_at: string; // Timestamp when stat was recorded
459
- }
460
- ```
461
-
462
- | Field | Type | Description |
463
- |-------|------|-------------|
464
- | `id` | `string` | Unique identifier for this stat record |
465
- | `account_id` | `string` | ID of the account these stats belong to |
466
- | `followers` | `number \| null` | Total number of followers |
467
- | `following` | `number \| null` | Total number of accounts being followed |
468
- | `views` | `number \| null` | Total profile/content views |
469
- | `likes` | `number \| null` | Total likes received across all content |
470
- | `created_at` | `string` | ISO 8601 timestamp when this stat was recorded |
471
-
472
- **Example:**
473
-
474
- ```typescript
475
- const response = await client.accounts.getStats({
476
- accountIds: ['account-1', 'account-2'],
477
- startDate: '2024-01-01T00:00:00Z',
478
- endDate: '2024-12-31T23:59:59Z'
479
- });
480
- ```
481
-
482
- ---
483
-
484
- #### `client.accounts.refreshStats(params?)`
485
-
486
- Refresh account statistics by fetching live data from TikTok/Instagram API.
487
-
488
- **Endpoint:** `POST /accounts/stats/refresh`
489
-
490
- **Parameters:**
491
-
492
- | Parameter | Type | Required | Description |
493
- |-----------|------|----------|-------------|
494
- | `accountIds` | `string[]` | No | Array of account IDs to refresh stats for |
495
- | `tag` | `string` | No | Filter by tag |
496
- | `org_group` | `string` | No | Filter by organization group |
497
- | `user_group` | `string` | No | Filter by user group |
498
-
499
- **Returns:** `ApiResponse<AccountStat[]>`
500
-
501
- Returns an array of newly created AccountStat objects with live data from TikTok or Instagram. This endpoint fetches fresh statistics directly from the platform APIs and creates new stat records in the database. Use this when you need up-to-date metrics instead of historical data. The API automatically determines which platform to query based on the account type.
502
-
503
- **Key Differences from `getStats()`:**
504
- - `refreshStats()` fetches **live data** from TikTok/Instagram API and creates new records
505
- - `getStats()` retrieves **historical data** from your database
506
-
507
- **Example:**
508
-
509
- ```typescript
510
- const response = await client.accounts.refreshStats({
511
- accountIds: ['account-1', 'account-2'],
512
- tag: 'influencer'
513
- });
514
-
515
- if (response.ok) {
516
- console.log(`Successfully refreshed ${response.data.length} accounts`);
517
- response.data.forEach(stat => {
518
- console.log(`Account ${stat.account_id}:`);
519
- console.log(` Followers: ${stat.followers}`);
520
- console.log(` Views: ${stat.views}`);
521
- });
522
25
  }
523
26
  ```
524
27
 
525
- ---
526
-
527
- #### `client.accounts.getStatus(params)`
528
-
529
- Get account status and pending tasks.
530
-
531
- **Endpoint:** `POST /accounts/status`
532
-
533
- **Parameters:**
534
-
535
- | Parameter | Type | Required | Description |
536
- |-----------|------|----------|-------------|
537
- | `accountId` | `string` | **Yes** | Account ID to check status for |
538
- | `includeCompleted` | `boolean` | No | Include completed tasks (default: false) |
539
-
540
- **Returns:** `ApiResponse<AccountTask[]>`
541
-
542
- Returns an array of AccountTask objects showing pending and (optionally) completed tasks for the specified account. Tasks include profile edits and other account-level operations.
543
-
544
- **AccountTask Object:**
545
-
546
- ```typescript
547
- {
548
- id: string; // Unique task identifier
549
- account_id: string; // Associated account ID
550
- type: string; // Task type
551
- status: string; // Current task status
552
- scheduled_time: string | null; // When task is scheduled to run
553
- edit_profile_info: EditProfileInfo | null; // Profile update details (if type is 'edit_profile')
554
- created_at: string; // When task was created
555
- }
556
- ```
557
-
558
- | Field | Type | Description |
559
- |-------|------|-------------|
560
- | `id` | `string` | Unique identifier for this task |
561
- | `account_id` | `string` | ID of the account this task belongs to |
562
- | `type` | `string` | Task type (e.g., `'edit_profile'`, `'warmup_scroll'`) |
563
- | `status` | `string` | Current task status (`'scheduled'`, `'pending'`, `'complete'`, `'failed'`) |
564
- | `scheduled_time` | `string \| null` | ISO 8601 timestamp when task is scheduled to execute |
565
- | `edit_profile_info` | `EditProfileInfo \| null` | Profile update information (only for `edit_profile` tasks) |
566
- | `created_at` | `string` | ISO 8601 timestamp when task was created |
567
-
568
- **Example:**
569
-
570
- ```typescript
571
- const response = await client.accounts.getStatus({
572
- accountId: 'account-id',
573
- includeCompleted: true
574
- });
575
- ```
576
-
577
- ---
578
-
579
- #### `client.accounts.updateInfo(params)`
580
-
581
- Update account metadata (tag, org_group, user_group).
582
-
583
- **Endpoint:** `POST /accounts/update-info`
584
-
585
- **Parameters:**
586
-
587
- | Parameter | Type | Required | Description |
588
- |-----------|------|----------|-------------|
589
- | `accountId` | `string` | **Yes** | Account ID to update |
590
- | `tag` | `string` | No | New tag value for categorization |
591
- | `org_group` | `string` | No | New organization group identifier |
592
- | `user_group` | `string` | No | New user group identifier |
593
-
594
- **Note:** At least one of `tag`, `org_group`, or `user_group` must be provided.
595
-
596
- **Returns:** `ApiResponse<{ message: string; account: Account }>`
597
-
598
- Returns a success message and the updated account object. The update is applied immediately to the database.
599
-
600
- **Response Object:**
601
-
602
- ```typescript
603
- {
604
- message: string; // Success message (e.g., "Account info updated successfully")
605
- account: Account; // Updated account object with new values
606
- }
607
- ```
608
-
609
- **Example:**
610
-
611
- ```typescript
612
- const response = await client.accounts.updateInfo({
613
- accountId: 'account-id',
614
- tag: 'influencer',
615
- org_group: 'group1',
616
- user_group: 'users1'
617
- });
28
+ ## Get Your API Key
618
29
 
619
- if (response.ok) {
620
- console.log(response.data.account.tag); // 'influencer'
621
- }
622
- ```
623
-
624
- ---
625
-
626
- #### `client.accounts.updateSocial(params)`
627
-
628
- Update account social profile (avatar, nickname, bio).
629
-
630
- **Endpoint:** `POST /accounts/update-social`
631
-
632
- **Parameters:**
633
-
634
- | Parameter | Type | Required | Description |
635
- |-----------|------|----------|-------------|
636
- | `accountId` | `string` | **Yes** | Account ID to update |
637
- | `avatarUrl` | `string` | No | New avatar/profile picture URL |
638
- | `nickName` | `string` | No | New display name |
639
- | `bio` | `string` | No | New bio text |
640
-
641
- **Important:** Nicknames can only be updated **once every 7 days**. If you attempt to update a nickname before the 7-day period has elapsed, the API will return an error with details about when the next update is allowed.
642
-
643
- **Returns:** `ApiResponse<{ message: string }>`
644
-
645
- Returns a success message when the profile update task has been successfully created and queued. The actual profile update will be processed asynchronously through the GeeLark API.
646
-
647
- **Response Object:**
648
-
649
- ```typescript
650
- {
651
- message: string; // Success message (e.g., "Profile update task created successfully")
652
- }
653
- ```
654
-
655
- **Error Response (Nickname Restriction):**
656
-
657
- If you attempt to update the nickname too soon:
658
-
659
- ```typescript
660
- {
661
- ok: false,
662
- code: 400,
663
- message: "Nickname can only be updated once every 7 days. Last update was X days ago. You can update again in Y day(s) on YYYY-MM-DD"
664
- }
665
- ```
666
-
667
- **Example:**
668
-
669
- ```typescript
670
- const response = await client.accounts.updateSocial({
671
- accountId: 'account-id',
672
- nickName: 'Cool Creator',
673
- bio: 'Content creator 🎥',
674
- avatarUrl: 'https://storage.example.com/avatar.jpg'
675
- });
676
-
677
- if (response.ok) {
678
- console.log(response.data.message);
679
- } else {
680
- // Handle nickname restriction error
681
- console.error(response.message);
682
- }
683
- ```
684
-
685
- ---
686
-
687
- ### Tasks API
688
-
689
- #### `client.tasks.getTasks(params?)`
690
-
691
- Retrieve tasks with optional filters.
692
-
693
- **Endpoint:** `POST /tasks`
694
-
695
- **Parameters:**
696
-
697
- | Parameter | Type | Required | Description |
698
- |-----------|------|----------|-------------|
699
- | `accountIds` | `string[]` | No | Filter by account IDs |
700
- | `startDate` | `string` | No | Start date (ISO 8601 format) |
701
- | `endDate` | `string` | No | End date (ISO 8601 format) |
702
- | `taskType` | `TaskType` | No | Filter by task type |
703
-
704
- **TaskType:** `'warmup_scroll' | 'warmup_search_term' | 'warmup_search_profile' | 'edit_profile'`
705
-
706
- **Returns:** `ApiResponse<Task[]>`
707
-
708
- Returns an array of Task objects including warmup tasks (scrolling, searching) and profile edit tasks for the specified accounts and date range. Each task includes scheduling information and type-specific parameters.
709
-
710
- **Task Object:**
711
-
712
- ```typescript
713
- {
714
- id: string; // Unique task identifier
715
- account_id: string; // Associated account ID
716
- type: TaskType; // Task type
717
- status: string; // Current status
718
- scheduled_time: string | null; // When task is scheduled
719
- duration: number | null; // Task duration in seconds
720
- keywords: string[] | null; // Keywords for search tasks
721
- edit_profile_info: EditProfileInfo | null; // Profile info for edit tasks
722
- created_at: string; // Creation timestamp
723
- }
724
- ```
725
-
726
- | Field | Type | Description |
727
- |-------|------|-------------|
728
- | `id` | `string` | Unique identifier for this task |
729
- | `account_id` | `string` | ID of the account this task belongs to |
730
- | `type` | `TaskType` | Task type: `'warmup_scroll'`, `'warmup_search_term'`, `'warmup_search_profile'`, or `'edit_profile'` |
731
- | `status` | `string` | Current status: `'scheduled'`, `'pending'`, `'complete'`, or `'failed'` |
732
- | `scheduled_time` | `string \| null` | ISO 8601 timestamp when task should execute |
733
- | `duration` | `number \| null` | Task duration in seconds (for warmup tasks) |
734
- | `keywords` | `string[] \| null` | Array of keywords (for search tasks) |
735
- | `edit_profile_info` | `EditProfileInfo \| null` | Profile update details (for `edit_profile` tasks) |
736
- | `created_at` | `string` | ISO 8601 timestamp when task was created |
737
-
738
- **Example:**
739
-
740
- ```typescript
741
- const response = await client.tasks.getTasks({
742
- accountIds: ['account-1', 'account-2'],
743
- taskType: 'edit_profile',
744
- startDate: '2024-01-01T00:00:00Z'
745
- });
746
- ```
30
+ To get your API key:
747
31
 
748
- ---
32
+ 1. Visit [ugc.inc](https://ugc.inc)
33
+ 2. Schedule a call with our team
34
+ 3. You'll receive your API key after the call
749
35
 
750
- ### Posts API
751
-
752
- #### `client.posts.getPosts(params?)`
753
-
754
- Retrieve posts with optional filters.
755
-
756
- **Endpoint:** `POST /post`
757
-
758
- **Parameters:**
759
-
760
- | Parameter | Type | Required | Description |
761
- |-----------|------|----------|-------------|
762
- | `accountIds` | `string[]` | No | Filter by account IDs |
763
- | `startDate` | `string` | No | Start date (ISO 8601 format) |
764
- | `endDate` | `string` | No | End date (ISO 8601 format) |
765
-
766
- **Returns:** `ApiResponse<Post[]>`
767
-
768
- Returns an array of Post objects (videos and slideshows) for the specified accounts and date range. Includes post status, URLs, captions, and associated media.
769
-
770
- **Post Object:**
771
-
772
- ```typescript
773
- {
774
- id: string; // Unique post identifier
775
- account_id: string; // Account that posted this
776
- type: 'video' | 'slideshow'; // Post type
777
- status: string; // Current post status
778
- social_id: string | null; // Platform post ID (TikTok video ID or Instagram reel code)
779
- caption: string | null; // Post caption/description
780
- media_urls: string[] | null; // URLs to media files
781
- music_post_id: string | null; // Associated music/audio ID
782
- }
783
- ```
784
-
785
- | Field | Type | Description |
786
- |-------|------|-------------|
787
- | `id` | `string` | Unique identifier for this post |
788
- | `account_id` | `string` | ID of the account that created this post |
789
- | `type` | `'video' \| 'slideshow'` | Type of post content |
790
- | `status` | `string` | Current status: `'scheduled'`, `'pending'`, `'complete'`, or `'failed'` |
791
- | `social_id` | `string \| null` | Platform-specific post ID (TikTok video ID or Instagram reel code, available after posting) |
792
- | `caption` | `string \| null` | Post caption/description text (max 500 characters) |
793
- | `media_urls` | `string[] \| null` | Array of URLs to video/image files used in the post |
794
- | `music_post_id` | `string \| null` | ID of the music/audio track used in the post |
795
-
796
- **Example:**
797
-
798
- ```typescript
799
- const response = await client.posts.getPosts({
800
- accountIds: ['account-1'],
801
- startDate: '2024-01-01T00:00:00Z',
802
- endDate: '2024-12-31T23:59:59Z'
803
- });
804
- ```
805
-
806
- ---
807
-
808
- #### `client.posts.createSlideshow(params)`
809
-
810
- Create a slideshow post from multiple images.
811
-
812
- **Endpoint:** `POST /post/slideshow`
813
-
814
- **Parameters:**
815
-
816
- | Parameter | Type | Required | Description |
817
- |-----------|------|----------|-------------|
818
- | `accountId` | `string` | **Yes** | Account ID to post from |
819
- | `imageUrls` | `string[]` | **Yes** | Array of image URLs (at least 1 required) |
820
- | `caption` | `string` | No | Post caption (max 500 characters) |
821
- | `musicPostId` | `string` | No | Music/audio post ID to use |
822
- | `postTime` | `string` | No | When to schedule the post (ISO 8601) |
823
- | `strict` | `boolean` | No | Strict mode (default: true) |
824
-
825
- **Returns:** `ApiResponse<Post>`
826
-
827
- Returns a Post object for the newly created slideshow. The post will be scheduled for publishing based on the `postTime` parameter (or immediately if not specified). The `status` field indicates whether it's scheduled, pending, or complete.
828
-
829
- **Example:**
830
-
831
- ```typescript
832
- const response = await client.posts.createSlideshow({
833
- accountId: 'account-id',
834
- imageUrls: [
835
- 'https://storage.example.com/img1.jpg',
836
- 'https://storage.example.com/img2.jpg',
837
- 'https://storage.example.com/img3.jpg'
838
- ],
839
- caption: 'Check out these photos! 📸',
840
- postTime: '2024-12-25T12:00:00Z'
841
- });
842
- ```
843
-
844
- ---
845
-
846
- #### `client.posts.createVideo(params)`
847
-
848
- Create a video post.
849
-
850
- **Endpoint:** `POST /post/video`
851
-
852
- **Parameters:**
853
-
854
- | Parameter | Type | Required | Description |
855
- |-----------|------|----------|-------------|
856
- | `accountId` | `string` | **Yes** | Account ID to post from |
857
- | `videoUrl` | `string` | **Yes** | Video file URL |
858
- | `caption` | `string` | No | Post caption (max 500 characters) |
859
- | `musicPostId` | `string` | No | Music/audio post ID to use |
860
- | `postTime` | `string` | No | When to schedule the post (ISO 8601) |
861
- | `strict` | `boolean` | No | Strict mode (default: true) |
862
-
863
- **Returns:** `ApiResponse<Post>`
864
-
865
- Returns a Post object for the newly created video post. The post will be scheduled for publishing based on the `postTime` parameter (or immediately if not specified). The `status` field indicates whether it's scheduled, pending, or complete.
866
-
867
- **Example:**
868
-
869
- ```typescript
870
- const response = await client.posts.createVideo({
871
- accountId: 'account-id',
872
- videoUrl: 'https://storage.example.com/video.mp4',
873
- caption: 'My awesome video! 🎥 #viral',
874
- strict: false
875
- });
876
- ```
877
-
878
- ---
879
-
880
- #### `client.posts.getStats(params?)`
881
-
882
- Get post statistics.
883
-
884
- **Endpoint:** `POST /post/stats`
885
-
886
- **Parameters:**
887
-
888
- | Parameter | Type | Required | Description |
889
- |-----------|------|----------|-------------|
890
- | `postIds` | `string[]` | No | Array of post IDs to get stats for |
891
- | `startDate` | `string` | No | Start date (ISO 8601 format) |
892
- | `endDate` | `string` | No | End date (ISO 8601 format) |
893
-
894
- **Returns:** `ApiResponse<PostStat[]>`
895
-
896
- Returns an array of PostStat objects containing engagement metrics (views, likes, comments, shares, saves) for the specified posts and date range. Use this to track post performance over time.
897
-
898
- **PostStat Object:**
899
-
900
- ```typescript
901
- {
902
- id: string; // Unique stat record identifier
903
- post_id: string; // Associated post ID
904
- views: number | null; // View count
905
- likes: number | null; // Like count
906
- comments: number | null; // Comment count
907
- shares: number | null; // Share count
908
- saves: number | null; // Save/bookmark count
909
- created_at: string; // When stat was recorded
910
- }
911
- ```
912
-
913
- | Field | Type | Description |
914
- |-------|------|-------------|
915
- | `id` | `string` | Unique identifier for this stat record |
916
- | `post_id` | `string` | ID of the post these stats belong to |
917
- | `views` | `number \| null` | Total number of views the post received |
918
- | `likes` | `number \| null` | Total number of likes the post received |
919
- | `comments` | `number \| null` | Total number of comments on the post |
920
- | `shares` | `number \| null` | Total number of times the post was shared |
921
- | `saves` | `number \| null` | Total number of times the post was saved/bookmarked |
922
- | `created_at` | `string` | ISO 8601 timestamp when this stat was recorded |
923
-
924
- **Example:**
925
-
926
- ```typescript
927
- const response = await client.posts.getStats({
928
- postIds: ['post-1', 'post-2', 'post-3'],
929
- startDate: '2024-01-01T00:00:00Z'
930
- });
931
-
932
- if (response.ok) {
933
- response.data.forEach(stat => {
934
- console.log(`Post ${stat.post_id}:`);
935
- console.log(` Views: ${stat.views}`);
936
- console.log(` Likes: ${stat.likes}`);
937
- console.log(` Engagement: ${(stat.likes ?? 0) + (stat.comments ?? 0)}`);
938
- });
939
- }
940
- ```
941
-
942
- ---
943
-
944
- #### `client.posts.refreshStats(params?)`
945
-
946
- Refresh post statistics by fetching live data from TikTok/Instagram API.
947
-
948
- **Endpoint:** `POST /post/stats/refresh`
949
-
950
- **Parameters:**
951
-
952
- | Parameter | Type | Required | Description |
953
- |-----------|------|----------|-------------|
954
- | `postIds` | `string[]` | No | Array of post IDs to refresh stats for |
955
-
956
- **Returns:** `ApiResponse<PostStat[]>`
957
-
958
- Returns an array of newly created PostStat objects with live data from TikTok or Instagram. This endpoint fetches fresh statistics directly from the platform APIs and creates new stat records in the database. Use this when you need up-to-date engagement metrics instead of historical data. The API automatically determines which platform to query based on the account type.
959
-
960
- **Key Differences from `getStats()`:**
961
- - `refreshStats()` fetches **live data** from TikTok/Instagram API and creates new records
962
- - `getStats()` retrieves **historical data** from your database
963
-
964
- **Important:** Posts must have a valid `social_id` (TikTok video ID or Instagram reel code) to refresh statistics. The endpoint uses this ID to fetch live metrics from the platform.
965
-
966
- **Example:**
967
-
968
- ```typescript
969
- const response = await client.posts.refreshStats({
970
- postIds: ['post-1', 'post-2', 'post-3']
971
- });
972
-
973
- if (response.ok) {
974
- console.log(`Successfully refreshed ${response.data.length} posts`);
975
- response.data.forEach(stat => {
976
- console.log(`Post ${stat.post_id}:`);
977
- console.log(` Views: ${stat.views}`);
978
- console.log(` Likes: ${stat.likes}`);
979
- console.log(` Comments: ${stat.comments}`);
980
- console.log(` Engagement Rate: ${((stat.likes ?? 0) / (stat.views ?? 1) * 100).toFixed(2)}%`);
981
- });
982
- }
983
-
984
- // Refresh all posts (no filters)
985
- const allPostsResponse = await client.posts.refreshStats();
986
- ```
987
-
988
- ---
989
-
990
- #### `client.posts.getStatus(params)`
991
-
992
- Get the status of a specific post.
993
-
994
- **Endpoint:** `POST /post/status`
995
-
996
- **Parameters:**
997
-
998
- | Parameter | Type | Required | Description |
999
- |-----------|------|----------|-------------|
1000
- | `postId` | `string` | **Yes** | Post ID to check status for |
36
+ **Important:** Keep your API key secure! Never commit it to version control or expose it in client-side code.
1001
37
 
1002
- **Returns:** `ApiResponse<{ post_id: string; status: string }>`
38
+ ## Documentation
1003
39
 
1004
- Returns the current status of the specified post. Use this to check if a post has been successfully published or if there were any issues.
40
+ For complete API documentation, including all endpoints, parameters, and examples, visit:
1005
41
 
1006
- **Response Object:**
42
+ **[docs.ugc.inc](https://docs.ugc.inc)**
1007
43
 
1008
- ```typescript
1009
- {
1010
- post_id: string; // ID of the post being checked
1011
- status: string; // Current status
1012
- }
1013
- ```
1014
-
1015
- **Status Values:** `'scheduled' | 'pending' | 'complete' | 'failed'`
1016
-
1017
- - `'scheduled'` - Post is scheduled to be published at a future time
1018
- - `'pending'` - Post is currently being processed/published
1019
- - `'complete'` - Post was successfully published
1020
- - `'failed'` - Post failed to publish (check error logs)
44
+ ## TypeScript Support
1021
45
 
1022
- **Example:**
46
+ This package is written in TypeScript and provides full type definitions:
1023
47
 
1024
48
  ```typescript
1025
- const response = await client.posts.getStatus({
1026
- postId: 'post-id'
1027
- });
1028
-
1029
- if (response.ok) {
1030
- console.log(`Post status: ${response.data.status}`);
1031
- }
49
+ import type { Account, Post, Task, ApiResponse } from 'ugcinc';
1032
50
  ```
1033
51
 
1034
- ---
1035
-
1036
52
  ## License
1037
53
 
1038
54
  MIT
1039
-
@@ -1,5 +1,5 @@
1
1
  import { BaseClient } from './base';
2
- import type { Account, AccountStat, AccountTask, GetAccountsParams, GetAccountStatsParams, RefreshAccountStatsParams, GetAccountStatusParams, UpdateAccountInfoParams, UpdateAccountSocialParams, ApiResponse } from './types';
2
+ import type { Account, AccountTask, GetAccountsParams, GetAccountStatusParams, UpdateAccountInfoParams, UpdateAccountSocialParams, ApiResponse } from './types';
3
3
  /**
4
4
  * Client for managing accounts
5
5
  */
@@ -9,17 +9,9 @@ export declare class AccountsClient extends BaseClient {
9
9
  */
10
10
  getAccounts(params?: GetAccountsParams): Promise<ApiResponse<Account[]>>;
11
11
  /**
12
- * Get account statistics
12
+ * Get account status (tasks) for one or more accounts
13
13
  */
14
- getStats(params?: GetAccountStatsParams): Promise<ApiResponse<AccountStat[]>>;
15
- /**
16
- * Refresh account statistics from TikTok/Instagram API
17
- */
18
- refreshStats(params?: RefreshAccountStatsParams): Promise<ApiResponse<AccountStat[]>>;
19
- /**
20
- * Get account status (tasks)
21
- */
22
- getStatus(params: GetAccountStatusParams): Promise<ApiResponse<AccountTask[]>>;
14
+ getStatus(params?: GetAccountStatusParams): Promise<ApiResponse<AccountTask[]>>;
23
15
  /**
24
16
  * Update account metadata (tag, org_group, user_group)
25
17
  */
package/dist/accounts.js CHANGED
@@ -13,22 +13,10 @@ class AccountsClient extends base_1.BaseClient {
13
13
  return this.post('/accounts', params ?? {});
14
14
  }
15
15
  /**
16
- * Get account statistics
17
- */
18
- async getStats(params) {
19
- return this.post('/accounts/stats', params ?? {});
20
- }
21
- /**
22
- * Refresh account statistics from TikTok/Instagram API
23
- */
24
- async refreshStats(params) {
25
- return this.post('/accounts/stats/refresh', params ?? {});
26
- }
27
- /**
28
- * Get account status (tasks)
16
+ * Get account status (tasks) for one or more accounts
29
17
  */
30
18
  async getStatus(params) {
31
- return this.post('/accounts/status', params);
19
+ return this.post('/accounts/status', params ?? {});
32
20
  }
33
21
  /**
34
22
  * Update account metadata (tag, org_group, user_group)
package/dist/client.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { AccountsClient } from './accounts';
2
2
  import { TasksClient } from './tasks';
3
3
  import { PostsClient } from './posts';
4
+ import { StatsClient } from './stats';
4
5
  import type { ClientConfig } from './base';
5
6
  /**
6
7
  * Main UGC Inc API Client
@@ -40,5 +41,9 @@ export declare class UGCClient {
40
41
  * Client for post-related operations
41
42
  */
42
43
  posts: PostsClient;
44
+ /**
45
+ * Client for statistics operations
46
+ */
47
+ stats: StatsClient;
43
48
  constructor(config: ClientConfig);
44
49
  }
package/dist/client.js CHANGED
@@ -4,6 +4,7 @@ exports.UGCClient = void 0;
4
4
  const accounts_1 = require("./accounts");
5
5
  const tasks_1 = require("./tasks");
6
6
  const posts_1 = require("./posts");
7
+ const stats_1 = require("./stats");
7
8
  /**
8
9
  * Main UGC Inc API Client
9
10
  *
@@ -34,6 +35,7 @@ class UGCClient {
34
35
  this.accounts = new accounts_1.AccountsClient(config);
35
36
  this.tasks = new tasks_1.TasksClient(config);
36
37
  this.posts = new posts_1.PostsClient(config);
38
+ this.stats = new stats_1.StatsClient(config);
37
39
  }
38
40
  }
39
41
  exports.UGCClient = UGCClient;
package/dist/index.d.ts CHANGED
@@ -7,5 +7,6 @@ export { UGCClient } from './client';
7
7
  export { AccountsClient } from './accounts';
8
8
  export { TasksClient } from './tasks';
9
9
  export { PostsClient } from './posts';
10
+ export { StatsClient } from './stats';
10
11
  export type { ClientConfig, } from './base';
11
- export type { SuccessResponse, ErrorResponse, ApiResponse, Account, AccountStat, AccountTask, EditProfileInfo, Task, TaskType, Post, PostType, PostStat, GetAccountsParams, GetAccountStatsParams, GetAccountStatusParams, UpdateAccountInfoParams, GetTasksParams, GetPostsParams, CreateSlideshowParams, GetPostStatsParams, GetPostStatusParams, CreateVideoParams, } from './types';
12
+ export type { SuccessResponse, ErrorResponse, ApiResponse, Account, AccountStat, AccountTask, EditProfileInfo, Task, TaskType, Post, PostType, PostStat, GetAccountsParams, GetAccountStatsParams, GetAccountStatusParams, UpdateAccountInfoParams, GetTasksParams, GetPostsParams, CreateSlideshowParams, GetPostStatsParams, GetPostStatusParams, CreateVideoParams, RefreshStatsParams, RefreshStatsResponse, } from './types';
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * Official TypeScript/JavaScript client for the UGC Inc API
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.PostsClient = exports.TasksClient = exports.AccountsClient = exports.UGCClient = void 0;
8
+ exports.StatsClient = exports.PostsClient = exports.TasksClient = exports.AccountsClient = exports.UGCClient = void 0;
9
9
  var client_1 = require("./client");
10
10
  Object.defineProperty(exports, "UGCClient", { enumerable: true, get: function () { return client_1.UGCClient; } });
11
11
  var accounts_1 = require("./accounts");
@@ -14,3 +14,5 @@ var tasks_1 = require("./tasks");
14
14
  Object.defineProperty(exports, "TasksClient", { enumerable: true, get: function () { return tasks_1.TasksClient; } });
15
15
  var posts_1 = require("./posts");
16
16
  Object.defineProperty(exports, "PostsClient", { enumerable: true, get: function () { return posts_1.PostsClient; } });
17
+ var stats_1 = require("./stats");
18
+ Object.defineProperty(exports, "StatsClient", { enumerable: true, get: function () { return stats_1.StatsClient; } });
package/dist/posts.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BaseClient } from './base';
2
- import type { Post, PostStat, GetPostsParams, CreateSlideshowParams, GetPostStatsParams, RefreshPostStatsParams, GetPostStatusParams, CreateVideoParams, ApiResponse } from './types';
2
+ import type { Post, GetPostsParams, CreateSlideshowParams, GetPostStatusParams, CreateVideoParams, ApiResponse } from './types';
3
3
  /**
4
4
  * Client for managing posts
5
5
  */
@@ -12,15 +12,6 @@ export declare class PostsClient extends BaseClient {
12
12
  * Create a slideshow post
13
13
  */
14
14
  createSlideshow(params: CreateSlideshowParams): Promise<ApiResponse<Post>>;
15
- /**
16
- * Get post statistics
17
- */
18
- getStats(params?: GetPostStatsParams): Promise<ApiResponse<PostStat[]>>;
19
- /**
20
-
21
- * Refresh post statistics from TikTok/Instagram API
22
- */
23
- refreshStats(params?: RefreshPostStatsParams): Promise<ApiResponse<PostStat[]>>;
24
15
  /**
25
16
  * Get post status
26
17
  */
package/dist/posts.js CHANGED
@@ -18,19 +18,6 @@ class PostsClient extends base_1.BaseClient {
18
18
  async createSlideshow(params) {
19
19
  return this.post('/post/slideshow', params);
20
20
  }
21
- /**
22
- * Get post statistics
23
- */
24
- async getStats(params) {
25
- return this.post('/post/stats', params ?? {});
26
- }
27
- /**
28
-
29
- * Refresh post statistics from TikTok/Instagram API
30
- */
31
- async refreshStats(params) {
32
- return this.post('/post/stats/refresh', params ?? {});
33
- }
34
21
  /**
35
22
  * Get post status
36
23
  */
@@ -0,0 +1,20 @@
1
+ import { BaseClient } from './base';
2
+ import type { AccountStat, PostStat, GetAccountStatsParams, GetPostStatsParams, RefreshStatsParams, RefreshStatsResponse, ApiResponse } from './types';
3
+ /**
4
+ * Client for managing statistics
5
+ */
6
+ export declare class StatsClient extends BaseClient {
7
+ /**
8
+ * Get account statistics
9
+ */
10
+ getAccountStats(params?: GetAccountStatsParams): Promise<ApiResponse<AccountStat[]>>;
11
+ /**
12
+ * Get post statistics
13
+ */
14
+ getPostStats(params?: GetPostStatsParams): Promise<ApiResponse<PostStat[]>>;
15
+ /**
16
+ * Refresh statistics for an account and all its posts
17
+ * Fetches live data from TikTok/Instagram API and creates new stat records
18
+ */
19
+ refresh(params: RefreshStatsParams): Promise<ApiResponse<RefreshStatsResponse>>;
20
+ }
package/dist/stats.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StatsClient = void 0;
4
+ const base_1 = require("./base");
5
+ /**
6
+ * Client for managing statistics
7
+ */
8
+ class StatsClient extends base_1.BaseClient {
9
+ /**
10
+ * Get account statistics
11
+ */
12
+ async getAccountStats(params) {
13
+ return this.post('/stats/accounts', params ?? {});
14
+ }
15
+ /**
16
+ * Get post statistics
17
+ */
18
+ async getPostStats(params) {
19
+ return this.post('/stats/posts', params ?? {});
20
+ }
21
+ /**
22
+ * Refresh statistics for an account and all its posts
23
+ * Fetches live data from TikTok/Instagram API and creates new stat records
24
+ */
25
+ async refresh(params) {
26
+ return this.post('/stats/refresh', params);
27
+ }
28
+ }
29
+ exports.StatsClient = StatsClient;
package/dist/types.d.ts CHANGED
@@ -53,7 +53,7 @@ export interface EditProfileInfo {
53
53
  /**
54
54
  * Task types
55
55
  */
56
- export type TaskType = 'warmup_scroll' | 'warmup_search_term' | 'warmup_search_profile' | 'edit_profile';
56
+ export type TaskType = 'warmup_scroll' | 'warmup_search_term' | 'warmup_search_profile' | 'edit_profile' | 'update_posts';
57
57
  export interface Task {
58
58
  id: string;
59
59
  account_id: string;
@@ -61,7 +61,7 @@ export interface Task {
61
61
  status: string;
62
62
  scheduled_time: string | null;
63
63
  duration: number | null;
64
- keywords: string[] | null;
64
+ keywords: string | null;
65
65
  edit_profile_info: EditProfileInfo | null;
66
66
  created_at: string;
67
67
  }
@@ -105,14 +105,8 @@ export interface GetAccountStatsParams {
105
105
  org_group?: string;
106
106
  user_group?: string;
107
107
  }
108
- export interface RefreshAccountStatsParams {
109
- accountIds?: string[];
110
- tag?: string;
111
- org_group?: string;
112
- user_group?: string;
113
- }
114
108
  export interface GetAccountStatusParams {
115
- accountId: string;
109
+ accountIds?: string[];
116
110
  includeCompleted?: boolean;
117
111
  }
118
112
  export interface UpdateAccountInfoParams {
@@ -151,9 +145,6 @@ export interface GetPostStatsParams {
151
145
  startDate?: string;
152
146
  endDate?: string;
153
147
  }
154
- export interface RefreshPostStatsParams {
155
- postIds?: string[];
156
- }
157
148
  export interface GetPostStatusParams {
158
149
  postId: string;
159
150
  }
@@ -165,3 +156,11 @@ export interface CreateVideoParams {
165
156
  videoUrl: string;
166
157
  strict?: boolean;
167
158
  }
159
+ export interface RefreshStatsParams {
160
+ accountId: string;
161
+ }
162
+ export interface RefreshStatsResponse {
163
+ account_stats: AccountStat;
164
+ post_stats: PostStat[];
165
+ post_stats_count: number;
166
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugcinc",
3
- "version": "1.0.6",
3
+ "version": "1.0.9",
4
4
  "description": "TypeScript/JavaScript client for the UGC Inc API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",