I am trying to use your REST API to create leads in erp.
I am logged in successfully… but facing problem in creating any document ie lead
Is there any API key or some process to get permission to create document in erpnext?
CODE:
<?php
//******************** LOGIN REQUEST ********************************//
$url= 'http://128.199.200.206/api/method/login';
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS,array(
'usr'=>'vineet@mittalagro.com',
'pwd'=>'vineet1234' // it is not real passwd but while sending request i am using real paswd
));
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
//******************** DOCUMENT CREATE REQUEST ******************************//
$response= json_decode($result,true);
if($response['message']=='Logged In'){
// Create lead.................................//
$url = 'http://128.199.200.206/api/resource/Lead';
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS,array(
'data' => '{"lead_name":"Lead00011"}'
));
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
echo $result;
}
?>
It doesn’t look like you are passing a cookie from the log in sequence when you are trying to create the document. I think the system is not recognizing that the person that logged in is trying to create the document.
Yes its not recognizing. but how to pass cookie from the log in sequence?
Nothing mentioned in documentation of Rest API that how to tell ERP System that who is trying to create document.
Yes that I know but to tell erpnext that this usr is creating document I need to passing a cookie from the log in sequence while trying to create the document.
So my question is how to pass a cookie from the log in sequence while creating document?
Every API like linkedin, facebook, google etc have api key and secret ki… just by passing those key along with the request help their system to validate our request.
But i think here things are different.
Please provide proper information that how to create documents? what steps are involve into it?
I know it’s simple but don’t have proper information about it.
You provided me php file link, I did whatever required. PHP is a very simple language, any developer can easily understand the code. I did whatever mentioned there. I am having good development experience in PHP. So even after doing everything as instructed, still it’s not validating. You give it a try, its just 5 min work. Because you know your system better.
<?php
/**
* FrappeClient-PHP Sample Script
*
*/
require(dirname(__FILE__).'/FrappeClient.php');
try{
$client = new FrappeClient();
var_dump($client);
// get ----------------------------
$result = $client->get(
"User"
,"puneetverma@mittalclothing.com"
);
var_dump($result);
}catch(Exception $e){
var_dump($e);
}
set_error_handler(function ($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
});
CONFIG.PHP
<?php if(!defined("ROOTPATH")){die("Access forbidden.".PHP_EOL);}
return array(
'auth_url' => 'http://mittalclothing.erpnext.com/api/method/login',
'api_url' => 'http://mittalclothing.erpnext.com/api/resource/',
'auth' => array('usr' => 'vineet@mittalagro.com', 'pwd' => 'password of this user'),
'cookie_file' => 'cookie.txt',
'curl_timeout' => 30,
'basic_auth' => array(),
// 'basic_auth' => array('usr' => '', 'pwd' => ''),
);
This much only need to change.. there is no other setting...
So now we can test with link http://erp.wholesaleraja.com/erpnext/sample.php