4 Replies Latest reply on Aug 31, 2016 3:46 AM by devgeeks@adobe

    contacts xhr request via json


      Hi i retrieve all contacts from the device and i want to send this contacts to an wordpress rest api? Do i need to make a json object of all the contacts or how can i do it? thank you

        • 1. Re: contacts xhr request via json
          VectorP Level 4

          Well, what does your Wordpress rest api expect? What is its interface?

          • 2. Re: contacts xhr request via json
            devgeeks@adobe Adobe Employee

            Yes, usually you'll be POSTing a JSON object to your API.


            The Contacts plugin returns an array of Contact objects, so you should be able to use that as the body of your POST.


            My concern is the actual act of posting a users Contacts to an external site. Is this really necessary? This seems like a massive breach of privacy. What is the use case?

            • 3. Re: contacts xhr request via json
              eddiii17043368 Level 1

              Well thanks for the answer i'm trying to send the


              contact_name & contact_mobile which i packed into an javascript array.


              function onSuccess(contacts) {

              var json = [];  // create aJavascript Array


              //Iterate over the CONTACTS OBJECT and push name & number into JS Object {}

                      for (var i=0; i<contacts.length; i++) {

                          for (var j=0; j<contacts[i].phoneNumbers.length; j++) {

                              var con ={

                                  contact_name :  contacts[i].displayName,

                                  contact_mobile : contacts[i].phoneNumbers[j].value



                   //push new contact object into Array of Contact Objects



              //send all retrieved contacts via ajax to remote url





                  // onError: Failed to get the contacts  

                  function onError(contactError) {





              function sendContacts (contactData){


                                      type: "POST",

                                      url: "",

                                      crossDomain: true,

                                      dataType: 'json',

                                      data: JSON.stringify(contactData),

                                      timeout: 10000,

                                      success: function(data, status, jqXHR) {

                                          console.log("result is ");



                                      error: function(xhr, ajaxOptions, thrownError) {

                                          alert(ajaxOptions + " " + thrownError);






              The Problem is when i send the data as one object like


              "data": {

                  "contact_name": "Foo",

                  "contact_mobile": "0621234231"


              this it works but when i send the complete Array



              like [Object, Object, {"contact_name":"Foo", "contact_mobile":"221311"},{"contact_name":"Bar", "contact_mobile":"221311"}]

              it does not work

              • 4. Re: contacts xhr request via json
                devgeeks@adobe Adobe Employee

                Without knowing anything about what your API is expecting, the first thing that stands out is that the working data is an object whereas the other is an array. Could it be that the API is expecting a single contact object?