forbidden+request+403

  • 1
  • Problem
  • Updated 2 years ago
  • (Edited)
Hi,

i have followed the documentation on the given url below

https://docs.servicerocket.com/display/CFSJ/Writing+Apex+Class+to+Call+for+Connector+REST+APIs


when i try to create Jira Ticket using Detail page button, it got successfully created in the Jira Side

But when i created class to create Case in the Jira Project.
Found the Error : System.HttpResponse[Status=Forbidden, StatusCode=403]

I have installed Jira in my local host and tried to access the same through Local IP
http://192.168.1.136:8080/

I hope this is throwing me error.

Please provide solution for this ASAP, our client has purchased the Service Rocket plugin and not satisfactory with this.


Here is my Mail ID : kranti.balagam.1@gmail.com


Thank You,
Kranti
Photo of kranti balagam

kranti balagam

  • 3 Posts
  • 0 Reply Likes

Posted 2 years ago

  • 1
Photo of Suresh Mathusuthanan

Suresh Mathusuthanan, Alum

  • 117 Posts
  • 9 Reply Likes
Hi Kranti,

Can you share with us the following :

  • JIRA version
  • ServiceRocket Salesforce.com Connector Plugin
Can you verify that your JIRA server is not configured behind the firewall ?

Besides, can you please provide us with a with the Apex Code that you have implemented? (Please remove the credential in the Apex Code)

Thank you. 

Regards,
Suresh
Photo of kranti balagam

kranti balagam

  • 3 Posts
  • 0 Reply Likes
Hi Suresh,

Here are the Details you requested for:
JIRA Version : JIRA v7.1.9
ServiceRocket Salesforce.com Connector Plugin : v. 6.0.15

Our Client JIRA Server is with in the Firewall, they does not want to configure outside of Firewall.

Here is the Apex Codes :

Parent Code :
public with sharing class JIRA {
 
    // Change values in this class according to you JIRA/Salesforce coordinates.
 
    public static String baseUrl = 'http://192.168.1.136:8080/'; // Base URL of your JIRA instance
    public static String systemId = '2'; // Salesforce Connector System ID in JIRA
    public static String username = 'xxx';  // JIRA username
    public static String password = 'xxxx'; // JIRA password
 
    public static String agentProfileName = 'System Administrator'; // Jira agent profile name in Salesforce
 
    // Constructs Basic Http Authentication header from provided credentials
    public static String authHeader(String u, String p) {
        Blob headerValue = Blob.valueOf(u + ':' + p);
        return 'Basic ' + EncodingUtil.base64Encode(headerValue);
    }
 
    // Sends a request and returns the response
    public static HttpResponse sendRequest(HttpRequest req) {
        Http http = new Http();
        system.debug('Request Sent');
        return http.send(req);
    }
 
    // Detects whether current user is not JIRA agent. By calling this you can make sure that
    // infinite loops won't happen in triggers (for instance when synchronizing an issue with JIRA)
    public static Boolean currentUserIsNotJiraAgent() {
        //Boolean allow = false;
        Boolean allow = true;
        List<Profile> jiraAgentProfile = [SELECT Id FROM Profile WHERE Name=:JIRA.agentProfileName];
        if (!jiraAgentProfile.isEmpty()) {
            String jiraProfileAgentId = String.valueOf(jiraAgentProfile[0].id);
            allow = UserInfo.getProfileId() != jiraProfileAgentId;
           
        }
        system.debug('Verified User');
        return allow || Test.isRunningTest();
    }
 
}



Apex Code:

global class JIRAConnectorWebserviceCalloutCreate {
 
    @future (callout=true) WebService static void createIssue(String baseUrl, String systemId, String objectType, String objectId, String projectKey, String issueType) {
        try {
            HttpRequest req = buildRequest(baseUrl, JIRA.username, JIRA.password, systemId, objectType, objectId, projectKey, issueType);
            HttpResponse ress = new HttpResponse();
            ress = JIRA.sendRequest(req);
            system.debug('Printing Response');
            system.debug('Response ----'+ress );
        } catch(System.CalloutException e) {
            System.debug(e);
        }
    }
 
    // Constructs request needed to create a JIRA issue from provided parameters.
    @testVisible private static HttpRequest buildRequest(String baseUrl, String username, String password,
                                           String systemId, String objectType, String objectId,
                                           String projectKey, String issueType) {
        HttpRequest req = new HttpRequest();
        String basicAuthHeader = JIRA.authHeader(username, password);
        String endpoint = getEndpoint(baseUrl, systemId, objectType, objectId);
        req.setHeader('Authorization', basicAuthHeader);
        req.setHeader('Content-Type','application/json');
        req.setMethod('POST');
        req.setEndpoint(endpoint);
        req.setBody('{"project":"' + projectKey + '", "issueType":"' + issueType + '"}');
                system.debug('Request prepared');
        return req;
    }
 
    // Creates the endpoint to create the issue from provided parameters.
    private static String getEndpoint(String baseUrl, String systemId, String objectType, String objectId) {
        return baseUrl + '/rest/customware/connector/1.0/' + systemId + '/' + objectType + '/' + objectId + '/issue/create.json';
      
    }
 
}


Trigger :
trigger CreateIssue on Case (after insert) {
 
    // Check whether current user is not JIRA agent so that we don't create an infinite loop.
    //if (JIRA.currentUserIsNotJiraAgent()) {
        for (Case c : Trigger.new) {
            // Define parameters to be used in calling Apex Class
            String objectType ='Case';  // Please change this according to the object type
            String objectId = c.id;
            String projectKey = 'SFDC'; //Please change this according to the JIRA project key
            String issueType = '1';     //Please change this according to the JIRA issue type ID
            // Calls the actual callout to create the JIRA issue.
            system.debug('Trigger fired');
            JIRAConnectorWebserviceCalloutCreate.createIssue(JIRA.baseUrl, JIRA.systemId, objectType, objectId, projectKey, issueType);
        }
    //}




Thank You,
Kranti.
Photo of Suresh Mathusuthanan

Suresh Mathusuthanan, Alum

  • 117 Posts
  • 9 Reply Likes
Hi Kranti,

If you wish to use Apex classes and triggers, please make sure JIRA Server is not behind the firewall, you can read it in our documentation to understand better. 

However, I would suggest you to whitelist your IP.

Thank you.

Regards,
Suresh
Photo of kranti balagam

kranti balagam

  • 3 Posts
  • 0 Reply Likes
Hi Suresh,

I have whitelisted my IP Address in JIRA
as i am testing in Our local machine,  we have disabled Windows Firewall too.
event then we facing the same 403 Error.
Please help with this, please suggest if we could have a call with screen share and resolve the issue.
our client is facing problem with this.

Thank You,
Kranti.
Photo of Aidin Mahmoodi

Aidin Mahmoodi, Alum

  • 267 Posts
  • 6 Reply Likes
Hi Kranti,

Not behind the firewall that Suresh is mentioning basically means that you JIRA should be assigned with a public IP/DNS.

Salesforce is a Cloud base solution and in order to for Salesforce to communicate to JIRA, you JIRA should be available on Internet or at least exposed to Salesforce.com (hence the white-list).

The URL that you are configuring however, http://192.168.1.136:8080 is a local address which implies that would not be exposed to public internet and Salesforce.com.

You need to configure Public IP or a Public DNS in order to make JIRA publicly available.

Hope this clarifies.

Cheers,
Aidin