How to set debug to true
If you are having trouble getting your API to output data, the first step should be setting the ‘debug’ parameter to ‘true’. This will output a whole bunch of debugging information which can assist in finding the issue.
Using the Binance API as an example, we can see how to set debug to true on both the template tag and the shortcode.
echo wpgetapi_endpoint( 'binance', 'price_of_coin', array('debug'='true') );
[wpgetapi_endpoint api_id='binance' endpoint_id='price_of_coin' debug='true']
The template tag returns a Warning or says ‘Array’
If you are using the template tag and it outputs either of the following:
- Warning: Array to string conversion….
The likely cause is that you have tried to ‘echo’ the data when the Results Format is set to PHP array data, as shown below.
// wrong way to do it when set to PHP array data echo wpgetapi_endpoint( 'binance', 'price_of_coin', array('debug'='false') ); // correct way to do it when set to PHP array data // you can then use the $data variable however you like $data = wpgetapi_endpoint( 'binance', 'price_of_coin', array('debug'='false') ); // wpgetapi_pp is a helper function for 'pretty printing' the raw data wpgetapi_pp($data);
The other option is to simply set the Results Format to JSON (as string) and echo the data but this may not return the desired results as it would return a JSON formatted string.