Skip to content

Commit f2e7db6

Browse files
author
Jeff Shillitto
committed
Add Serve API transfer and examples
1 parent 4ef41ef commit f2e7db6

8 files changed

Lines changed: 350 additions & 3 deletions

‎README.md‎

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Check generation status:
100100
import Shotstack, { CreateApiApiKeys } from './dist/index.js';
101101

102102
const apiKey = 'YOUR_API_KEY';
103-
const basePath = 'https://api.shotstack.io/create/dev';
103+
const basePath = 'https://api.shotstack.io/create/v1';
104104

105105
const CreateApi = new Shotstack.CreateApi(basePath);
106106
CreateApi.setApiKey(CreateApiApiKeys.DeveloperKey, apiKey);
@@ -113,3 +113,58 @@ CreateApi.getGeneratedAsset(assetId).then((data) => {
113113
}
114114
});
115115
```
116+
117+
#### Serve API
118+
119+
Transfer a file to a destination (Pexels to AWS S3):
120+
121+
```javascript
122+
import Shotstack, { ServeApiApiKeys } from './dist/index.js';
123+
124+
const apiKey = 'YOUR_API_KEY';
125+
const basePath = 'https://api.shotstack.io/serve/v1';
126+
127+
const ServeApi = new Shotstack.ServeApi(basePath);
128+
ServeApi.setApiKey(ServeApiApiKeys.DeveloperKey, apiKey);
129+
130+
const s3DestinationOptions = new Shotstack.S3DestinationOptions();
131+
s3DestinationOptions.region = 'ap-southeast-2';
132+
s3DestinationOptions.bucket = 'my-bucket';
133+
s3DestinationOptions.prefix = 'testing';
134+
s3DestinationOptions.filename = 'photo';
135+
s3DestinationOptions.acl = 'public-read';
136+
137+
const s3Destination = new Shotstack.S3Destination();
138+
s3Destination.options = s3DestinationOptions;
139+
140+
const transfer = new Shotstack.Transfer();
141+
transfer.url = 'https://images.pexels.com/photos/1547813/pexels-photo-1547813.jpeg';
142+
transfer.id = 'MY_ASSET_ID';
143+
transfer.destinations = [s3Destination];
144+
145+
ServeApi.postServeAsset(transfer).then((data) => {
146+
console.log(data.response.body);
147+
});
148+
```
149+
150+
Get asset details:
151+
152+
```javascript
153+
import Shotstack, { ServeApiApiKeys } from './dist/index.js';
154+
155+
const apiKey = 'YOUR_API_KEY';
156+
const basePath = 'https://api.shotstack.io/serve/v1';
157+
158+
const ServeApi = new Shotstack.ServeApi(basePath);
159+
ServeApi.setApiKey(ServeApiApiKeys.DeveloperKey, apiKey);
160+
161+
const assetId = 'MY_ASSET_ID'; // User created asset ID, render ID or source/rendition ID
162+
163+
ServeApi.getAssetByRenderId(assetId).then((data) => {
164+
if (data.response.body.data[0].attributes.status === 'ready') {
165+
ServeApi.getAsset(data.response.body.data[0].attributes.id).then((data) => {
166+
console.log(data.response.body.data.attributes.url);
167+
});
168+
}
169+
});
170+
```

‎src/api/serveApi.ts‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import http from 'http';
1717
/* tslint:disable:no-unused-locals */
1818
import { AssetRenderResponse } from '../model/assetRenderResponse';
1919
import { AssetResponse } from '../model/assetResponse';
20+
import { Transfer } from '../model/transfer';
21+
import { TransferResponse } from '../model/transferResponse';
2022

2123
import { ObjectSerializer, Authentication, VoidAuth, Interceptor } from '../model/models';
2224
import { HttpBasicAuth, HttpBearerAuth, ApiKeyAuth, OAuth } from '../model/models';
@@ -298,4 +300,76 @@ export class ServeApi {
298300
});
299301
});
300302
}
303+
/**
304+
* Transfer a file from any publicly available URL to one or more Serve API [destinations](#tocs_destinations). **Base URL:** https://api.shotstack.io/serve/{version}
305+
* @summary Transfer Asset
306+
* @param transfer Fetch an asset from a URL and send it to one or more destinations.
307+
*/
308+
public async postServeAsset (transfer: Transfer, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: TransferResponse; }> {
309+
const localVarPath = this.basePath + '/assets';
310+
let localVarQueryParameters: any = {};
311+
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
312+
const produces = ['application/json'];
313+
// give precedence to 'application/json'
314+
if (produces.indexOf('application/json') >= 0) {
315+
localVarHeaderParams.Accept = 'application/json';
316+
} else {
317+
localVarHeaderParams.Accept = produces.join(',');
318+
}
319+
let localVarFormParams: any = {};
320+
321+
// verify required parameter 'transfer' is not null or undefined
322+
if (transfer === null || transfer === undefined) {
323+
throw new Error('Required parameter transfer was null or undefined when calling postServeAsset.');
324+
}
325+
326+
(<any>Object).assign(localVarHeaderParams, options.headers);
327+
328+
let localVarUseFormData = false;
329+
330+
let localVarRequestOptions: localVarRequest.Options = {
331+
method: 'POST',
332+
qs: localVarQueryParameters,
333+
headers: localVarHeaderParams,
334+
uri: localVarPath,
335+
useQuerystring: this._useQuerystring,
336+
json: true,
337+
body: ObjectSerializer.serialize(transfer, "Transfer")
338+
};
339+
340+
let authenticationPromise = Promise.resolve();
341+
if (this.authentications.DeveloperKey.apiKey) {
342+
authenticationPromise = authenticationPromise.then(() => this.authentications.DeveloperKey.applyToRequest(localVarRequestOptions));
343+
}
344+
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
345+
346+
let interceptorPromise = authenticationPromise;
347+
for (const interceptor of this.interceptors) {
348+
interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions));
349+
}
350+
351+
return interceptorPromise.then(() => {
352+
if (Object.keys(localVarFormParams).length) {
353+
if (localVarUseFormData) {
354+
(<any>localVarRequestOptions).formData = localVarFormParams;
355+
} else {
356+
localVarRequestOptions.form = localVarFormParams;
357+
}
358+
}
359+
return new Promise<{ response: http.IncomingMessage; body: TransferResponse; }>((resolve, reject) => {
360+
localVarRequest(localVarRequestOptions, (error, response, body) => {
361+
if (error) {
362+
reject(error);
363+
} else {
364+
if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) {
365+
body = ObjectSerializer.deserialize(body, "TransferResponse");
366+
resolve({ response: response, body: body });
367+
} else {
368+
reject(new HttpError(response, body, response.statusCode));
369+
}
370+
}
371+
});
372+
});
373+
});
374+
}
301375
}

‎src/model/assetResponseAttributes.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class AssetResponseAttributes {
2121
*/
2222
'id': string;
2323
/**
24-
* The owner id of the render task.
24+
* The owner id of the asset.
2525
*/
2626
'owner': string;
2727
/**

‎src/model/models.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ export * from './timeline';
8080
export * from './titleAsset';
8181
export * from './track';
8282
export * from './transcription';
83+
export * from './transfer';
84+
export * from './transferResponse';
85+
export * from './transferResponseAttributes';
86+
export * from './transferResponseData';
8387
export * from './transformation';
8488
export * from './transition';
8589
export * from './uploadResponse';
@@ -151,7 +155,6 @@ import { S3Destination } from './s3Destination';
151155
import { S3DestinationOptions } from './s3DestinationOptions';
152156
import { ShotstackDestination } from './shotstackDestination';
153157
import { ShotstackGeneratedAsset } from './shotstackGeneratedAsset';
154-
import { ShotstackGeneratedAssetOptions } from './shotstackGeneratedAssetOptions';
155158
import { ShotstackTextToImageOptions } from './shotstackTextToImageOptions';
156159
import { ShotstackTextToSpeechOptions } from './shotstackTextToSpeechOptions';
157160
import { Size } from './size';
@@ -176,6 +179,10 @@ import { Timeline } from './timeline';
176179
import { TitleAsset } from './titleAsset';
177180
import { Track } from './track';
178181
import { Transcription } from './transcription';
182+
import { Transfer } from './transfer';
183+
import { TransferResponse } from './transferResponse';
184+
import { TransferResponseAttributes } from './transferResponseAttributes';
185+
import { TransferResponseData } from './transferResponseData';
179186
import { Transformation } from './transformation';
180187
import { Transition } from './transition';
181188
import { UploadResponse } from './uploadResponse';
@@ -233,6 +240,7 @@ let enumsMap: {[index: string]: any} = {
233240
"Rendition.FpsEnum": Rendition.FpsEnum,
234241
"RenditionResponseAttributes.StatusEnum": RenditionResponseAttributes.StatusEnum,
235242
"ShotstackGeneratedAsset.ProviderEnum": ShotstackGeneratedAsset.ProviderEnum,
243+
"ShotstackTextToImageOptions.TypeEnum": ShotstackTextToImageOptions.TypeEnum,
236244
"ShotstackTextToSpeechOptions.TypeEnum": ShotstackTextToSpeechOptions.TypeEnum,
237245
"ShotstackTextToSpeechOptions.VoiceEnum": ShotstackTextToSpeechOptions.VoiceEnum,
238246
"ShotstackTextToSpeechOptions.LanguageEnum": ShotstackTextToSpeechOptions.LanguageEnum,
@@ -242,6 +250,7 @@ let enumsMap: {[index: string]: any} = {
242250
"TitleAsset.SizeEnum": TitleAsset.SizeEnum,
243251
"TitleAsset.PositionEnum": TitleAsset.PositionEnum,
244252
"Transcription.FormatEnum": Transcription.FormatEnum,
253+
"TransferResponseAttributes.StatusEnum": TransferResponseAttributes.StatusEnum,
245254
"Transition.InEnum": Transition.InEnum,
246255
"Transition.OutEnum": Transition.OutEnum,
247256
"VideoAsset.VolumeEffectEnum": VideoAsset.VolumeEffectEnum,
@@ -321,6 +330,10 @@ let typeMap: {[index: string]: any} = {
321330
"TitleAsset": TitleAsset,
322331
"Track": Track,
323332
"Transcription": Transcription,
333+
"Transfer": Transfer,
334+
"TransferResponse": TransferResponse,
335+
"TransferResponseAttributes": TransferResponseAttributes,
336+
"TransferResponseData": TransferResponseData,
324337
"Transformation": Transformation,
325338
"Transition": Transition,
326339
"UploadResponse": UploadResponse,

‎src/model/transfer.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Shotstack
3+
* Shotstack is a video, image and audio editing service that allows for the automated generation of videos, images and audio using JSON and a RESTful API. You arrange and configure an edit and POST it to the API which will render your media and provide a file location when complete. For more details visit [shotstack.io](https://shotstack.io) or checkout our [getting started](https://shotstack.io/docs/guide/) documentation. There are three API\'s, one for editing and generating assets (Edit API), one for managing hosted assets (Serve API) and one for ingesting and transforming source assets (Ingest API). Each API has it\'s own base URL and collection of endpoints. Each API uses the same set of API keys. **[Edit API](#shotstack-edit)** - [https://api.shotstack.io/edit/{version}](#)<br> Edit videos, images and audio assets in the cloud using a simple JSON schema and templates. **[Serve API](#shotstack-serve)** - [https://api.shotstack.io/serve/{version}](#)<br> Inspect and manage the hosting of assets generated by the Edit and Ingest APIs. **[Ingest API](#shotstack-ingest)** - [https://api.shotstack.io/ingest/{version}](#)<br> Ingest (upload, store and transform) source footage, images, audio and fonts to be used by the Edit API. **[Create API](#shotstack-create)** - [https://api.shotstack.io/create/{version}](#)<br> Generate images, videos, voice overs and text using built in and third party generative AI providers.
4+
*
5+
* The version of the OpenAPI document: v1
6+
*
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
13+
import { RequestFile } from './models';
14+
import { Destinations } from './destinations';
15+
16+
/**
17+
* The asset URL to fetch and transfer to a destination.
18+
*/
19+
export class Transfer {
20+
/**
21+
* The file URL to fetch and transfer.
22+
*/
23+
'url': string;
24+
/**
25+
* An identifier for the asset which must be provided by the client. The identifier does not need to be unique.
26+
*/
27+
'id': string;
28+
/**
29+
* Specify the storage locations and hosting services to send the file to.
30+
*/
31+
'destinations': Array<Destinations>;
32+
33+
static discriminator: string | undefined = undefined;
34+
35+
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
36+
{
37+
"name": "url",
38+
"baseName": "url",
39+
"type": "string"
40+
},
41+
{
42+
"name": "id",
43+
"baseName": "id",
44+
"type": "string"
45+
},
46+
{
47+
"name": "destinations",
48+
"baseName": "destinations",
49+
"type": "Array<Destinations>"
50+
} ];
51+
52+
static getAttributeTypeMap() {
53+
return Transfer.attributeTypeMap;
54+
}
55+
}
56+

‎src/model/transferResponse.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Shotstack
3+
* Shotstack is a video, image and audio editing service that allows for the automated generation of videos, images and audio using JSON and a RESTful API. You arrange and configure an edit and POST it to the API which will render your media and provide a file location when complete. For more details visit [shotstack.io](https://shotstack.io) or checkout our [getting started](https://shotstack.io/docs/guide/) documentation. There are three API\'s, one for editing and generating assets (Edit API), one for managing hosted assets (Serve API) and one for ingesting and transforming source assets (Ingest API). Each API has it\'s own base URL and collection of endpoints. Each API uses the same set of API keys. **[Edit API](#shotstack-edit)** - [https://api.shotstack.io/edit/{version}](#)<br> Edit videos, images and audio assets in the cloud using a simple JSON schema and templates. **[Serve API](#shotstack-serve)** - [https://api.shotstack.io/serve/{version}](#)<br> Inspect and manage the hosting of assets generated by the Edit and Ingest APIs. **[Ingest API](#shotstack-ingest)** - [https://api.shotstack.io/ingest/{version}](#)<br> Ingest (upload, store and transform) source footage, images, audio and fonts to be used by the Edit API. **[Create API](#shotstack-create)** - [https://api.shotstack.io/create/{version}](#)<br> Generate images, videos, voice overs and text using built in and third party generative AI providers.
4+
*
5+
* The version of the OpenAPI document: v1
6+
*
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
13+
import { RequestFile } from './models';
14+
import { TransferResponseData } from './transferResponseData';
15+
16+
/**
17+
* The response returned by the Serve API [transfer asset](#transfer-asset) request. The response includes the ID and transfer status. The response follows the [json:api](https://jsonapi.org/) specification.
18+
*/
19+
export class TransferResponse {
20+
'data': TransferResponseData;
21+
22+
static discriminator: string | undefined = undefined;
23+
24+
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
25+
{
26+
"name": "data",
27+
"baseName": "data",
28+
"type": "TransferResponseData"
29+
} ];
30+
31+
static getAttributeTypeMap() {
32+
return TransferResponse.attributeTypeMap;
33+
}
34+
}
35+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Shotstack
3+
* Shotstack is a video, image and audio editing service that allows for the automated generation of videos, images and audio using JSON and a RESTful API. You arrange and configure an edit and POST it to the API which will render your media and provide a file location when complete. For more details visit [shotstack.io](https://shotstack.io) or checkout our [getting started](https://shotstack.io/docs/guide/) documentation. There are three API\'s, one for editing and generating assets (Edit API), one for managing hosted assets (Serve API) and one for ingesting and transforming source assets (Ingest API). Each API has it\'s own base URL and collection of endpoints. Each API uses the same set of API keys. **[Edit API](#shotstack-edit)** - [https://api.shotstack.io/edit/{version}](#)<br> Edit videos, images and audio assets in the cloud using a simple JSON schema and templates. **[Serve API](#shotstack-serve)** - [https://api.shotstack.io/serve/{version}](#)<br> Inspect and manage the hosting of assets generated by the Edit and Ingest APIs. **[Ingest API](#shotstack-ingest)** - [https://api.shotstack.io/ingest/{version}](#)<br> Ingest (upload, store and transform) source footage, images, audio and fonts to be used by the Edit API. **[Create API](#shotstack-create)** - [https://api.shotstack.io/create/{version}](#)<br> Generate images, videos, voice overs and text using built in and third party generative AI providers.
4+
*
5+
* The version of the OpenAPI document: v1
6+
*
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
13+
import { RequestFile } from './models';
14+
15+
/**
16+
* The transfer request attributes inlcudling the user specified ID and status. Returned with [TransferResponseData](#tocs_transferresponsedata).
17+
*/
18+
export class TransferResponseAttributes {
19+
/**
20+
* The user provided ID for the asset
21+
*/
22+
'id'?: string;
23+
/**
24+
* The attributes of the asset transfer including the status.
25+
*/
26+
'owner'?: string;
27+
/**
28+
* The status of the asset transfer. <ul> <li>`queued` - the transfer request has been queued</li> <li>`failed` - the transfer request failed</li> </ul>
29+
*/
30+
'status'?: TransferResponseAttributes.StatusEnum;
31+
/**
32+
* The time the asset transfer was created.
33+
*/
34+
'created'?: string;
35+
36+
static discriminator: string | undefined = undefined;
37+
38+
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
39+
{
40+
"name": "id",
41+
"baseName": "id",
42+
"type": "string"
43+
},
44+
{
45+
"name": "owner",
46+
"baseName": "owner",
47+
"type": "string"
48+
},
49+
{
50+
"name": "status",
51+
"baseName": "status",
52+
"type": "TransferResponseAttributes.StatusEnum"
53+
},
54+
{
55+
"name": "created",
56+
"baseName": "created",
57+
"type": "string"
58+
} ];
59+
60+
static getAttributeTypeMap() {
61+
return TransferResponseAttributes.attributeTypeMap;
62+
}
63+
}
64+
65+
export namespace TransferResponseAttributes {
66+
export enum StatusEnum {
67+
QUEUED = <any> 'queued',
68+
FAILED = <any> 'failed'
69+
}
70+
}

0 commit comments

Comments
 (0)