Skip to content

Update API Endpoint

Here is an example of code in JavaScript to send an update to the plugin

interface AppInfos {
version_name: string
version_build: string
version_os: string
custom_id?: string
is_prod?: boolean
is_emulator?: boolean
plugin_version: string
platform: string
app_id: string
device_id: string
}
export const handler: Handler = async (event) => {
const body = JSON.parse(event.body || '{}') as AppInfos
const {
platform,
app_id,
version_os,
device_id,
version_name,
version_build,
plugin_version,
} = body
console.log('update asked', platform,
app_id,
version_os,
device_id,
version_name,
version_build,
plugin_version)
if (version_name === '1.0.0') {
return {
version: '1.0.1',
url: 'https://apiurl.com/mybuild_101.zip',
checksum: 'sha256_checksum_of_bundle',
}
}
else if (version_name === '1.0.1') {
return {
version: '1.0.2',
url: 'https://apiurl.com/mybuild_102.zip',
checksum: 'sha256_checksum_of_bundle',
}
}
else {
return {
message: 'Error version not found'
version: '',
url: '',
}
}
}

For non-encrypted bundles, your endpoint should return:

{
"version": "1.0.2",
"url": "https://apiurl.com/mybuild_102.zip",
"checksum": "sha256_checksum_of_bundle"
}

For encrypted bundles, you also need to include the session key:

{
"version": "1.0.2",
"url": "https://apiurl.com/mybuild_102.zip",
"checksum": "encrypted_checksum_from_encrypt_command",
"session_key": "ivSessionKey_from_encrypt_command"
}

And if no update or error, add the message key and optionally an error:

{
"message": "Version not found",
"error": "The backend crashed",
"version": "1.0.2",
}
  • checksum: SHA256 hash of your bundle zip file for integrity verification
  • session_key: Required only for encrypted bundles - this is the ivSessionKey returned by the encrypt command
  • version: Version identifier in semver format
  • url: HTTPS URL where the bundle can be downloaded

To learn how to create compatible bundles and generate checksums, see the Auto Update documentation.

For encrypted bundles, see the Encrypted Bundles documentation which explains the complete encryption workflow.

If you are using Update API Endpoint to plan CI/CD automation, connect it with Using @capgo/capacitor-updater for the native capability in Using @capgo/capacitor-updater, Capgo CI/CD for the product workflow in Capgo CI/CD, Capgo Native Builds for the product workflow in Capgo Native Builds, Capgo Integrations for the product workflow in Capgo Integrations, and CI/CD Integration for the implementation detail in CI/CD Integration.