@@ -70,24 +70,44 @@ func (r *WebhookService) Unwrap(payload []byte, headers http.Header, opts ...opt
7070 return res , nil
7171}
7272
73- type UploadPostTransformErrorEvent struct {
73+ type BaseWebhookEvent struct {
7474 // Unique identifier for the event.
7575 ID string `json:"id,required"`
76+ // The type of webhook event.
77+ Type string `json:"type,required"`
78+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
79+ JSON struct {
80+ ID respjson.Field
81+ Type respjson.Field
82+ ExtraFields map [string ]respjson.Field
83+ raw string
84+ } `json:"-"`
85+ }
86+
87+ // Returns the unmodified JSON received from the API
88+ func (r BaseWebhookEvent ) RawJSON () string { return r .JSON .raw }
89+ func (r * BaseWebhookEvent ) UnmarshalJSON (data []byte ) error {
90+ return apijson .UnmarshalRoot (data , r )
91+ }
92+
93+ // Triggered when a post-transformation fails. The original file remains available,
94+ // but the requested transformation could not be generated.
95+ type UploadPostTransformErrorEvent struct {
7696 // Timestamp of when the event occurred in ISO8601 format.
7797 CreatedAt time.Time `json:"created_at,required" format:"date-time"`
7898 Data UploadPostTransformErrorEventData `json:"data,required"`
7999 Request UploadPostTransformErrorEventRequest `json:"request,required"`
80100 Type constant.UploadPostTransformError `json:"type,required"`
81101 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
82102 JSON struct {
83- ID respjson.Field
84103 CreatedAt respjson.Field
85104 Data respjson.Field
86105 Request respjson.Field
87106 Type respjson.Field
88107 ExtraFields map [string ]respjson.Field
89108 raw string
90109 } `json:"-"`
110+ BaseWebhookEvent
91111}
92112
93113// Returns the unmodified JSON received from the API
@@ -203,24 +223,25 @@ func (r *UploadPostTransformErrorEventRequestTransformation) UnmarshalJSON(data
203223 return apijson .UnmarshalRoot (data , r )
204224}
205225
226+ // Triggered when a post-transformation completes successfully. The transformed
227+ // version of the file is now ready and can be accessed via the provided URL. Note
228+ // that each post-transformation generates a separate webhook event.
206229type UploadPostTransformSuccessEvent struct {
207- // Unique identifier for the event.
208- ID string `json:"id,required"`
209230 // Timestamp of when the event occurred in ISO8601 format.
210231 CreatedAt time.Time `json:"created_at,required" format:"date-time"`
211232 Data UploadPostTransformSuccessEventData `json:"data,required"`
212233 Request UploadPostTransformSuccessEventRequest `json:"request,required"`
213234 Type constant.UploadPostTransformSuccess `json:"type,required"`
214235 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
215236 JSON struct {
216- ID respjson.Field
217237 CreatedAt respjson.Field
218238 Data respjson.Field
219239 Request respjson.Field
220240 Type respjson.Field
221241 ExtraFields map [string ]respjson.Field
222242 raw string
223243 } `json:"-"`
244+ BaseWebhookEvent
224245}
225246
226247// Returns the unmodified JSON received from the API
@@ -298,24 +319,24 @@ func (r *UploadPostTransformSuccessEventRequestTransformation) UnmarshalJSON(dat
298319 return apijson .UnmarshalRoot (data , r )
299320}
300321
322+ // Triggered when a pre-transformation fails. The file upload may have been
323+ // accepted, but the requested transformation could not be applied.
301324type UploadPreTransformErrorEvent struct {
302- // Unique identifier for the event.
303- ID string `json:"id,required"`
304325 // Timestamp of when the event occurred in ISO8601 format.
305326 CreatedAt time.Time `json:"created_at,required" format:"date-time"`
306327 Data UploadPreTransformErrorEventData `json:"data,required"`
307328 Request UploadPreTransformErrorEventRequest `json:"request,required"`
308329 Type constant.UploadPreTransformError `json:"type,required"`
309330 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
310331 JSON struct {
311- ID respjson.Field
312332 CreatedAt respjson.Field
313333 Data respjson.Field
314334 Request respjson.Field
315335 Type respjson.Field
316336 ExtraFields map [string ]respjson.Field
317337 raw string
318338 } `json:"-"`
339+ BaseWebhookEvent
319340}
320341
321342// Returns the unmodified JSON received from the API
@@ -399,9 +420,10 @@ func (r *UploadPreTransformErrorEventRequest) UnmarshalJSON(data []byte) error {
399420 return apijson .UnmarshalRoot (data , r )
400421}
401422
423+ // Triggered when a pre-transformation completes successfully. The file has been
424+ // processed with the requested transformation and is now available in the Media
425+ // Library.
402426type UploadPreTransformSuccessEvent struct {
403- // Unique identifier for the event.
404- ID string `json:"id,required"`
405427 // Timestamp of when the event occurred in ISO8601 format.
406428 CreatedAt time.Time `json:"created_at,required" format:"date-time"`
407429 // Object containing details of a successful upload.
@@ -410,14 +432,14 @@ type UploadPreTransformSuccessEvent struct {
410432 Type constant.UploadPreTransformSuccess `json:"type,required"`
411433 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
412434 JSON struct {
413- ID respjson.Field
414435 CreatedAt respjson.Field
415436 Data respjson.Field
416437 Request respjson.Field
417438 Type respjson.Field
418439 ExtraFields map [string ]respjson.Field
419440 raw string
420441 } `json:"-"`
442+ BaseWebhookEvent
421443}
422444
423445// Returns the unmodified JSON received from the API
@@ -641,9 +663,10 @@ func (r *UploadPreTransformSuccessEventRequest) UnmarshalJSON(data []byte) error
641663 return apijson .UnmarshalRoot (data , r )
642664}
643665
666+ // Triggered when a new video transformation request is accepted for processing.
667+ // This event confirms that ImageKit has received and queued your transformation
668+ // request. Use this for debugging and tracking transformation lifecycle.
644669type VideoTransformationAcceptedEvent struct {
645- // Unique identifier for the event.
646- ID string `json:"id,required"`
647670 // Timestamp when the event was created in ISO8601 format.
648671 CreatedAt time.Time `json:"created_at,required" format:"date-time"`
649672 Data VideoTransformationAcceptedEventData `json:"data,required"`
@@ -652,14 +675,14 @@ type VideoTransformationAcceptedEvent struct {
652675 Type constant.VideoTransformationAccepted `json:"type,required"`
653676 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
654677 JSON struct {
655- ID respjson.Field
656678 CreatedAt respjson.Field
657679 Data respjson.Field
658680 Request respjson.Field
659681 Type respjson.Field
660682 ExtraFields map [string ]respjson.Field
661683 raw string
662684 } `json:"-"`
685+ BaseWebhookEvent
663686}
664687
665688// Returns the unmodified JSON received from the API
@@ -804,9 +827,11 @@ func (r *VideoTransformationAcceptedEventRequest) UnmarshalJSON(data []byte) err
804827 return apijson .UnmarshalRoot (data , r )
805828}
806829
830+ // Triggered when an error occurs during video encoding. Listen to this webhook to
831+ // log error reasons and debug issues. Check your origin and URL endpoint settings
832+ // if the reason is related to download failure. For other errors, contact ImageKit
833+ // support.
807834type VideoTransformationErrorEvent struct {
808- // Unique identifier for the event.
809- ID string `json:"id,required"`
810835 // Timestamp when the event was created in ISO8601 format.
811836 CreatedAt time.Time `json:"created_at,required" format:"date-time"`
812837 Data VideoTransformationErrorEventData `json:"data,required"`
@@ -815,14 +840,14 @@ type VideoTransformationErrorEvent struct {
815840 Type constant.VideoTransformationError `json:"type,required"`
816841 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
817842 JSON struct {
818- ID respjson.Field
819843 CreatedAt respjson.Field
820844 Data respjson.Field
821845 Request respjson.Field
822846 Type respjson.Field
823847 ExtraFields map [string ]respjson.Field
824848 raw string
825849 } `json:"-"`
850+ BaseWebhookEvent
826851}
827852
828853// Returns the unmodified JSON received from the API
@@ -990,9 +1015,11 @@ func (r *VideoTransformationErrorEventRequest) UnmarshalJSON(data []byte) error
9901015 return apijson .UnmarshalRoot (data , r )
9911016}
9921017
1018+ // Triggered when video encoding is finished and the transformed resource is ready
1019+ // to be served. This is the key event to listen for - update your database or CMS
1020+ // flags when you receive this so your application can start showing the
1021+ // transformed video to users.
9931022type VideoTransformationReadyEvent struct {
994- // Unique identifier for the event.
995- ID string `json:"id,required"`
9961023 // Timestamp when the event was created in ISO8601 format.
9971024 CreatedAt time.Time `json:"created_at,required" format:"date-time"`
9981025 Data VideoTransformationReadyEventData `json:"data,required"`
@@ -1003,7 +1030,6 @@ type VideoTransformationReadyEvent struct {
10031030 Timings VideoTransformationReadyEventTimings `json:"timings"`
10041031 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
10051032 JSON struct {
1006- ID respjson.Field
10071033 CreatedAt respjson.Field
10081034 Data respjson.Field
10091035 Request respjson.Field
@@ -1012,6 +1038,7 @@ type VideoTransformationReadyEvent struct {
10121038 ExtraFields map [string ]respjson.Field
10131039 raw string
10141040 } `json:"-"`
1041+ BaseWebhookEvent
10151042}
10161043
10171044// Returns the unmodified JSON received from the API
@@ -1235,7 +1262,12 @@ func (r *VideoTransformationReadyEventTimings) UnmarshalJSON(data []byte) error
12351262//
12361263// Use the methods beginning with 'As' to cast the union to one of its variants.
12371264type UnsafeUnwrapWebhookEventUnion struct {
1265+ // This field is from variant [VideoTransformationAcceptedEvent],
1266+ // [VideoTransformationReadyEvent], [VideoTransformationErrorEvent],
1267+ // [UploadPreTransformSuccessEvent], [UploadPreTransformErrorEvent],
1268+ // [UploadPostTransformSuccessEvent], [UploadPostTransformErrorEvent].
12381269 ID string `json:"id"`
1270+ Type string `json:"type"`
12391271 CreatedAt time.Time `json:"created_at"`
12401272 // This field is a union of [VideoTransformationAcceptedEventData],
12411273 // [VideoTransformationReadyEventData], [VideoTransformationErrorEventData],
@@ -1247,15 +1279,14 @@ type UnsafeUnwrapWebhookEventUnion struct {
12471279 // [UploadPreTransformSuccessEventRequest], [UploadPreTransformErrorEventRequest],
12481280 // [UploadPostTransformSuccessEventRequest], [UploadPostTransformErrorEventRequest]
12491281 Request UnsafeUnwrapWebhookEventUnionRequest `json:"request"`
1250- Type string `json:"type"`
12511282 // This field is from variant [VideoTransformationReadyEvent].
12521283 Timings VideoTransformationReadyEventTimings `json:"timings"`
12531284 JSON struct {
12541285 ID respjson.Field
1286+ Type respjson.Field
12551287 CreatedAt respjson.Field
12561288 Data respjson.Field
12571289 Request respjson.Field
1258- Type respjson.Field
12591290 Timings respjson.Field
12601291 raw string
12611292 } `json:"-"`
@@ -1566,7 +1597,12 @@ func (r *UnsafeUnwrapWebhookEventUnionRequestTransformation) UnmarshalJSON(data
15661597//
15671598// Use the methods beginning with 'As' to cast the union to one of its variants.
15681599type UnwrapWebhookEventUnion struct {
1600+ // This field is from variant [VideoTransformationAcceptedEvent],
1601+ // [VideoTransformationReadyEvent], [VideoTransformationErrorEvent],
1602+ // [UploadPreTransformSuccessEvent], [UploadPreTransformErrorEvent],
1603+ // [UploadPostTransformSuccessEvent], [UploadPostTransformErrorEvent].
15691604 ID string `json:"id"`
1605+ Type string `json:"type"`
15701606 CreatedAt time.Time `json:"created_at"`
15711607 // This field is a union of [VideoTransformationAcceptedEventData],
15721608 // [VideoTransformationReadyEventData], [VideoTransformationErrorEventData],
@@ -1578,15 +1614,14 @@ type UnwrapWebhookEventUnion struct {
15781614 // [UploadPreTransformSuccessEventRequest], [UploadPreTransformErrorEventRequest],
15791615 // [UploadPostTransformSuccessEventRequest], [UploadPostTransformErrorEventRequest]
15801616 Request UnwrapWebhookEventUnionRequest `json:"request"`
1581- Type string `json:"type"`
15821617 // This field is from variant [VideoTransformationReadyEvent].
15831618 Timings VideoTransformationReadyEventTimings `json:"timings"`
15841619 JSON struct {
15851620 ID respjson.Field
1621+ Type respjson.Field
15861622 CreatedAt respjson.Field
15871623 Data respjson.Field
15881624 Request respjson.Field
1589- Type respjson.Field
15901625 Timings respjson.Field
15911626 raw string
15921627 } `json:"-"`
0 commit comments