You can now group multiple Daylife API requests into one request
using the Batch API. Batch API calls help improve the
performance of your application as your application makes only HTTP
request to the Daylife API.
can also download a PHP script to call the Batch API.
- What is the Batch
The Batch API accepts multiple Daylife API requests, executes each of
them in parallel and returns a combined response for all Daylife API
requests. You can make up to 12 individual Daylife API
requests in one batch request.
- When should you use the Batch API?
If you are building an application or website that makes multiple Daylife API requests to render one module or web-page, you can group the Daylife API requests together into one batch request.
For e.g., if you are building a topic page which calls topic_getRelatedStories, topic_getRelatedTopics and topic_getRelatedQuotes, you can make one batch request with all the 3 Daylife API requests together.
- What methods are available for the Batch API?
The Batch API currently exposes one method - parallel. All Daylife API requests provided as an input to this method, are executed in parallel by the batch API and the response to each Daylife API request is combined and returned as one response.
- How do you make a request to the Batch API?
The methodology to make Batch API calls is very similar to that of making Daylife API calls:
There is only input parameter for the method parallel: request. The request parameter accepts the part of a valid Daylife API request that appears beyond the format specifier in the Daylife API request.
- . All requests to the Batch API are HTTP GET or POST requests.
- . All input parameters are accepted as name-value pairs in the query string of the HTTP GET request or the body of the HTTP POST request.
- . Batch APIs can return data as XML, JSON or PHP serialized formats.
- Values for all input parmeters must be url-encoded.
For example., if your individual Daylife API request is
then the value of the requestparam to the parallel method would be the urlencoded value of
You can provide multiple name-value pairs for the request parameter as an input, one for each request . A batch request with 2 individual request looks like this (THIS IS NOT A REAL API CALL. Just an example to show how your code should formulate the Batch API calls):
- How do you match an individual Daylife API request in the batch request to an individual Daylife API response in the batch response?
Notice the request_id param in the values of the request parameter above. Every single Daylife API request provided as input to the batch.parallel method needs to have a unique alphanumeric request_id. When the batch API combines the response of each individual Daylife API request, it adds the request_id from the indvidual request to its corresponding response. Your Batch API client can then match up every single request sent to batch.parallel to the individual responses in the combined response using the request_id.
Download Sample Batch Response Here.
- Is there a way to call the batch API in a way so that you do not have to repeatedly provide common parameters that share the same value in each individual Daylife API request?
Yes, any parameter to the batch.parallel API call that starts with "batch_" is appended to each individual request without the prefix "batch_". For e.,g,, your provide batch_accesskey=XYZ as an input to the batch.parallel call, then accesskey=XYZ gets added as a parameter to each individual request.
- Are there any timeouts by the Batch API?
Yes. The Batch API attempts to make individual requests in parallel, waits a maximum upto 25 seconds for each request to come back and then returns the combined responses of the requests that got completed.
- Is there any authentication for the Batch API?
No. The Batch API has no authentication of its own. Each individual Daylife API request provided as an input must contain a valid accesskey and signature. However, you can use the feature mentioned in topic 6 above to provide batch_accesskey and batch_signature as an input to the batch.parallel call rather than providing accesskey and signature in each individual request.
- What error codes are returned by the Batch API?
3001: Success. All individual requests were completed without a timeout. However, this does not guarantee that each individual request was successful.
-3001: One or more individual requests did not complete within the 25 second timeframe.
-3002: Duplicate request_ids provided in the individual requests
-3003: One or more of the individual Daylife API request were not formatted properly. See above how to make a valid request for the Batch API.
-3004: More than 12 requests provided as input to the batch API.
- How do I specify a timeout of my own for the individual requests of a batch call?
The timeout parameter lets you specify the maximum number of seconds that you want to allow your individual requests in the batch to complete in. If some of the requests are not completed, still the Batch API returns with partial results.