2

I have the following json Response I get through a webhook with jira and a @restresource apex class.

 {
  "timestamp": 1572538898517,
  "webhookEvent": "jira:issue_updated",
  "issue_event_type_name": "issue_updated",
  "user": {
    "self": "*",
    "accountId": "*",
    "emailAddress": "?",
    "avatarUrls": {
      "48x48": "*",
      "24x24": "*",
      "16x16": "h*",
      "32x32": "*"
    },
    "displayName": "*",
    "active": true,
    "timeZone": "*",
    "accountType": "atlassian"
  },
  "issue": {
    "id": "11122",
    "self": "*",
    "key": "TES-8",
    "fields": {
      "statuscategorychangedate": "2019-10-25T10:17:49.042+0200",
      "issuetype": {
        "self": "*",
        "id": "10003",
        "description": "A task that needs to be done.",
        "iconUrl": "*",
        "name": "Task",
        "subtask": false,
        "avatarId": 10318
      },
      "timespent": null,
      "customfield_10030": null,
      "project": {
        "self": "*",
        "id": "10013",
        "key": "TES",
        "name": "Testumgebung",
        "projectTypeKey": "software",
        "simplified": false,
        "avatarUrls": {
          "48x48": "*",
          "24x24": "*",
          "16x16": "*",
          "32x32": "*"
        }
      },
      "customfield_10032": null,
      "customfield_10033": null,
      "fixVersions": [],
      "aggregatetimespent": null,
      "resolution": null,
      "customfield_10035": null,
      "customfield_10036": null,
      "customfield_10037": null,
      "customfield_10027": null,
      "customfield_10028": null,
      "resolutiondate": null,
      "workratio": -1,
      "watches": {
        "self": "*",
        "watchCount": 1,
        "isWatching": true
      },
      "lastViewed": "2019-10-31T17:21:35.190+0100",
      "created": "2019-10-25T10:17:48.897+0200",
      "customfield_10020": [],
      "customfield_10021": null,
      "priority": {
        "self": "*",
        "iconUrl": "*",
        "name": "Low",
        "id": "4"
      },
      "customfield_10024": null,
      "customfield_10026": null,
      "labels": [],
      "customfield_10016": null,
      "customfield_10017": null,
      "customfield_10018": null,
      "customfield_10019": "0|i005x3:",
      "timeestimate": null,
      "aggregatetimeoriginalestimate": null,
      "versions": [],
      "issuelinks": [],
      "assignee": null,
      "updated": "2019-10-31T17:21:38.508+0100",
      "status": {
        "self": "*",
        "description": "",
        "iconUrl": "*",
        "name": "Backlog",
        "id": "10005",
        "statusCategory": {
          "self": "*",
          "id": 2,
          "key": "new",
          "colorName": "blue-gray",
          "name": "New"
        }
      },
      "components": [],
      "timeoriginalestimate": null,
      "description": "Blub",
      "customfield_10013": null,
      "customfield_10014": null,
      "customfield_10015": {
        "hasEpicLinkFieldDependency": false,
        "showField": false,
        "nonEditableReason": {
          "reason": "PLUGIN_LICENSE_ERROR",
          "message": "Portfolio for Jira must be licensed for the Parent Link to be available."
        }
      },
      "timetracking": {},
      "customfield_10005": null,
      "customfield_10006": null,
      "security": null,
      "customfield_10007": null,
      "customfield_10008": null,
      "customfield_10009": null,
      "aggregatetimeestimate": null,
      "attachment": [],
      "summary": "as",
      "creator": {
        "self": "*",
        "name": "*",
        "key": "*",
        "accountId": "*",
        "emailAddress": "*",
        "avatarUrls": {
          "48x48": "*",
          "24x24": "*",
          "16x16": "*",
          "32x32": "*"
        },
        "displayName": "*",
        "active": true,
        "timeZone": "*",
        "accountType": "atlassian"
      },
      "subtasks": [],
      "reporter": {
        "self": "*",
        "name": "*",
        "key": "*",
        "accountId": "*",
        "emailAddress": "*",
        "avatarUrls": {
          "48x48": "*",
          "24x24": "*",
          "16x16": "*",
          "32x32": "*"
        },
        "displayName": "*",
        "active": true,
        "timeZone": "*",
        "accountType": "atlassian"
      },
      "customfield_10000": "{}",
      "aggregateprogress": {
        "progress": 0,
        "total": 0
      },
      "customfield_10001": null,
      "customfield_10002": null,
      "customfield_10003": null,
      "customfield_10004": null,
      "customfield_10038": null,
      "customfield_10039": null,
      "environment": null,
      "duedate": null,
      "progress": {
        "progress": 0,
        "total": 0
      },
      "votes": {
        "self": "*",
        "votes": 0,
        "hasVoted": false
      }
    }
  },
  "changelog": {
    "id": "23861",
    "items": [
      {
        "field": "summary",
        "fieldtype": "jira",
        "fieldId": "summary",
        "from": null,
        "fromString": "gsadgd",
        "to": null,
        "toString": "as"
      }
    ]
  }
}

I'm trying to get the value "as" from "summary".

This is the code I have right now:

    @RestResource(urlMapping='/test/*')

     global with sharing class IssueController {
    public class issue{
          public string expand;
          public fields fields;
          public string id;
          public string key;
          public string self;
    }
         public class Fields {
             public string summary;
         }

        @HttpPost
    global static void CreateIssue()
    {
        RestRequest req = RestContext.request;
        String requestBody = req.requestBody.toString();
        Issue Issue = (Issue) JSON.deserialize(requestbody, Issue.class);

        JiraIssue__c i=new JiraIssue__c();
        i.Key=issue.key;
i.summary=issue.summary;
        insert i;

    }
     }

The issue gets created but the fields are empty.

1 Answer 1

0

This is probably the simplest approach:

Map<String, Object> root = (Map<String, Object>) JSON.deserializeUntyped(jsonString);
Map<String, Object> issue = (Map<String, Object>) root.get('issue');
Map<String, Object> fields = (Map<String, Object>) issue.get('fields');
String summary = (String) fields.get('summary');

if all you want to do is access that single value.

(In your code, you are missing a class for the root object that has a field called "issue" holding data of type Issue.class.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .