Custom JIRA connector

I have tried using the inbuild JIRA connector but I believe our businesses JIRA has customfields which means I cant make sense of the data using this connector and get data like this:

Therefore I am trying to build my own custom JIRA connector. I am however experiencing issues with the Authentication part.

Has anyone else managed to get this set up?

current code is :

httprequest.addHeader('Accept' , 'application/json');
httprequest.addHeader('Authorization' , 'Basic ' + btoa(metadata.account.Username + metadata.account.APIToken));

//Make API call
var res = httprequest.get(metadata.account.JIRA_URL+'rest/api/3/myself');

what I get is

'ERROR: Client must be authenticated to access this resource.'

These credentials work in the available connector

thanks

Best Answer

  • ArborRose
    ArborRose Coach
    Answer ✓

    Correct Encoding for Basic Auth:

    Ensure you are encoding the credentials correctly for Basic Authentication. The btoa function should encode the credentials as username:api_token.

    For example, if metadata.account.Username is user@example.com and metadata.account.APIToken is your_api_token, the btoa function should encode the string user@example.com:your_api_token.

    Correct API Endpoint:

    Ensure that the API endpoint metadata.account.JIRA_URL+'rest/api/3/myself' is correct. The base URL should end with a slash (/) if it’s not included in the variable metadata.account.JIRA_URL.

    Basic Authentication Header Format:

    The Basic Authentication header should be formatted as Basic <encoded_credentials>. Make sure there is no extra space or incorrect formatting.

    Check API Token and Permissions:

    Verify that the API token you’re using has the appropriate permissions to access the JIRA API. Also, ensure that the API token is active and has not expired or been revoked.

    Verify Credentials:

    Test the credentials with a REST client (like Postman) to ensure that they work outside your code. This can help isolate whether the issue is with your code or the credentials.

    Correct URL Encoding:

    Ensure that metadata.account.JIRA_URL is properly URL-encoded if necessary.

    // Create HTTP request
    var httprequest = new Request();
    httprequest.addHeader('Accept', 'application/json');


    // Encode credentials
    var credentials = metadata.account.Username + ':' + metadata.account.APIToken;
    var encodedCredentials = btoa(credentials);

    // Add Authorization header
    httprequest.addHeader('Authorization', 'Basic ' + encodedCredentials);

    // Make API call
    var res = httprequest.get(metadata.account.JIRA_URL + 'rest/api/3/myself');

    // Log response
    console.log(res);

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

Answers

  • ArborRose
    ArborRose Coach
    Answer ✓

    Correct Encoding for Basic Auth:

    Ensure you are encoding the credentials correctly for Basic Authentication. The btoa function should encode the credentials as username:api_token.

    For example, if metadata.account.Username is user@example.com and metadata.account.APIToken is your_api_token, the btoa function should encode the string user@example.com:your_api_token.

    Correct API Endpoint:

    Ensure that the API endpoint metadata.account.JIRA_URL+'rest/api/3/myself' is correct. The base URL should end with a slash (/) if it’s not included in the variable metadata.account.JIRA_URL.

    Basic Authentication Header Format:

    The Basic Authentication header should be formatted as Basic <encoded_credentials>. Make sure there is no extra space or incorrect formatting.

    Check API Token and Permissions:

    Verify that the API token you’re using has the appropriate permissions to access the JIRA API. Also, ensure that the API token is active and has not expired or been revoked.

    Verify Credentials:

    Test the credentials with a REST client (like Postman) to ensure that they work outside your code. This can help isolate whether the issue is with your code or the credentials.

    Correct URL Encoding:

    Ensure that metadata.account.JIRA_URL is properly URL-encoded if necessary.

    // Create HTTP request
    var httprequest = new Request();
    httprequest.addHeader('Accept', 'application/json');


    // Encode credentials
    var credentials = metadata.account.Username + ':' + metadata.account.APIToken;
    var encodedCredentials = btoa(credentials);

    // Add Authorization header
    httprequest.addHeader('Authorization', 'Basic ' + encodedCredentials);

    // Make API call
    var res = httprequest.get(metadata.account.JIRA_URL + 'rest/api/3/myself');

    // Log response
    console.log(res);

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

  • wow, thats great thanks. It was the btoa part I had the format wrong on :)