-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathimagesApi.ts
388 lines (324 loc) · 17.3 KB
/
imagesApi.ts
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
/**
* Klaviyo API
* The Klaviyo REST API. Please visit https://developers.klaviyo.com for more details.
*
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
const axios = require('axios');
import {AxiosRequestConfig, AxiosResponse} from "axios";
import FormData from 'form-data'
/* tslint:disable:no-unused-locals */
import { GetAccounts4XXResponse } from '../model/getAccounts4XXResponse';
import { GetImageResponse } from '../model/getImageResponse';
import { GetImageResponseCollection } from '../model/getImageResponseCollection';
import { ImageCreateQuery } from '../model/imageCreateQuery';
import { ImagePartialUpdateQuery } from '../model/imagePartialUpdateQuery';
import { PatchImageResponse } from '../model/patchImageResponse';
import { PostImageResponse } from '../model/postImageResponse';
import { ObjectSerializer } from '../model/models';
import {RequestFile, queryParamPreProcessor, RetryWithExponentialBackoff, Session} from './apis';
let defaultBasePath = 'https://a.klaviyo.com';
// ===============================================
// This file is autogenerated - Please do not edit
// ===============================================
export class ImagesApi {
session: Session
protected _basePath = defaultBasePath;
protected _defaultHeaders : any = {};
protected _useQuerystring : boolean = false;
constructor(session: Session){
this.session = session
}
set useQuerystring(value: boolean) {
this._useQuerystring = value;
}
set basePath(basePath: string) {
this._basePath = basePath;
}
set defaultHeaders(defaultHeaders: any) {
this._defaultHeaders = defaultHeaders;
}
get defaultHeaders() {
return this._defaultHeaders;
}
get basePath() {
return this._basePath;
}
/**
* Get the image with the given image ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `images:read`
* @summary Get Image
* @param id The ID of the image
* @param fieldsImage For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#sparse-fieldsets
*/
public async getImage (id: string, options: { fieldsImage?: Array<'name' | 'image_url' | 'format' | 'size' | 'hidden' | 'updated_at'>, } = {}): Promise<{ response: AxiosResponse; body: GetImageResponse; }> {
const localVarPath = this.basePath + '/api/images/{id}'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getImage.');
}
if (options.fieldsImage !== undefined) {
localVarQueryParameters['fields[image]'] = ObjectSerializer.serialize(options.fieldsImage, "Array<'name' | 'image_url' | 'format' | 'size' | 'hidden' | 'updated_at'>");
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetImageResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetImageResponse");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get all images in an account.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `images:read`
* @summary Get Images
* @param fieldsImage For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#sparse-fieldsets* @param filter For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`id`: `any`, `equals`<br>`updated_at`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`<br>`format`: `any`, `equals`<br>`name`: `any`, `contains`, `ends-with`, `equals`, `starts-with`<br>`size`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`<br>`hidden`: `any`, `equals`* @param pageCursor For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#pagination* @param pageSize Default: 20. Min: 1. Max: 100.* @param sort For more information please visit https://developers.klaviyo.com/en/v2025-01-15/reference/api-overview#sorting
*/
public async getImages (options: { fieldsImage?: Array<'name' | 'image_url' | 'format' | 'size' | 'hidden' | 'updated_at'>, filter?: string, pageCursor?: string, pageSize?: number, sort?: 'format' | '-format' | 'id' | '-id' | 'name' | '-name' | 'size' | '-size' | 'updated_at' | '-updated_at', } = {}): Promise<{ response: AxiosResponse; body: GetImageResponseCollection; }> {
const localVarPath = this.basePath + '/api/images';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
if (options.fieldsImage !== undefined) {
localVarQueryParameters['fields[image]'] = ObjectSerializer.serialize(options.fieldsImage, "Array<'name' | 'image_url' | 'format' | 'size' | 'hidden' | 'updated_at'>");
}
if (options.filter !== undefined) {
localVarQueryParameters['filter'] = ObjectSerializer.serialize(options.filter, "string");
}
if (options.pageCursor !== undefined) {
localVarQueryParameters['page[cursor]'] = ObjectSerializer.serialize(options.pageCursor, "string");
}
if (options.pageSize !== undefined) {
localVarQueryParameters['page[size]'] = ObjectSerializer.serialize(options.pageSize, "number");
}
if (options.sort !== undefined) {
localVarQueryParameters['sort'] = ObjectSerializer.serialize(options.sort, "'format' | '-format' | 'id' | '-id' | 'name' | '-name' | 'size' | '-size' | 'updated_at' | '-updated_at'");
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetImageResponseCollection; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetImageResponseCollection");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Update the image with the given image ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` **Scopes:** `images:write`
* @summary Update Image
* @param id The ID of the image* @param imagePartialUpdateQuery
*/
public async updateImage (id: string, imagePartialUpdateQuery: ImagePartialUpdateQuery, ): Promise<{ response: AxiosResponse; body: PatchImageResponse; }> {
const localVarPath = this.basePath + '/api/images/{id}'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling updateImage.');
}
// verify required parameter 'imagePartialUpdateQuery' is not null or undefined
if (imagePartialUpdateQuery === null || imagePartialUpdateQuery === undefined) {
throw new Error('Required parameter imagePartialUpdateQuery was null or undefined when calling updateImage.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'PATCH',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
data: ObjectSerializer.serialize(imagePartialUpdateQuery, "ImagePartialUpdateQuery")
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: PatchImageResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "PatchImageResponse");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Upload an image from a file. If you want to import an image from an existing url or a data uri, use the Upload Image From URL endpoint instead.<br><br>*Rate limits*:<br>Burst: `3/s`<br>Steady: `100/m`<br>Daily: `100/d` **Scopes:** `images:write`
* @summary Upload Image From File
* @param file The image file to upload. Supported image formats: jpeg,png,gif. Maximum image size: 5MB.
* @param name A name for the image. Defaults to the filename if not provided. If the name matches an existing image, a suffix will be added.* @param hidden If true, this image is not shown in the asset library.
*/
public async uploadImageFromFile (file: RequestFile, name?: string, hidden?: boolean, ): Promise<{ response: AxiosResponse; body: PostImageResponse; }> {
const localVarPath = this.basePath + '/api/image-upload';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
const form = new FormData();
// verify required parameter 'file' is not null or undefined
if (file === null || file === undefined) {
throw new Error('Required parameter file was null or undefined when calling uploadImageFromFile.');
}
if (file !== undefined) {
form.append('file', file);
}
if (name !== undefined) {
form.append('name', name.toString());
}
if (hidden !== undefined) {
form.append('hidden', hidden.toString());
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'POST',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
data: form,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: PostImageResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "PostImageResponse");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Import an image from a url or data uri. If you want to upload an image from a file, use the Upload Image From File endpoint instead.<br><br>*Rate limits*:<br>Burst: `3/s`<br>Steady: `100/m`<br>Daily: `100/d` **Scopes:** `images:write`
* @summary Upload Image From URL
* @param imageCreateQuery
*/
public async uploadImageFromUrl (imageCreateQuery: ImageCreateQuery, ): Promise<{ response: AxiosResponse; body: PostImageResponse; }> {
const localVarPath = this.basePath + '/api/images';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'imageCreateQuery' is not null or undefined
if (imageCreateQuery === null || imageCreateQuery === undefined) {
throw new Error('Required parameter imageCreateQuery was null or undefined when calling uploadImageFromUrl.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'POST',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
data: ObjectSerializer.serialize(imageCreateQuery, "ImageCreateQuery")
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: PostImageResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "PostImageResponse");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
}
export interface ImagesApi {
/**
* Alias of {@link ImagesApi.uploadImageFromFile}
*
* @deprecated Use {@link ImagesApi.uploadImageFromFile} instead
*/
createImageUpload: typeof ImagesApi.prototype.uploadImageFromFile;
}
ImagesApi.prototype.createImageUpload = ImagesApi.prototype.uploadImageFromFile
export interface ImagesApi {
/**
* Alias of {@link ImagesApi.uploadImageFromUrl}
*
* @deprecated Use {@link ImagesApi.uploadImageFromUrl} instead
*/
createImage: typeof ImagesApi.prototype.uploadImageFromUrl;
}
ImagesApi.prototype.createImage = ImagesApi.prototype.uploadImageFromUrl