Connector Synchronize REST API - Automating the Synchronization Process

  • 1
  • Problem
  • Updated 3 years ago
We are getting an error "System.HttpResponse[Status=Forbidden, StatusCode=403]", on comment synchronization. 
Photo of Fahad Ali

Fahad Ali

  • 49 Posts
  • 0 Reply Likes

Posted 3 years ago

  • 1
Photo of Sattesh Maran

Sattesh Maran

  • 8 Posts
  • 0 Reply Likes
Hey Fahad,

Can you please check to see if the user profile in JIRA has sufficient permission to use the connector?

As stated in the documentations here, the user in JIRA must have Browse Project, Create Issues and Edit Issues permissions for the relevant projects.The user should also have Add Comment, if comments are also being synced.

You can also refer to this previous thread for more information.

Thank you.

Regards,
Sattesh
(Edited)
Photo of Fahad Ali

Fahad Ali

  • 49 Posts
  • 0 Reply Likes
Thanks for your reply.

I am using admin user. It has all permissions. Still getting error.
Photo of Sattesh Maran

Sattesh Maran

  • 8 Posts
  • 0 Reply Likes
Hey Fahad,

There is a possibility that even the admin user might not have all the permission needed.

Can I please get a full screenshot of your "Users and Roles" and "Permissions" page.

You can find the pages at Settings(the cog icon)>Projects>"Name-of-your-Project"
"Users and Roles" and "Permissions" should be on the left hand side panel of the project page.

Thank you.

Regards, 
Sattesh
(Edited)
Photo of Fahad Ali

Fahad Ali

  • 49 Posts
  • 0 Reply Likes
global class JIRAConnectorWebserviceCalloutSync { 
    @future (callout=true) WebService static void synchronizeWithJIRAIssue(String baseUrl, String systemId, String objectType, String caseId) {
        try {

            HttpRequest req = buildRequest(baseUrl, JIRA.username, JIRA.password, systemId, objectType, caseId);
            JIRA.sendRequest(req);
        } catch(System.CalloutException e) {        
            System.debug(e);
        }
    }
 
    // Constructs request needed to synchronize a JIRA issue from provided parameters.
    //public static HttpRequest buildRequest(String systemId, String objectType, String caseId) {
    public static HttpRequest buildRequest(String baseUrl, String username, String password,
                                           String systemId, String objectType, String caseId) {
      
        
        HttpRequest req = new HttpRequest();
        String basicAuthHeader = JIRA.authHeader(username, password);
        String endpoint = getEndpoint(baseUrl, systemId, objectType, caseId);
        req.setHeader('Authorization', basicAuthHeader);
        system.debug('FA Testing '+basicAuthHeader);
        req.setHeader('Content-Type', 'application/json');
        req.setHeader('Content-Length', '0');
        req.setEndpoint(endpoint);
        req.setMethod('PUT');
        return req;
    }
 
    // Creates the endpoint to synchronize the issue from provided parameters.
    private static String getEndpoint(String baseUrl,String systemId, String objectType, String caseId) {        
        return baseUrl + '/rest/customware/connector/1.0/' + systemId + '/' + objectType +  '/' + caseId + '/issue/synchronize.json';
    }
 
}
Photo of Fahad Ali

Fahad Ali

  • 49 Posts
  • 0 Reply Likes
trigger CaseCommentSyncTrg on CaseComment (after insert, after update) {    
    // Check whether current user is not JIRA agent so that we don't create an infinite loop.
    if (JIRA.currentUserIsNotJiraAgent()) {
        for (CaseComment cc : Trigger.new) { 
            String objectType ='Case'; // Please change this according to the object type.     
            String objectId = cc.ParentId;
            // Calls the actual callout to synchronize with the JIRA issue.
            JIRAConnectorWebserviceCalloutSync.synchronizeWithJIRAIssue(JIRA.baseUrl, JIRA.systemId, objectType, objectId);
        }
    }
 
}
Photo of Sattesh Maran

Sattesh Maran

  • 8 Posts
  • 0 Reply Likes
Hey Fahad, 

To recap, we have confirmed that;

  1. You are logged in as user "sdogar" in JIRA using your username and not your email
  2. Checked that user "sdogar" has Browse Project, Create IssuesEdit Issues and Add Comment permission using the permission checker
  3. You can sync case/issues but cannot sync case comments (The problem)
  4. The username in your Salesforce Apex class is your username and not your email

We have looked at your Apex classes and triggers and everything seems to be in order.

If you are sure everything else you have provided is accurate, please do contact us at support@servicerocket.com so that we can arrange a screen share session to troubleshoot the problem.

Thank you.

Regards,
Sattesh
Photo of Fahad Ali

Fahad Ali

  • 49 Posts
  • 0 Reply Likes
Yes, we are logging in by using username not email and also using this username in Salesforce Apex class.
We are getting issue in comments sync by using API call, but comments are synchronizing successfully by using plugin standard functionality.
Photo of Sattesh Maran

Sattesh Maran

  • 8 Posts
  • 0 Reply Likes
Hey Fahad,

Thanks for confirming that.

Please contact us at support@servicerocket.com so that we can arrange a screen share session to troubleshoot the problem.

Thank you.

Regards,
Sattesh