Webhook payload structure
When you include a webhookUrl
parameter in your update or upload API calls, the final status of extensions after they have completed execution will be delivered to this endpoint as a POST request. The payload will contain the following fields:
Request Field | Description |
---|---|
service | Name of the extension. |
status | Final status of the extension execution. Can be either SUCCESS or FAILURE . |
fileObject (for success responses only) | The result of a Get File Details API call that you would receive after completion of this extension. |
fileId (for failure responses only) | Unique id associated with the file on which the extension was attempted. |
error (for failure responses only) | Error object indicating the cause of failure. |
ImageKit expects a response with a status code 200 from your webhook endpoint. Any other status code will be interpreted as a failure and may trigger a retry. Not receiving a response in 30 seconds will also be interpreted as a failure. ImageKit will attempt webhook retries for a maximum of 24 hours in spaced intervals.
See example payloads:
// A success webhook request for a background removal extension { "service": "remove-bg", "status": "SUCCESS", "fileObject": { "fileId": "5effaa5662679b5af2c58829", /* ... rest of the fields in a file object */ }, }
// A SUCCESS webhook request for a google auto-tagging extension { "service": "google-auto-tagging", "status": "SUCCESS", "fileObject": { "fileId": "5effaa5662679b5af2c58829", "AITags": [ { "name": "Shirt", "confidence": 90.12, "source": "google-auto-tagging" }, /* ... more google-auto-tagging tags ... */ ], /* ... rest of the fields in a file object */ }, }
// A failure webhook request for a google auto tagging extension { "service": "google-auto-tagging", "status": "FAILURE", "fileId": "5effaa5662679b5af2c58829", "error": { /* error fields */ } }
Examples
Tags and custom coordinate update
# The unique fileId of the uploaded file. fileId is returned in response of list files API and upload API. curl -X PATCH "https://api.imagekit.io/v1/files/:fileId/details" \ -H 'Content-Type: application/json' \ -u your_private_key: -d' { "tags": [ "tag1", "tag2" ], "customCoordinates": "10,10,100,100" } '
var ImageKit = require("imagekit"); var imagekit = new ImageKit({ publicKey : "your_public_api_key", privateKey : "your_private_api_key", urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/" }); imagekit.updateFileDetails("file_id", { tags : ['image_tag'], customCoordinates : "10,10,100,100" }, function(error, result) { if(error) console.log(error); else console.log(result); });
from imagekitio import ImageKit imagekit = ImageKit( public_key='your_public_api_key', private_key='your_private_api_key', url_endpoint = 'https://ik.imagekit.io/your_imagekit_id/' ) updated_detail = imagekit.update_file_details( file_id="file_id", options=UpdateFileRequestOptions(remove_ai_tags=['remove-ai-tag-1', 'remove-ai-tag-2'], webhook_url="url", tags=["tag1", "tag2"], custom_coordinates="10,10,100,100", custom_metadata={"test": 11}) ) print("Updated detail-", updated_detail, end="\n\n") # Raw Response print(updated_detail.response_metadata.raw) # print that file's id print(updated_detail.file_id)
use ImageKit\ImageKit; $public_key = "your_public_api_key"; $your_private_key = "your_private_api_key"; $url_end_point = "https://ik.imagekit.io/your_imagekit_id"; $imageKit = new ImageKit( $public_key, $your_private_key, $url_end_point ); // Update File Details $updateData = [ "tags" => ["tag1", "tag2"], "customCoordinates" => "10,10,100,100" ]; $updateFileDetails = $imageKit->updateFileDetails( $fileId, $updateData ); echo("Updated File Details : " . json_encode($updateFileDetails));
FileUpdateRequest fileUpdateRequest =new FileUpdateRequest("file_id"); List<String> tags=new ArrayList<>(); tags.add("tag1"); tags.add("tag2"); fileUpdateRequest.setTags(tags); fileUpdateRequest.setCustomCoordinates("10,10,100,100"); Result result=ImageKit.getInstance().updateFileDetail(fileUpdateRequest);
imagekitio = ImageKit::ImageKitClient.new("your_private_key", "your_public_key", "your_url_endpoint") updated_detail = imagekitio.update_file_details( "file_id", { "tags": ["tag1", "tag2"], "custom_coordinates": "10,10,100,100" } )
resp, err := ik.Media.UpdateFile(ctx, "file_id", media.UpdateFileParam{ Tags: []string{"tag1", "tag2"}, CustomCoordinates: "10,10,100,100", })
var imagekit = new ImageKit({ publicKey : "your_public_api_key", privateKey : "your_private_api_key", urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/" }); FileUpdateRequest updateob = new FileUpdateRequest { fileId = "fileId", }; List<string> updatetags = new List<string> { "tag1", "tag2" }; updateob.tags = updatetags; string updatecustomCoordinates = "10,10,100,100"; updateob.customCoordinates = updatecustomCoordinates; Result updateresp = imagekit.UpdateFileDetail(updateob);
Changing the publication status of a file
# The unique fileId of the uploaded file. fileId is returned in response of list files API and upload API. curl -X PATCH "https://api.imagekit.io/v1/files/:fileId/details" \ -H 'Content-Type: application/json' \ -u your_private_key: -d' { "publish": { "isPublished": true, "includeFileVersions": false } } '
Applying extensions
Request
# The unique fileId of the uploaded file. fileId is returned in response of list files API and upload API. # Example of using the google-auto-tagging extension curl -X PATCH "https://api.imagekit.io/v1/files/file_id/details" \ -H 'Content-Type: application/json' \ -u your_private_key: -d' { "extensions": [ { "name": "google-auto-tagging", "maxTags": 5, "minConfidence": 95 } ] } '
var ImageKit = require("imagekit"); var imagekit = new ImageKit({ publicKey : "your_public_api_key", privateKey : "your_private_api_key", urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/" }); imagekit.updateFileDetails("file_id", { extensions: [ { name: "google-auto-tagging", maxTags: 5, minConfidence: 95 } ] }, function(error, result) { if(error) console.log(error); else console.log(result); });
from imagekitio import ImageKit imagekit = ImageKit( public_key='your_public_api_key', private_key='your_private_api_key', url_endpoint = 'https://ik.imagekit.io/your_imagekit_id/' ) updated_detail = imagekit.update_file_details( file_id="file_id", options=UpdateFileRequestOptions(extensions = [ { "name": "google-auto-tagging", "maxTags": 5, "minConfidence": 95 } ]) ) print("Updated detail-", updated_detail, end="\n\n") # Raw Response print(updated_detail.response_metadata.raw) # print that file's id print(updated_detail.file_id)
use ImageKit\ImageKit; $public_key = "your_public_api_key"; $your_private_key = "your_private_api_key"; $url_end_point = "https://ik.imagekit.io/your_imagekit_id"; $imageKit = new ImageKit( $public_key, $your_private_key, $url_end_point ); // Update File Details $updateData = [ "extensions" => [ [ "name" => "google-auto-tagging", "maxTags" => 5, "minConfidence" => 95 ] ] ]; $updateFileDetails = $imageKit->updateFileDetails( $fileId, $updateData ); echo("Updated File Details : " . json_encode($updateFileDetails));
JsonObject extension = new JsonObject(); extension.addProperty("name", "google-auto-tagging"); extension.addProperty("maxTags", 5); extension.addProperty("minConfidence", 95); JsonArray extensionArray = new JsonArray(); extensionArray.add(extension); fileUpdateRequest.setExtensions(extensionArray); Result result = ImageKit.getInstance().updateFileDetail(fileUpdateRequest);
imagekitio = ImageKitIo::Client.new("your_private_key", "your_public_key", "your_url_endpoint") updated_detail = imagekitio.update_file_details( file_id: "file_id", #required extension: [ { name: 'google-auto-tagging', maxTags: 5, minConfidence: 95 } ] )
import ( "github.com/imagekit-developer/imagekit-go/extension" "github.com/imagekit-developer/imagekit-go/api/uploader" ) const base64Image = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" resp, err := ik.Uploader.Upload(ctx, base64Image, uploader.UploadParam{ Extensions: []extension.IExtension{ extension.NewAutoTag(extension.GoogleAutoTag, 95, 5), extension.NewRemoveBg(extension.RemoveBgOption{}), }, })
var imagekit = new ImageKit({ publicKey : "your_public_api_key", privateKey : "your_private_api_key", urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/" }); FileUpdateRequest updateob = new FileUpdateRequest { fileId = "fileId", }; List<Extension> extModel = new List<Extension>(); BackGroundImage bck = new BackGroundImage { name = "remove-bg", options = new options() { add_shadow = true, semitransparency = false, bg_color = "green" } }; extModel.Add(bck); updateob.extensions = extModel; Result updateresp = imagekit.UpdateFileDetail(updateob);
Response
/* "success" status for google-auto-tagging extension having AITags field synchronously populated. */ { "fileId" : "598821f949c0a938d57563bd", "type": "file", "name": "file1.jpg", "filePath": "/images/products/file1.jpg", "tags": null, "AITags" [ { "name": "saree", "confidence": 96.2837328, "source": "google-auto-tagging" }, { "name": "traditional clothing", "confidence": 98.3732228, "source": "google-auto-tagging" }, { "name": "women's wear", "confidence": 97.7233283, "source": "google-auto-tagging" }, { "name": "ethnic", "confidence": 99.9928828, "source": "google-auto-tagging" } ] "isPrivateFile" : false, "customCoordinates" : null, "url": "https://ik.imagekit.io/your_imagekit_id/images/products/file1.jpg?updatedAt=1566630881313", "thumbnail": "https://ik.imagekit.io/your_imagekit_id/images/products/file1.jpg?updatedAt=1566630881313&tr=n-ik_ml_thumbnail", "fileType": "image", "mime": "image/jpeg", "width": 100, "height": 100, "size": 100, "hasAlpha": false, "createdAt": "2019-08-24T06:14:41.313Z", "updatedAt": "2019-08-24T06:14:41.313Z", "extensionStatus": { "google-auto-tagging": "success" } }