Number Lookup: Sync vs. Async

Learn about the difference between synchronous and asynchronous Number Lookup.

Number Lookup provides information about phone numbers in your database. There are two ways of getting that information:

  • Sync
  • Async

If an API call is synchronous, it means that Number Lookup will be done before your application receives a response from an API call. In turn, this means the application code should properly handle waiting for the HTTP response so users don’t perceive waiting for NC lookup response as latency or performance lag inside your app.

Making a synchronous API call can be beneficial if there is a code in your app that will only execute properly once the API response is received.

POST /number/1/query HTTP/1.1
Host: api.infobip.com
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Content-Type: application/json

{  
   "to":[  
      "41793026727",
      "41793026728",
      "41793026729"
   ]
}	
  

The Number Lookup result will be received directly in the response:

HTTP/1.1 200 OK
Content-Type: application/json

{  
   "results":[  
      {  
         "to":"41793026727",
         "mccMnc":"22801",
         "originalNetwork":{  
            "networkPrefix":"79",
            "countryPrefix":"41"
         },
         "ported":false,
         "roaming":false,
         "status":{  
            "groupId":2,
            "groupName":"UNDELIVERABLE",
            "id":9,
            "name":"UNDELIVERABLE_NOT_DELIVERED",
            "description":"Message sent not delivered"
         },
         "error":{  
            "groupId":1,
            "groupName":"HANDSET_ERRORS",
            "id":27,
            "name":"EC_ABSENT_SUBSCRIBER",
            "description":"Absent Subscriber",
            "permanent":false
         }
      }
   ]
}	
  

Asynchronous calls do not wait for Number Lookup to be done before the API call response is returned. When Number Lookup is done, a “callback” function is executed and Number Lookup information is sent to the notifyUrl you specified in the request.

POST /number/1/notify HTTP/1.1
Host: api.infobip.com
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Content-Type: application/json

{  
   "to":[  
      "41793026727",
      "41793026728",
      "41793026729"
   ],
   "notifyUrl":"http://example.com/notifyUrl",
   "notifyContentType":"application/json"
}