How to get reports from Commision Junction API - PHP

1.2k views Asked by At

Commision Junction is the name of an affiliate company. I am not familiar with SOAP, WSDL and with web services in general, but wanted to quickly test the data coming back from their affiliate api. Cannot make it work though. They provide a page for their API

I tried smtg like:

public function testCJApi() {

    $url = "http://" . $this->user . ":" . $this->password . "@datatransfer.cj.com/datatransfer/files/" . $this->account . "/outgoing/commission_report.csv";

    $xml = simplexml_load_file($url);

    if (isset($xml)) {
        return ($xml
            ? $this->formatJsonReturn($xml, array("txt"=>"CJ Results OK","code"=>""))
            : $this->formatJsonReturn("", array("txt"=>"CJ Results Empty","code"=>""))
        );
    }
}

but it didn't give me any results. I just need to quickly test the data coming back. The API link they provide is http://api.affiliatewindow.com/v4/MerchantService?wsdl.

1

There are 1 answers

0
Kanan Farzali On BEST ANSWER

I have figured it out myself:

public function testCJApi() {

    $uri = "https://commission-detail.api.cj.com/v3/commissions?date-type=posting&start-date=2013-02-15&end-date=2013-02-17"; // can be other api uri, this is one of them

    $context = stream_context_create(
        array(
            'http' => array(
                'method' => 'GET',
                'header' => 'Authorization: ' . 'YOUR API KEY GOES HERE'
            )
        )
    );
    $x = file_get_contents($uri, false, $context);
    $response = new SimpleXMLElement($x);
    return $response->asXML();
}