Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Problem Accessing Service Desk API

Himanshu Sharma
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 13, 2017

I have a service desk for my customer, and i have created various users in that service desk for users to log issue.

In my application I want my users to log issues from my application itself into service desk, using their credentials, but I m getting authentication error. But it works same when i use my admin credentials. 

So, my question is can i use the Service desk APIs using the customer's credentials which I have created for respective Service desk?

 

1 answer

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 14, 2017

Yes, you can use the customer credentials to do things with the API.

You'll need to explain what your code is doing when it tries to authenticate, and give us the full error message.

Himanshu Sharma
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 14, 2017

@Nic Brough [Adaptavist] Thanks for reply.

Code I m using is : (I m getting all service desk user belongs to, Using basic authentication)

private static String makeGetRequestToServiceDesk(String userName, String password, String requestUrl) 
    		throws ServiceDeskAuthenticationException, ServiceDeskAuthorizationException {
    	InputStream in = null;
    	HttpURLConnection conn = null;
    	try{
    		String base64Creds = getAuthenticationHeaderForServiceDesk(userName, password);
    		
    		URL url = new URL(SERVICE_DESK_URL + requestUrl);
	        conn = (HttpURLConnection) url.openConnection();
	        conn.setConnectTimeout(5000);
	        conn.setRequestProperty("Authorization", "Basic " + base64Creds);
	        conn.setRequestMethod("GET");
	        int code = conn.getResponseCode();
	        if(code == SERVICEDESK_AUTHENTICATION_ERROR_CODE) {
	        	throw new ServiceDeskAuthenticationException("Failed to authenticate user.");
	        }
	        if(code == SERVICEDESK_AUTHORIZATION_ERROR_CODE) {
	        	throw new ServiceDeskAuthorizationException("Failed to authorize user.");
	        }
	        in = new BufferedInputStream(conn.getInputStream());
	        String result = IOUtils.toString(in, "UTF-8");
	        
	        in.close();
	        String a = "";
	        return result;
		} catch (IOException e) {
			Activator.logError("Error making GET request to service desk: ",
					MessageSupport.getExceptionMessages(e));
		}
    	finally {
	        conn.disconnect();
		}
		return null;
    }

Error I m getting is: 

java.io.IOException: Server returned HTTP response code: 401 for URL: https://provartesting.atlassian.net/rest/servicedeskapi/servicedesk

Suggest an answer

Log in or Sign up to answer