CJ Web Services Soap Error

Discussion in 'Commission Junction' started by markzero, Dec 13, 2009.

  1. #1
    When I try to connect to CJ's web service I get this error:
    "SoapFault Object ( [message: protected] => Could not connect to host [string: private] => [code: protected] => 0 [file: protected]...." then it's showing array list


    I am using this code (sample code from cj ws site):
    $developerKey = "mydevkey";
        $websiteId = "mywebsiteid";
    
        $ini = ini_set("soap.wsdl_cache_enabled","0");
    
        try {
    
            $client = new SoapClient("https://product.api.cj.com/wsdl/version2/productSearchServiceV2.wsdl", array('trace'=> true));
    
            //Enter the request parameters for productSearch below.
    		//For detailed usage of the parameter values, please refer to CJ Web Services online documentation
    
            $results = $client->search(array("developerKey" => $developerKey,
                                                "websiteId" => $websiteId,
                                            	"advertiserIds" => '',
                                                "keywords" => '',
                                                "serviceableArea" => '',
                                                "upc" => '',
                                                "linkType" => '',
                                                "manufacturerName" => '',
                                                "manufacturerSku" => '',
                                                "advertiserSku" => '',
                                                "lowPrice" => '',
                                                "highPrice" => '',
                                                "lowSalePrice" => '',
                                                "highSalePrice" => '',
                                          	 	"currency" => '',
                                             	"isbn" => '',
                                       			"sortBy" => 'name',
                                         		"sortOrder" => 'asc',
                                                "startAt" => 0,
                                                "maxResults" => 10));
    
            // The entire response structure will be printed in the next line
            print_r($results);
    
        } catch (Exception $e){
            echo "There was an error with your request or the service is unavailable.\n";
            print_r ($e);
        }
    PHP:
    I'm sure my dev key and website id are fine, and the error is in search function, because when comment it (and print_r), no error is shown

    I'm just starting with CJ WS
    Anybody been with this?
     
    markzero, Dec 13, 2009 IP
  2. QiSoftware

    QiSoftware Well-Known Member

    Messages:
    805
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    158
    #2
    I have two domains and found that the exact same code I ran on one would produce a similar error as you are getting on the other. I never figured out what was different on the two as I decided to go with a Java servlet rather than PHP. I would check the PHP version installed on your server.

    I also found running the php code locally worked.

    Q...
     
    QiSoftware, Dec 13, 2009 IP
  3. markzero

    markzero Peon

    Messages:
    133
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The version is 5.2.11 and the latest PHP version is 5.3.1
    I think that's not the problem as long as it's not v4.xx or older
     
    markzero, Dec 13, 2009 IP
  4. markzero

    markzero Peon

    Messages:
    133
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Alright, I have to write now my experiences after success connecting to CJ WS through REST API.
    After getting only 5 products from certain advertiser, it took several seconds to load the page. And I mean only writing returned xml to the test page.
    So, my recommendation is to use DATA FEEDS because it's A LOT faster having YOUR database (load time is less than 1sec for me). Yes, you take you lose like everything in life, here you need to be up-to-date with your feeds, following CJ update services, but I update only once in 3-5 updates (I'm doing it in two minutes exactly) :)
     
    markzero, Dec 14, 2009 IP
  5. phpPig

    phpPig Peon

    Messages:
    128
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I, too, was never able to connect using that soap client, so change this section of code

     $client = new SoapClient("https://product.api.cj.com/wsdl/version2/productSearchServiceV2.wsdl", array('trace'=> true));
    PHP:
    to

    $client = new SoapClient("https://product.api.cj.com/wsdl/literal_wrapped/productSearchService.wsdl", array('trace'=> true));
    PHP:

    That was what I had to change using SOAP. Also, instead of entering these into the database, I do a search for a specific keyword and define the amount of results that I would like to return. I then echo these results into php code and it actually loads extremely fast.

    I have actually written a script and am completing the code to make it a little more user friendly before releasing it but, you can preview how it works here. I only have about 200 pages now. The only information in my database is the product name. The rest is returned via CJ webservices.
     
    phpPig, Dec 14, 2009 IP
  6. markzero

    markzero Peon

    Messages:
    133
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks phpPig, that worked! But still not fast enough for me.. Maybe it's fast enough (3-5sec load time) but not if one day having 100s or even 1000s of visitors
     
    markzero, Dec 14, 2009 IP