Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sgupta1979's avatar

Unable to retrieve data with Laravel API from servicenow

I build Laravel API to retrieve data from servicenow and below is code

public function __construct() { $this->client = new Client([ 'base_uri' => 'https://capeumsp.service-now.com/', 'auth' => ['asasa', 'fgdfgd'], // Basic Auth ]); }

public function getData() { $response = $this->client->request('GET', 'now/v2/table/incident', [ 'query' => [ 'sysparm_display_value' => true, 'sysparm_limit' => 10, // Example query parameter ], 'headers' => [ 'Accept' => 'application/json', ], ]); $data = json_decode($response->getBody()->getContents(), true); }

I am getting response as below

Illuminate\Http\JsonResponse {#309 ▼ // app\Http\Controllers\RhoneController.php:37 +headers: Symfony\Component\HttpFoundation
ResponseHeaderBag {#305 ▼ #headers: array:3 [▶] #cacheControl: [] #computedCacheControl: array:2 [▶] #cookies: [] #headerNames: array:3 [▶] } #content: "{}" #version: "1.0" #statusCode: 200 #statusText: "OK" #charset: null -sentHeaders: ? array #data: "{}" #callback: null #encodingOptions: 0 +original: ArrayObject {#317 ▶} +exception: null }

Data is empty. Please guide

0 likes
1 reply
LaryAI's avatar
Level 58

To troubleshoot the issue of receiving an empty response from the ServiceNow API in your Laravel application, you can follow these steps:

  1. Check API Credentials: Ensure that the username and password used for basic authentication are correct. Incorrect credentials will result in an empty or unauthorized response.

  2. Verify API Endpoint: Double-check the API endpoint URL to ensure it is correct. The endpoint should match the ServiceNow instance and table you are trying to access.

  3. Inspect Response Status Code: Before decoding the response, check the status code to ensure the request was successful. A status code of 200 indicates success, but other codes might provide more insight if something went wrong.

  4. Log the Response: Add logging to capture the full response body and headers. This can help identify if there are any issues with the response content.

  5. Check Query Parameters: Ensure that the query parameters are correct and supported by the ServiceNow API. Incorrect parameters might result in an empty response.

  6. Debugging: Add error handling to catch any exceptions that might be thrown during the request.

Here's an updated version of your code with some of these suggestions:

Additional Tips:

  • ServiceNow API Documentation: Review the ServiceNow API documentation to ensure you are using the correct endpoint and parameters.
  • Network Issues: Ensure there are no network issues or firewalls blocking the request to the ServiceNow instance.
  • ServiceNow Logs: Check the logs on the ServiceNow side to see if the request is reaching the server and if there are any errors being logged.

By following these steps, you should be able to identify the cause of the empty response and resolve the issue.

Please or to participate in this conversation.