0

I'm trying to login to channel advisor but it output an error of: HTTP/1.1 302 Moved Temporarily.

But last week it runs perfectly that I login and retrieve my data and now I run again it has an error.

Here is my code:

 $pages = array('home' => 
 'https://login.channeladvisor.com/?gotourl=https%3a%2f%2fcomplete.channeladvisor.com%2f', 
           'login' => 
 'https://login.channeladvisor.com/?gotourl=https%3a%2f%2fcomplete.channeladvisor.com%2f', 
           'data' => 
  'https://merchant.channeladvisor.com/AM/MyInventory/View_Inventory.aspx?apid=32001263'); 

  $ch = curl_init(); 
  //Set options for curl session 
  $options = array(CURLOPT_USERAGENT => 'Mozilla/12.0 (compatible; MSIE 6.0; Windows NT 5.1)', 
         CURLOPT_SSL_VERIFYPEER => FALSE, 
         CURLOPT_SSL_VERIFYHOST => 2, 
         CURLOPT_HEADER => TRUE, 
         CURLOPT_RETURNTRANSFER => TRUE, 
         CURLOPT_COOKIEFILE => 'cookies.txt', 
         CURLOPT_COOKIEJAR => 'cookies.txt'); 

//Hit home page for session cookie 
$options[CURLOPT_URL] = $pages['home']; 
curl_setopt_array($ch, $options); 
//curl_exec($ch); 

//Login 
$options[CURLOPT_URL] = $pages['login']; 
$options[CURLOPT_POST] = TRUE; 
$options[CURLOPT_POSTFIELDS] = 'username=xxxxx@gmail.com&password=xxxxxxx'; 
$options[CURLOPT_FOLLOWLOCATION] = false;
curl_setopt_array($ch, $options);
curl_exec($ch);

//Hit data page 
$options[CURLOPT_URL] = $pages['data'];
curl_setopt_array($ch, $options); 
$data = curl_exec($ch); 

//Output data
echo $data; 

//Close curl session 
curl_close($ch); 
j0k
  • 22,600
  • 28
  • 79
  • 90
Mhel
  • 167
  • 1
  • 11

3 Answers3

0

If you are looking for data from 'https://merchant.channeladvisor.com/AM/MyInventory/View_Inventory.aspx' Why not use the API instead?

http://developer.channeladvisor.com/display/cadn/Inventory+Service

Sean
  • 282
  • 3
  • 11
0

If exporting your inventory information is all you're trying to do, ChannelAdvisor has its own UI-available inventory export service. At very least, you can automate your code to kick that off and download the exported csv or tab delim file: http://ssc.channeladvisor.com/howto/exporting-inventory

-1

I think you should handle such update from Channel Advisor and so, follow the redirect.

Since I don't think this is a common way to login to Channel Advisor using curl, you will always need to update your code on each Channel Advisor update. It remember me when we can only use curl to retrieve Google Analytics data: every time they update the login system, you have to rewrite your own curl login method - boring.

You can read this answer about following a Header: Location with curl. Basically:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$a = curl_exec($ch);
if(preg_match('#Location: (.*)#', $a, $r))
 $l = trim($r[1]);
Community
  • 1
  • 1
j0k
  • 22,600
  • 28
  • 79
  • 90