manucmt_18551
09/07/2025, 12:29 AMAI Evy
09/07/2025, 12:30 AMAI Evy
09/07/2025, 12:30 AMcall_id to a variable in JavaScript, you can extract it from the response when creating or registering a phone call [(1) ]() [(2) ]() .
For creating a phone call:
javascript
import Retell from 'retell-sdk';
const client = new Retell({
apiKey: 'YOUR_RETELL_API_KEY',
}) ;
const phoneCallResponse = await client.call.createPhoneCall({
from_number: '+14157774444',
to_number: '+12137774445',
}) ;
console.log(phoneCallResponse.agent_id) ;
[(1) ]()
For registering a phone call:
javascript
import Retell from 'retell-sdk';
const client = new Retell({
apiKey: 'YOUR_RETELL_API_KEY',
}) ;
const phoneCallResponse = await client.call.registerPhoneCall({
agent_id: 'oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD',
}) ;
console.log(phoneCallResponse.agent_id) ;
[(2) ]()
To access the call_id specifically, you would use phoneCallResponse.call_id instead of phoneCallResponse.agent_id [(1) ]() [(2) ]() . The response object contains a call_id field that you can assign to a variable like:
javascript
const callId = phoneCallResponse.call_id;AI Evy
09/07/2025, 12:30 AMAI Evy
09/07/2025, 12:30 AMmanucmt_18551
09/07/2025, 12:32 AMAI Evy
09/07/2025, 12:32 AMAI Evy
09/07/2025, 12:32 AMAI Evy
09/07/2025, 12:32 AMcall_id is automatically included in the request body that Retell sends to your custom function endpoint [(1) ]() . You can access it directly from req.body.call [(1) ]() [(2) ]() .
Here's how to access the call ID in your custom function:
JavaScript example:
javascript
import { Retell } from "retell-sdk";
this.app.post("/check-weather", async (req: Request, res: Response) => {
if (
!Retell.verify(
JSON.stringify(req.body) ,
process.env.RETELL_API_KEY,
req.headers["x-retell-signature"] as string,
)
) {
console.error("Invalid signature") ;
return;
}
const content = req.body;
if (content.args.city === "New York") {
return res.json("25f and sunny") ;
} else {
return res.json("20f and cloudy") ;
}
}) ;
[(1) ]()
Python example:AI Evy
09/07/2025, 12:32 AMpython
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from retell import Retell
retell = Retell(api_key=os.environ["RETELL_API_KEY"])
@app.post("/check-weather")
async def check-weather(request: Request) :
try:
post_data = await request.json()
valid_signature = retell.verify(
json.dumps(post_data, separators=(",", ":") , ensure_ascii=False) ,
api_key=str(os.environ["RETELL_API_KEY"]) ,
signature=str(request.headers.get("X-Retell-Signature") ) ,
)
if not valid_signature:
print(
"Received Unauthorized",
post_data["event"],
post_data["data"]["call_id"],
)
return JSONResponse(status_code=401, content={"message": "Unauthorized"})
args = post_data["args"]
if args["city"] == "New York":
return JSONResponse(status_code=200, content={"result": "25f and sunny"})
else:
return JSONResponse(status_code=200, content={"result": "20f and cloudy"})
except Exception as err:
print(f"Error in webhook: {err}")
return JSONResponse(
status_code=500, content={"message": "Internal Server Error"}
)
The request body structure includes the call object containing the same information you would get from the Get Call API . You can access the call ID from req.body.call in your endpoint [(2) ]() .AI Evy
09/07/2025, 12:32 AM