Data load script using REST API add "externalKey" to groups

Not Yet Reviewed

Hi, we are using the CA SDM Data Load via our integration agent and need to make use of the "externalKey" field which is available when using the REST API.

Ideally I am looking for a ready made piece of JavaScript which could convert the SOAP xml string which gets constructed to add/update/query a group into a ready string which could be sent to the REST API endpoint.

however if that is not possible then is there someone who could write a javascript include which I could call that simply queries and updates the externalKey field independently as I could then use that to query if a group exists based on the external key field and use the existing SOAP data load scripts for doing the adding/updating of all the other fields...?

The driver  behind this is we have just gone through an organisational restructure and the group names in our management system will be changing which need to reflect in Xmatters. Updating manually is not an option as we have 100's of groups already configured with rosters etc.



Date Votes

Please sign in to leave a comment.

  • Hey Alistair,

        Converting the SOAP xml can be a headache and some of the items won't make a good mapping or might not make sense. Also, off the top of my head the REST API uses a UUID for updates, which is not available in the SOAP API. So we might need to look at a different approach. 

    So, doing the query, check if it exists, then updating all via REST is pretty easy to do. I think the hard part will be figuring out where this externalKey value is coming from? Is it stored in CA SD and if so, is it currently being passed into the IA? I poked through this CA SD data sync and the group stuff is a little sparse. 

    So where do you expect the externalKey to come from?


  • Travis, thanks for reply. I'll be pulling a uuid from CA service desk, that's available and I'll bastardised the vanilla data sync plenty already so a bit more wont hurt :)

    My challenge is when it comes to web services, I'm less than a novice!

    Currently from what I can figure the data sync defines a new soap message then sets parameters, does some wiggy stuff to reuse existing values where applicable (supervisors, site, name etc) then calls the function sendReceive' from wsutil.js which does the sending.... I notice there is also a restSendReceive function in wsutil - if I define the correct rest endpoint and set a few required variables, can I just call this instead ?

  • Hey Alistair... not sure why but we didn't get notified of your Monday post until the wee hours this morning. Anyway, we'll track down Travis (I think he might be on the road this week).

  • Hi Alistair, 

    How will your team be changing the group names in CA SD?

    If that is an automated process you might also consider changing the xMatters group names at the same time? That might be easier as you could create a script that looks up groups using the old name and instantly updates it to the new name.  

    As far as I recall, the CA SD data sync will be expecting the group names to match in both CA SD and xMatters. If you change the CA SD group names ahead of time, I expect that the sync will create new groups with the new names in xMatters in addition to the existing ones.

    One other suggestion might be to:

    1. Populate the external key of all the existing xM groups with the group UUID from CA SD (As you also suggested)

    2. Update the group names in CA SD

    3. Update the data sync to look up xMatters group by UUID / external key instead of name

    4. If you find a match, sync the group name at the same time you sync all the members, etc. 

    Either way, you'll want to use the modify group web service in order to change the name or external key of the group.

  • Hi Iain, yes we will be updating the group names in CA SD. Your suggested approach of using the externalKey field is exactly what I'm wanting to do, unfortunately the data sync uses SOAP and I don't see the externalKey field as an available field in the wsdl....?

    Can I simply update the wsdl file to include the externalKey field and then make the necessary changes in the data sync to use it?


  • Hi Alistair,

    No, that won't work. The external key field is not supported by the SOAP API.

    How will you be updating the group names in CA SD? 




  • We will likely use a script to update the names within the database of CA...'

    Can someone give provide me with the couple of lines of code which will update the external key field using the REST api? I can then simply call this after the SOAP call for add/updates.


  • Anyone ???

  • I'll wrangle up someone to comment here, Alistair.

  • Hey Alistair, sorry for the delay. Lots going on lately. 

    I've put together and tested a couple of lines for the Integration Agent as that's where it sounds like you will be using it. You'll need to do some code reading to figure out where exactly to put this. 

    First, you'll need to add these two lines near the top of the script:


    The xmio (xMatters In/Out) is an easy library for making HTTP calls and is available in the IA 5.1.5 and after. 

    This is the function to do the work:

    function updateExternalKey( groupName, externalKey ) {

    // Get the group based on the group name
    var url = BASE_URL + "groups/" + groupName;
    var resp = XMIO.get( url, USERNAME, PASSWORD );

    if( resp.status != 200 ) {
    ServiceAPI.getLogger().error( "Error getting group '" + groupName + "' Response: " + resp.body );

    // Extract the group object
    var groupObj = JSON.parse( resp.body );
    ServiceAPI.getLogger().debug( "Group ID: " + );

    // Now make the update and send to xM
    groupObj.externalKey = externalKey +"";

    url = BASE_URL + "groups/";
    resp = JSON.stringify( groupObj ), url, USERNAME, PASSWORD );

    return JSON.parse( resp.body );


    You can put that anywhere in the IA script. 

    Then, when you find the place to call it, just insert this line:

    var groupObj = updateExternalKey( groupName, externalKey );

    Where groupName and externalKey are the name of the group in xMatters and the external key you want to set respectively. 

    In the course of this, I found an interesting feature. The externalKey is only returned from the GET /groups XM API call if it is populated. I entered a ticket with engineering to investigate, but in my testing I was still able to set, then retrieve the externalKey value. 

    I hope that helps. I'll be out on PTO for a few weeks so I won't be able to respond, but we should be able to find someone else to post if you run into trouble. 


Didn't find what you were looking for?

New post