0

I am using mautic-node npm module for contacting mautic REST API from node.js.My aim is to create a contact from my app in mautic dashboard using mautic REST API,but i am facing issue in creating contact from node.js.Please help me to figure out this.

var mautic = require('mautic-api-node');
var request = require('request');
var config = require('../config/config.js');
var request = require('request');
exports.saveContact = (req, res) => {
queryParameters = JSON.stringify(req.body);
var username = "mauticUsername";
var password = "mauticPassword";
var auth = "Basic " + new Buffer.from(username + ":" + 
password).toString("base64");


var options = {
   url: 'https://mautic-url/api/contacts/new',
   method: "POST",
   form: queryParameters,
   headers: {
       "Authorization": auth
   }
};
request(options, (error, response, body) => {
   if (error) console.log(error);
   console.log("Body", body);
})

}

I am passing this request body to backend:-

  {
  "firstname":"firstname",
  "ipAddress":"Ipaddress",
  "lastname":"lastname",
  "email":"email"
  }

when i run this code i am getting this response

 Body {
 "contact": {
    "isPublished": true,
    "dateAdded": "2019-06-08T10:06:25+00:00",
    "dateModified": null,
    "createdBy": 1,
    "createdByUser": "username",
    "modifiedBy": null,
    "modifiedByUser": null,
    "id": 1277,
    "points": 0,
    "color": null,
    "fields": {
        "core": {
            "title": {
                "id": 1,
                "group": "core",
                "label": "Title",
                "alias": "title",
                "type": "lookup",
                "value": null
            },
            "firstname": {
                "id": 2,
                "group": "core",
                "label": "First Name",
                "alias": "firstname",
                "type": "text",
                "value": null
            },
            "lastname": {
                "id": 3,
                "group": "core",
                "label": "Last Name",
                "alias": "lastname",
                "type": "text",
                "value": null
            },
            "company": {
                "id": 4,
                "group": "core",
                "label": "Primary company",
                "alias": "company",
                "type": "text",
                "value": null
            },
            "position": {
                "id": 5,
                "group": "core",
                "label": "Position",
                "alias": "position",
                "type": "text",
                "value": null
            },
            "email": {
                "id": 6,
                "group": "core",
                "label": "Email",
                "alias": "email",
                "type": "email",
                "value": null
            },
            "mobile": {
                "id": 7,
                "group": "core",
                "label": "Mobile",
                "alias": "mobile",
                "type": "tel",
                "value": null
            },
            "phone": {
                "id": 8,
                "group": "core",
                "label": "Phone",
                "alias": "phone",
                "type": "tel",
                "value": null
            },
            "points": {
                "id": 9,
                "group": "core",
                "label": "Points",
                "alias": "points",
                "type": "number",
                "value": null
            },
            "fax": {
                "id": 10,
                "group": "core",
                "label": "Fax",
                "alias": "fax",
                "type": "tel",
                "value": null
            },
            "address1": {
                "id": 11,
                "group": "core",
                "label": "Address Line 1",
                "alias": "address1",
                "type": "text",
                "value": null
            },
            "address2": {
                "id": 12,
                "group": "core",
                "label": "Address Line 2",
                "alias": "address2",
                "type": "text",
                "value": null
            },
            "city": {
                "id": 13,
                "group": "core",
                "label": "City",
                "alias": "city",
                "type": "text",
                "value": null
            },
            "state": {
                "id": 14,
                "group": "core",
                "label": "State",
                "alias": "state",
                "type": "region",
                "value": null
            },
            "zipcode": {
                "id": 15,
                "group": "core",
                "label": "Zip Code",
                "alias": "zipcode",
                "type": "text",
                "value": null
            },
            "country": {
                "id": 16,
                "group": "core",
                "label": "Country",
                "alias": "country",
                "type": "country",
                "value": null
            },
            "preferred_locale": {
                "id": 17,
                "group": "core",
                "label": "Preferred Locale",
                "alias": "preferred_locale",
                "type": "locale",
                "value": null
            },
            "timezone": {
                "id": 18,
                "group": "core",
                "label": "mautic.lead.field.timezone",
                "alias": "timezone",
                "type": "timezone",
                "value": null
            },
            "last_active": {
                "id": 19,
                "group": "core",
                "label": "Date Last Active",
                "alias": "last_active",
                "type": "datetime",
                "value": null
            },
            "attribution_date": {
                "id": 20,
                "group": "core",
                "label": "Attribution Date",
                "alias": "attribution_date",
                "type": "datetime",
                "value": null
            },
            "attribution": {
                "id": 21,
                "group": "core",
                "label": "Attribution",
                "alias": "attribution",
                "type": "number",
                "value": null
            },
            "website": {
                "id": 22,
                "group": "core",
                "label": "Website",
                "alias": "website",
                "type": "url",
                "value": null
            }
        },
        "social": {
            "facebook": {
                "id": 23,
                "group": "social",
                "label": "Facebook",
                "alias": "facebook",
                "type": "text",
                "value": null
            },
            "foursquare": {
                "id": 24,
                "group": "social",
                "label": "Foursquare",
                "alias": "foursquare",
                "type": "text",
                "value": null
            },
            "googleplus": {
                "id": 25,
                "group": "social",
                "label": "Google+",
                "alias": "googleplus",
                "type": "text",
                "value": null
            },
            "instagram": {
                "id": 26,
                "group": "social",
                "label": "Instagram",
                "alias": "instagram",
                "type": "text",
                "value": null
            },
            "linkedin": {
                "id": 27,
                "group": "social",
                "label": "LinkedIn",
                "alias": "linkedin",
                "type": "text",
                "value": null
            },
            "skype": {
                "id": 28,
                "group": "social",
                "label": "Skype",
                "alias": "skype",
                "type": "text",
                "value": null
            },
            "twitter": {
                "id": 29,
                "group": "social",
                "label": "Twitter",
                "alias": "twitter",
                "type": "text",
                "value": null
            }
        },
        "personal": [],
        "professional": [],
        "all": {
            "id": 1277,
            "title": null,
            "firstname": null,
            "lastname": null,
            "company": null,
            "position": null,
            "email": null,
            "mobile": null,
            "phone": null,
            "points": null,
            "fax": null,
            "address1": null,
            "address2": null,
            "city": null,
            "state": null,
            "zipcode": null,
            "country": null,
            "preferred_locale": null,
            "timezone": null,
            "last_active": null,
            "attribution_date": null,
            "attribution": null,
            "website": null,
            "facebook": null,
            "foursquare": null,
            "googleplus": null,
            "instagram": null,
            "linkedin": null,
            "skype": null,
            "twitter": null
        }
    },
    "lastActive": null,
    "owner": null,
    "ipAddresses": [],
    "tags": [],
    "utmtags": null,
    "stage": null,
    "dateIdentified": null,
    "preferredProfileImage": null,
    "doNotContact": [],
    "frequencyRules": []
    }
    }

This is the response of GET contacts API i guess so i am confused why i am getting GET API response while doing POST request to contact API please help me to figure out this issue.

Aditya
  • 9
  • 1
  • 6
  • Can you please specify what is the problem? You are not getting GET response on POST request. What does it even mean? You are just getting the newly created contact in the response. From that you can check that all the values were stored properly and you'll also get the contact ID which may be useful for updates in the future. – John Linhart Jun 20 '19 at 09:39

1 Answers1

0

enter image description here

As you can see in the picture, when you create a new contact along with response status code it returns the properties as well which are similar to "Get Contact" request(as you will get when you get contact by id). So I think as long as your new contact is being created in mautic you shouldn't be worried.

Mayank Tiwari
  • 919
  • 1
  • 6
  • 13