Asterisk cmd LookupCIDName


Look up CallerID Name from local database



Looks up the Caller*ID number on the active channel in the Asterisk database (family 'cidname') and sets the Caller*ID name. Does nothing if no Caller*ID was received on the channel. This is useful if you do not subscribe to Caller*ID name delivery, or if you want to change the names on some incoming calls.
LookupCIDName is deprecated from Asterisk 1.4. Please use Set(CALLERID(name)=${DB(cidname/${CALLERID(num)})}) instead. [NOTE: In 1.6 (maybe 1.4?) this will blank out your Caller ID Name if there is not a DB entry for the number. I use Set(CALLERID(name)=${IF(${DB_EXISTS(cidname/${CALLERID(num)})}?${DB(cidname/${CALLERID(num)})}:${CALLERID(name)})}) instead.]


exten => s,X,LookupCIDName

CLI command for storing CID names:

database put cidname 12345 "John Smith"

CLI command for listing CID names:

database show cidname

Using Trixbox / FreePBX with Third Party Caller Name Lookup Scripts

This is the original caller-id macro used by FreePBX (v 2.1.2)

exten => s,1,GotoIf($["${CHANNEL:0:5}" = "Local"]?report)
exten => s,n,GotoIf($["${REALCALLERIDNUM:1:2}" != ""]?start)
exten => s,n,Set(REALCALLERIDNUM=${CALLERID(number)})
exten => s,n,Set(AMPUSER=${DB(DEVICE/${REALCALLERIDNUM}/user)})
exten => s,n,Set(AMPUSERCIDNAME=${DB(AMPUSER/${AMPUSER}/cidname)})
exten => s,n,GotoIf($["x${AMPUSERCIDNAME:1:2}" = "x"]?report)
exten => s,n,Set(CALLERID(all)=${AMPUSERCIDNAME} <${AMPUSER}>)
exten => s,n(report),NoOp(Using CallerID ${CALLERID(all)})

exten => s,n,GotoIf($["${CALLERID(name)}" != ""]?done)
exten => s,n,AGI(callerid_shell.agi|${CALLERIDNUM})
exten => s,n,NoOp(AGI Returned ${lookupname})
exten => s,n,Set(CALLERID(name)=${lookupname})
exten => s,n(done),NoOp(Callerid Lookup Complete)

The second paragraph of code will kick in if no Caller Name has been set,
perform the lookup and return it. I've used the following script (also linked below) to do this. Just place the
second block of code below the existing macro-user-callerid section.

As an alternative, you can use the smartCID script (available at This script can do callerid lookup from a local MYSQL database, but can also go out to websites like and do a reverse phone lookup to get the caller's name and address. This script also offers a call screening field - usefull!

See also

Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ

Created by: oej, Last modification: Thu 04 of Nov, 2010 (03:22 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+