0

so after some great help, I've managed to get the script doing everything I need it to, but I need help with the next bit.

Please see my script below. <?php

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://www.xxxxx.com/webAPI/api/stock',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => false,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_POSTFIELDS =>'<?xml version="1.0" encoding="utf-8" ?>
<traderapi>
    <token>T1a5c3t9</token>
    <variant>Clearbank ltd</variant>
    <pon>X</pon>
</traderapi>',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer T1a5c3t9',
'Content-Type: application/xml'
),
));

$response = curl_exec($curl);

curl_close($curl);

echo $response
?>

I get the Picture of Chrome results

The results that are displayed as this "210-AZBVTBC"

However in the code show this (as per the picture) "210-AZBVTBC4"

You can see I do a simple echo $response. How do I parse the information so I can show and manipulate how I show the individual tags. For example

echo ''.$response->Sku.'
';

3
  • a GET request with a POST body? i call bullshit, you're calling the API wrong. link to the api docs (while it's technically possible, it's pretty much always a bug, not intended usage.) Commented Jun 12, 2022 at 22:15
  • Sorry I'm not sure I follow :( Commented Jun 13, 2022 at 13:02
  • you're almost certainly not supposed to use CURLOPT_CUSTOMREQUEST => 'GET' - instead you're probably supposed to set CURLOPT_POST => 1 ... but to be 100% sure, we need the API documentation. where is the documentation for the API you're trying to use? Commented Jun 13, 2022 at 13:21

1 Answer 1

3

the result is a string not a file. try using simplexml_load_string instead of simplexml_load_file.

$Products = simplexml_load_string($response);
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for this... However I get a new error now - AH01071: Got error 'PHP message: PHP Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '&lt;' not found in
@MatthewPayton you can probably ignore those strict XML warnings, try $Products = @simplexml_load_string($response);
I've done that now. I've updated the main question now with the new issue :) Thank you so far!
When you echo this, it parses as tags. Use inspect element to view the source
Hi Milad! thank you, so the source is down to the echo $response at the bottom of the script

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.