PHP authentication methods for Jira REST API requests

I’m trying to fetch user details from our Jira instance using PHP and cURL but keep running into authentication issues. Every time I make a request to the API endpoint, I get a 401 error saying the client needs to be authenticated.

Here’s my current attempt:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://mycompany.atlassian.net/rest/api/2/user?accountId=abc123');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
print_r($response);
curl_close($ch);

The server responds with:

401 Unauthorized - Authentication credentials were not provided

What’s the proper way to handle authentication when working with Jira’s REST API? Should I use basic auth, API tokens, or OAuth? I’m fairly new to API integration so looking for the most straightforward approach that actually works.

Had the same headaches when I started with Jira’s API. You’re missing authentication headers for sure. Everyone’s talking about API tokens, but try using CURLOPT_USERPWD instead of building the Authorization header manually. Just do curl_setopt($ch, CURLOPT_USERPWD, $email . ':' . $api_token); - works great. If you’re on Jira Cloud, you HAVE to use API tokens since they killed username/password auth. Server instances can still do basic auth with passwords, but honestly just stick with tokens. Watch out for the base URL format too - needs to be exactly https://yourcompany.atlassian.net. Don’t use http:// and don’t mess up the subdomain structure or you’ll pull your hair out.

you gotta set up some auth headers in your curl req. first, get an API token from atlassian account settings. then, add this line before you execute:
curl_setopt($ch, CURLOPT_HTTPHEADER, [‘Authorization: Basic ’ . base64_encode($email.’:'.$api_token)]);

API tokens with basic auth is your best bet here. I ran into the same thing when I started with Jira’s API. You’re probably not setting up the auth headers right in your cURL request. Generate your API token from Atlassian account settings, then encode your email and token with base64. This is what works for me: php $email = '[email protected]'; $api_token = 'your-generated-token'; $auth = base64_encode($email . ':' . $api_token); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: Basic ' . $auth, 'Content-Type: application/json' ]); Double-check you’re using the right email for your Atlassian account. OAuth’s overkill unless you need multi-user authentication. Basic auth with API tokens is rock solid and way simpler.