const { createHash } = require("node:crypto")
function hash(key) {
return {
value: createHash("sha256").update(key).digest("base64"),
variant: "sha256_base64",
}
}
const request = {
migrationId: "<UNKEY_MIGRATION_ID>", // the id of the migration you created
apiId: "<UNKEY_API_ID>", // the id of the API you created
keys: [
{
hash: hash("my-secret-key"),
//... other settings
},
{
hash: hash("my-other-secret-key"),
//... other settings
},
]
}
fetch("https://api.unkey.com/v2/keys.migrateKeys", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer <UNKEY_ROOT_KEY>",
},
body: JSON.stringify(request)
})
.then(res => res.json())
.then(res => {
console.log("Migrated keys:", res.data.migrated)
console.log("Failed hashes:", res.data.failed)
})