I have been working with an API where I'm calling it from a wordpress custom plugin. One of the response parameters that i need is Uid which is a long integer
This is what i'm getting on postmon and what is correct and i need to get this value on php too

But when I try to print same response on php it rounds the number somehow??
Here is what i get on php side which is wrong!

Im using wp_remote_post method from wordpress. I was thinking if there is a way to manually assign that Uid to string not integer to avoid rounding.
my Code:
// Create new endpoint to get all products Data
add_action('rest_api_init', 'eos_store_rest_ajax_endpoint');
function eos_store_rest_ajax_endpoint()
{
register_rest_route(
'eos-store',
'products',
[
'methods' => 'GET',
'permission_callback' => '__return_true',
'callback' => 'eos_store_rest_ajax_callback'
]
);
}
function eos_store_rest_ajax_callback()
{
$url = "https://host:port/pospal-api2/openapi/v1/productOpenApi/queryProductPages";
$response = wp_remote_post(
$url,
array(
'method' => 'POST',
'headers' => array(
'data-signature' => 'DATA-Signature',
'time-stamp' => '1641903969',
'Content-Type' => 'application/json;charset=UTF-8'
),
'body' => json_encode(array( 'appId' => 'APPID' )),
'cookies' => array()
)
);
if (is_wp_error($response)) {
$error_message = $response->get_error_message();
return "Something went wrong: $error_message";
} else {
return $response
}
}
Actually the problem was not with php side, it was actually from Javascript while parsing the json response body. Since Javascript does not support big Integer normally and while parsing big integer from json it loses its precision.
Accepted answer on this StackOverFlow question helped me temporary fix my issue. https://stackoverflow.com/a/20408845/13858082