Member
 
Join Date: Apr 2010
Posts: 79
Default PHP cURL POST request to a Suitelet - Cannot navigate directly to this page.

I've set up a suitelet that takes POST data, authenticates using a shared key and then creates a Vendor Return Authorisation based on the input. Essentially, the suitelet acts as a web service.

I've also set up a PHP script that uses cURL to POST the data to the suitelet, but for some reason I am getting the error "You are not allowed to navigate directly to this page."

The Suitelet is set up to run as administrator and to allow external access. All roles are selected as the audience in the deployment. The url being POSTed to is https://forms.netsuite.com/app/site/...g/scriptlet.nl and the contents of the POST contain the script, deploy, compid and h values. The execution log is empty.

Here is the relevant part of the php file:

PHP Code:
 function curl_post($url, array $post NULL, array $options = array()) 

    
$defaults = array( 
        
CURLOPT_POST => 1
        
CURLOPT_HEADER => 0
        
CURLOPT_URL => $url
        
CURLOPT_FRESH_CONNECT => 1
        
CURLOPT_RETURNTRANSFER => 1
        
CURLOPT_FORBID_REUSE => 1
        
CURLOPT_TIMEOUT => 4
        
CURLOPT_POSTFIELDS => http_build_query($post
    ); 

    
$ch curl_init(); 
    
curl_setopt_array($ch, ($options $defaults)); 
    if( ! 
$result curl_exec($ch)) 
    { 
        
trigger_error(curl_error($ch)); 
    } 
    
curl_close($ch); 
    return 
$result


$url 'https://forms.netsuite.com/app/site/hosting/scriptlet.nl';

if(isset(
$_POST['submit']))

    
$payload '{items:[';
    
    for(
$x 0$x <= $fldcount$x++)
    {
        if(!empty(
$_POST['product' $x]))
        {
            
$payload .= "{code:\"" $_POST['product' $x] . ",qtymissing:" $_POST['qtym' $x] . ",qtydamaged:" $_POST['qtyd' $x] . ",note:" $_POST['label' $x] . "}";
            if(
$x != $fldcount && !empty($_POST['product' . ($x 1)]))
            {
                
$payload .= ",";    
            }
        }
    }
    
    
$payload .= "]}";

    
$fields = array(
        
'script'    => 15,
        
'deploy'    => 1,
        
'compid'    => 25476,
        
'h'            => 'ba91648bbcc505325292',
        
'auth'        => $psk,
        
'po'        => $_POST['po'],
        
'lines'        => $payload
    
);

    
$options = array(
        
CURLOPT_RETURNTRANSFER    => true,
        
CURLOPT_SSL_VERIFYPEER    => false,  //Set to false for testing purposes.
        
CURLOPT_SSL_VERIFYHOST    => 2,
        
CURLOPT_CAINFO            => getcwd() . "/cacerts/VeriSignClass3PublicPrimaryCertificationAuthority-G5.crt"
    
);
    
    
$nsResponse curl_post($url$fields$options); 
 
dfcowell is online now Report Bad Post   Reply With Quote Quick reply to this message
Unread 11-10-2010, 02:16 AM   #2
Senior Member
 
Join Date: Jan 2010
Posts: 103
Send a message via Skype to BrettKnights
Default RE: PHP cURL POST request to a Suitelet - Cannot navigate directly to this page.

You might try setting a user agent header to mimic one of the common browsers

HTH
Brett Knights
__________________
Brett Knights
Qicnet Inc.
BrettKnights is offline Report Bad Post   Reply With Quote Quick reply to this message
Unread 11-12-2010, 10:49 AM   #3
Member
 
Join Date: Apr 2010
Posts: 79
Default

Thanks Brett, I've set it up to mimic Firefox, but it is still doing the same thing. I'll keep looking.
dfcowell is online now Report Bad Post   Reply With Quote Quick reply to this message
Unread 11-14-2010, 03:23 AM   #4
Senior Member
 
Join Date: Jan 2010
Posts: 103
Send a message via Skype to BrettKnights
Default RE: PHP cURL POST request to a Suitelet - Cannot navigate directly to this page.

Try posting something to that url from a browser. I hadn't looked at it before but on review it looks like you just took an internal suitelet url and changed the host.

Use a different browser or log out of Netsuite for the test.

To use "forms.netsuite.com" you have to make the suitelet not require login and set the audience to everyone.

HTH
Brett Knights
__________________
Brett Knights
Qicnet Inc.
BrettKnights is offline Report Bad Post   Reply With Quote Quick reply to this message
Unread 11-15-2010, 09:37 AM   #5
Member
 
Join Date: Apr 2010
Posts: 79
Default

Figured it out - it was the most stupid possible thing, I had the deployment set to "Testing" and so when I tried to access it through the PHP script, I got that message because as far as NetSuite was concerned, I wasn't logged in.

Thanks for your help Brett, you got me thinking and put me on the right track.
posted on 2010-11-30 10:19  houchengli  阅读(385)  评论(0编辑  收藏  举报