How to make REST api call from groovy script (credentials not working)

rodolfocostapr August 20, 2020

Hi, I’m trying to use this script from adaptavist library: https://library.adaptavist.com/entity/create-a-tempo-account-using-the-rest-api

But the "credentials" variable appears to be null after the following code, so i cant make the Basic authentication:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import groovyx.net.http.ContentType
import groovyx.net.http.EncoderRegistry
import groovyx.net.http.HttpResponseDecorator
import groovyx.net.http.RESTClient

final String userPropertyKey = "jira.meta.basicAuthCreds"

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def credentials = ComponentAccessor.userPropertyManager.getPropertySet(loggedInUser).getString(userPropertyKey)
def baseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL)

1 answer

1 accepted

1 vote
Answer accepted
Miguel Ángel García Gómez August 23, 2020

Hello @rodolfocostapr,

I am part of the Library Project team. Please, do you mind creating this question in our portal https://productsupport.adaptavist.com/servicedesk/customer/portal/49/create/337? Thus, we can track this issue better. For me time being, it might be a silly answer, but have you created correctly "basicAuthCreds" as a Jira User Property?

Thank you very much.

Regards,

Miguel.

rodolfocostapr August 24, 2020

Hi @Miguel Ángel García Gómez , im not the admin for the instalation, but i will check with him. Can you give me a link to a tutorial with the instructions on how to create the "basicAuthCreds" User Property? I having a hard time finding one.

Miguel Ángel García Gómez August 24, 2020

Hello @rodolfocostapr ,

Sure, I can share with you this script, also included in Library, where the user properties are used. And  here is the link for the official documentation provided by Atlassian ("Add a property to a user" section), explaining how to manage these properties.

I hope this can help you.

Regards,

Miguel.

rodolfocostapr August 25, 2020

Hello @Miguel Ángel García Gómez , I have read the material e now I have a better understanding of the situation. But can u point out to me how the basicAuthCreds would be added to the User Property, I haven’t found how the password would be stored in there.

Miguel Ángel García Gómez August 25, 2020

Hello @rodolfocostapr ,

As you can see in the description of the Library script, it can be added as:

 

API request credentials are stored as user properties. This property is named as basicAuthCreds and it contains user and password in the following format: <user>:<password>.

So it could be something like admin:admin. But please, bear in mind changing it for a strongest password ;) 

Regards,

Miguel.

Suggest an answer

Log in or Sign up to answer