Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!