Jump to content

Prestashop Webservice retrieving a customer data error


pablodalma93

Recommended Posts

Hi newbie here,

 

Im trying the tutorial for using the Prestashop Webservice, when running the code for creating a HTML table containing all the client IDs of chapter 3 it works  , but when trying to get a specific customer data with the following code it gives a "Node no longer exists in" PHP warning , but I know a customer with that id exists from the former chapter

 

$opt['resource'] = 'customers';

$opt['id'] = $_GET['id']; 

$xml = $webService->get($opt);

 

$resources = $xml->customers->children();

 

foreach ($resources as $key => $resource)

    echo 'Name of field: ' . $key . ' - Value: ' . $resource . '<br />';

 

also tried replacing  $_GET['id'] with

$opt['id'] = 1; 

or 

$opt['id'] = '1'; 

Link to comment
Share on other sites

  • 9 months later...

Hi I just expecting the same issue and I founded a solution:

 

Juste replace

 

$resources = $xml->customers->children();

 

By

 

$resources = $xml->customer->children();

 

(Remove "s" from the end of customerS)

 

Here is my working code:

<?php
 
  require_once('./PSWebServiceLibrary.php');
  
  $cusId = '2';
  
  try {
      // creating web service access
      $webService = new PrestaShopWebservice('http://example.com/', 'ZR92FNY5UFRERNI3O9Z5QDHWKTP3YIIT', false);

      // The key-value array
    
      $opt = array('resource' => 'customers',
                   'id' => $cusId);
       
      // call to retrieve all customers
      $xml = $webService->get($opt);
      
      $resources = $xml->customer->children();
      
      foreach ($resources as $key => $resource)
        {
        echo 'Name of field: ' . $key . ' - Value: ' . $resource . chr(10);
        } 
      }
  catch (PrestaShopWebserviceException $ex) 
      {
      // Shows a message related to the error
      echo 'Other error: <br />' . $ex->getMessage();
      }
      
?>
Edited by salbrech (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...