Integrations and APIs for Service

Get Involved. Join the Conversation.

Topic

    Mike Chelotti
    How do you modify the email address for an Agent using the...Answered
    Topic posted November 20, 2018 by Mike ChelottiBlue Ribbon: 750+ Points 
    44 Views, 7 Comments
    Title:
    How do you modify the email address for an Agent using the REST API.
    Content:

    We migrated to a new domain and need to update all of our Agents email addresses to the new domain suffix. Can this be done using the REST API ? I don't see any examples in the Rest API Guide ?

    Version:
    18A

    Best Comment

    Robert Surujbhan

    The correct JSON data payload for updating a staff account's email address is below.  The "addressType" ID value of zero/0 means the "Email - Primary" type.

    You would need to send this to the account's resource ID endpoint (e.g., https://site/services/rest/connect/<version>/accounts/12345).  You can use PATCH as you were trying and if your network supports it, or alternatively, you can also use POST by supplying the X-HTTP-Method-Override header set to "PATCH" - both should work.

    {
            "emails":[
                    {
                        "address": "agent@newdomain.com",
                        "addressType": {
                            "id": 0
                        }                   
                    }
            ]
    }
    

    Comment

     

    • Sebastiaan Draaisma

      Hi Mike

      Yes, it can be done. See attached account update example (working example).
      I think the only change you need to make is:

      data: JSON.stringify({
                                      Email : {
                                          Address: "agent@newdomain.com"
                                      }                                            
                                              
                                  })

      Unfortunately I don't have the time to upload this to a server and test but it should point you in the right direction.

       

    • Mike Chelotti

      Thanks Sebastiaan, 

      I modified the file to edit the Agent's email address rather than disable from assignment. When I open the file I see a button called "Edit Agents Email Address" 

      I am able to click it . However I don't see any changes made to the Agents contact record? Does this JSON formatting look correct to you?  

      <!DOCTYPE html>

      <html>

      <head>

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

      <script>

      function updateContactRecord(){

              return $.ajax({

                        url: 'https://arbor--tst.custhelp.com/services/rest/connect/v1.3/accounts/12274',

                        method: "POST",

                        headers:{'Authorization':'Basic ' + btoa('USERNAME:PASS'),'X-HTTP-Method-Override': 'PATCH'},

                        data: JSON.stringify({

                                                                      Email : {

                                          Address: "mike.chelotti@netscout.com"

                                      }

       

       

       

       

                                                              }),

                        dataType: "json"

                      });

      }

      </script>

      </head>

      <body>

       

      <button onclick="updateContactRecord()">Edit Agents Email Address</button>

       

       

      </body>

      </html>

       

    • Sebastiaan Draaisma

      Hi Mike.

      No, I made a mistake.
      The correct GET request indicates ......services/rest/connect/v1.3/accounts/1594/emails/0/address
      You would need to translate this in your PATCH (update) request. Even though there can only be one email address in the account it seems like it's part of an array.

    • Mike Chelotti

      Okay the GET returns

       

      {
          "address": "agent@olddomain.com"
      }

      If I try and PATCH with https://INTERFACE.custhelp.com/services/rest/connect/v1.3/accounts/12274/emails/0/address and in the request field 

       

      {
          "address": "agent@newdomain"
      }

      Returns an error

      {
          "type": "https://INTERFACE/services/rest/connect/exceptions/OSC-CREST-00006",
          "title": "An attempt to write a resource failed",
          "status": 400,
          "detail": "A problem setting a property was encountered: not an object; Account.Emails[0].Address",
          "instance": "https://INTERFACE.com/services/rest/connect/v1.3/accounts/12274/emails/0/address",
          "o:errorCode": "OSC-CREST-00006"
      }

      I've also tried PATCH with your example PHP 

      Email : {

                                          Email Address: agent@newdomain.com

                                      }

       
      And  I got a JSON Format error. 
    • Robert Surujbhan

      The correct JSON data payload for updating a staff account's email address is below.  The "addressType" ID value of zero/0 means the "Email - Primary" type.

      You would need to send this to the account's resource ID endpoint (e.g., https://site/services/rest/connect/<version>/accounts/12345).  You can use PATCH as you were trying and if your network supports it, or alternatively, you can also use POST by supplying the X-HTTP-Method-Override header set to "PATCH" - both should work.

      {
              "emails":[
                      {
                          "address": "agent@newdomain.com",
                          "addressType": {
                              "id": 0
                          }                   
                      }
              ]
      }
      
    • Sebastiaan Draaisma

      Sorry for the late response (different time zones) :-)
      Thanks for helping out Robert