- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello all. I am new to the VDP APIs and I am running into issues trying to read the output of the response as a json using php. I followed the tutorial here. I am using the Offers Data API.
My goal is to be able to generate a list of deals to be displayed in the frontend. I am trying to do this by reading the json output and parsing the info for the deals.
This is what the original tutorial had and it works fine:
$response = curl_exec($curl); //This output contains the json output as well
$response_info = curl_getinfo($curl);
To get the information, I am running: $response_data = file_get_contents($response); which does not appear to work. Since the output it not just the json, but with other info, I am not able to run: $arr = json_decode($response,true); to pasrse the json.
Please let me know what I can do to fix this, or if there is a better way to accomplish the goal. Thank you!
Solved! Go to Solution
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Issues with parsing response json output with php
Hi, @MiPlayer123. Thank you for reaching out! An agent is looking for a solution for you and will get back to you shortly. In the meantime, if any community members have a suggestion, feel free to share it here. - Jenn
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Issues with parsing response json output with php
Hi @MiPlayer123,
Please try to use an API client tool first so you can test and trouble errors/issues easily. You can use VDC Playground, Postman, SoapUI or any other tool that you are familiar with. Please see user guides below for respective tools.
- VDC Playground: https://community.developer.visa.com/t5/Tutorials/How-to-test-and-troubleshoot-APIs-with-the-Visa-De...
- Postman: https://developer.visa.com/pages/working-with-visa-apis/two-way-ssl#testing_twoway_ssl_connectivity_...
- SOAP UI: https://developer.visa.com/pages/working-with-visa-apis/two-way-ssl#testing_twoway_ssl_connectivity_...
Hope this helps, please let me know if you have any questions.
Best,
Stacey
Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you all for your input. I use VDP playground to test the APIs. The issue I was having was parsing the data into a json. I have since resolved the issue as follows:
$json = json_decode($response, true);
var_dump($json['Offers']); //This is only to display offers array
Here is the loop that I used to print the data:
$offers = $json["Offers"];
foreach ($offers as $x => &$offer) {
print($offer["offerId"]."<br>");
print($offer["offerTitle"]."<br>"."<br>");
}
Hope this helps others who run into the same issues.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Issues with parsing response json output with php
@MiPlayer123, Thank you for sharing with the developer community how you resolved the issue!
Best,
Stacey
Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.