Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
How to declare response parameters of a server to string?

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
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda