Skip to content

How to authenticate to XTRF using REST API with PHP, CURL

Last updated on February 10, 2018

Today I would like to write about Authenticating to XTRF using Rest API with PHP. After authenticating we can manage users, projects, and estimate ..etc.

Below is the function of making a post request to XTRF REST API with your credentials.

setAdapter(new \Zend\Http\Client\Adapter\Curl());
	$client->setOptions(array(
		'curloptions' => array(
			CURLOPT_POST => 1,
			CURLOPT_RETURNTRANSFER => 1,
			CURLOPT_SSL_VERIFYPEER => FALSE,
			CURLOPT_SSL_VERIFYHOST => FALSE,
			CURLOPT_COOKIEJAR => sys_get_temp_dir().DIRECTORY_SEPARATOR.$username.'_cookie.txt',
			CURLOPT_HEADER => TRUE,
		)
	));
	$request = new \Zend\Http\Request();
	$request->setUri($url);
	$request->setMethod(\Zend\Http\Request::METHOD_POST);
	$request->setContent($postString);
	$response = $client->dispatch($request);
	return json_decode($response->getContent());
}

How to use

Just pass the username and password to the function as shown below, after success full authentication it will create a cookie file, we need this generated cookie for further operations(for making other API requests) like getting projects list, Estimations list..etc.

 authenticate('UserName', 'Password');

That’s it.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments