Re: Marketo leads are not being saved

Anonymous
Not applicable

Marketo leads are not being saved

HI Team,

               I am using SOAP API of Marketo for getting access token and to submit leads , the response from Marketo is Status code 200 response OK which means leads are being saved successfully, but i cannot find thees saved leads into my Marketo leads board. what might be the cause?

Any help will be appreciated.

Thanks

5 REPLIES 5
Anonymous
Not applicable

Re: Marketo leads are not being saved

You would need to show the code and methods used.

Anonymous
Not applicable

Re: Marketo leads are not being saved

for getting access token

string GetAccessToken()

        {

            string accessToken = "";

            string identityUrl=MvcApplication4.Properties.Settings.Default.MarketoIdentityUrl;

            string clientID = MvcApplication4.Properties.Settings.Default.MarketoClientID; // Get from Marketo UI

            string clientSecret = MvcApplication4.Properties.Settings.Default.MarketoSecretKey; // Get from Marketo UI

            string url = string.Format("{0}?grant_type=client_credentials&client_id={1}&client_secret={2}",identityUrl,clientID,clientSecret);

            Uri getUri = new Uri(url);

            using (var httpClient = new HttpClient())

            {

                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var response = httpClient.GetAsync(getUri).Result;

                if (response.IsSuccessStatusCode)

                {

                    var result = response.Content.ReadAsStringAsync().Result;

                    var deserializer = new JavaScriptSerializer();

                    var someObject = deserializer.DeserializeObject(result);

                    Dictionary<string, object> data = (Dictionary<string, object>)someObject;

                    accessToken = data["access_token"].ToString();

                }

            }

            return accessToken;

        }

And for saving leads

public bool CreateLead(ContactUsForm model)

        {

            string accessToken = GetAccessToken();

            string marketoApiUrl=MvcApplication4.Properties.Settings.Default.MarketoRestApiUrl;

            string jsonObject=CreateJsonObject(model);

            if (accessToken.Length > 0)

            {

                using (var httpClient = new HttpClient())

                {

                    httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("access_token",accessToken);

                    var response = httpClient.PostAsJsonAsync(marketoApiUrl + "/v1/leads.json", jsonObject).Result;

                    if (response.IsSuccessStatusCode)

                    {

                        return true;

                    }

                }

            }

            return false;

        }

For creating Json object

string CreateJsonObject(ContactUsForm model)

        {

            string json = "";

            Dictionary<string, object> jsonObject = new Dictionary<string, object>();

            jsonObject.Add("action", "createOrUpdate");

            jsonObject.Add("lookupField", "email");

            Dictionary<string, string> dataObject = new Dictionary<string, string>();

            dataObject.Add("email", model.Email);

            dataObject.Add("firstName", model.FirstName);

            dataObject.Add("lastName", model.LastName);

            dataObject.Add("leadSource", model.LeadSource);

            dataObject.Add("leadSourceDetail", model.LeadSourceDetails);

            dataObject.Add("region", model.Region);

            dataObject.Add("business_unit", "testunit");

            dataObject.Add("originalReferrer", model.ReferringURL);

            jsonObject.Add("input", dataObject);

            json = (new JavaScriptSerializer()).Serialize(jsonObject);

            return json;

        }

Thanks

Kenny_Elkington
Marketo Employee

Re: Marketo leads are not being saved

Aradhana,  It doesn't look like you're checking for nested statuses in the result array to determine the outcome of individual lead inputs.  Here is an example of an upsert operation where a lead record was skipped becuase of a missing lookupfield value:

{

  "requestId" : "12697#14e88d4c3da",

  "result" : [

  {

  "status" : "skipped",

  "reasons" : [

  {

  "code" : "1003",

  "message" : "Value for requried field 'id' not specified"

  }

  ]

  }

  ],

  "success" : true

}

Each lead in your input will succeed or fail individual, so you need to check the status of each object in the result array individual, and its code/message to determine success/failure and the reason for failed.  If you can give an example of the raw result of one of your sync requests, then we can probably provide better guidance.

Steven_Vanderb3
Marketo Employee

Re: Marketo leads are not being saved

Aradhana Sharma​ in addition to the request XML, the response XML would also be useful in figuring out what's happening.

Anonymous
Not applicable

Re: Marketo leads are not being saved

Request xml

<root><action>createOrUpdate</action><lookupField>email</lookupField><input><email>test.21@test.com</email><firstName>test</firstName><lastName>21</lastName><leadSource>website</leadSource><leadSourceDetail>monotype.com</leadSourceDetail><region>region</region><business_unit>testunit</business_unit><originalReferrer>www.website.com</originalReferrer></input></root>

and response

{StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:

{

  Connection: keep-alive

  Date: Mon, 13 Jul 2015 09:03:15 GMT

  Set-Cookie: BIGipServerab-restapi_https=587792650.47873.0000; path=/

  Server: nginx

  Content-Length: 114

  Content-Type: application/json; charset=UTF-8

}}

Thanks