https://retellai.com/?utm_source=discord&utm_medium=seo logo
How to assign call_id to a variable
# ❓・ai-evy-support
m
@AI Evy How to assign call_id to a variable?
a
Thanks for tagging me @manucmt_18551. I'll look through relevant sources and get back to you shortly.
### Answer To assign a
call_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:
Copy code
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:
Copy code
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:
Copy code
javascript
const callId = phoneCallResponse.call_id;
​ To learn more, see the sources I considered: [[1] Create Phone Call](https://docs.retellai.com/api-references/create-phone-call) [[2] Register Phone Call](https://docs.retellai.com/api-references/register-phone-call) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
m
@AI Evy I mean if I want to use the call_id in a function during the conversation
a
Thanks for the follow-up, @manucmt_18551. I'll get back to you soon.
​ To learn more, see the sources I considered: [[1] Discord message from @realee_23147 on 2025-09-04](https://discord.com/channels/1186424376300679209/1186462578310910112/1413193465717719041) [[2] Get Call ID from Custom Function](https://discord.com/channels/1186424376300679209/1227560662541271081) ​
### Answer When using custom functions during a conversation, the
call_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:
Copy code
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:
Copy code
python
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) ]() .
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.