Home > Uncategorized > Create a Lead in Base using C# @getbase

Create a Lead in Base using C# @getbase

base-crm

Base is a CRM system that offers an API to allow you to automatically track your customers / or leads. Here’s a quick code example of how to call the Base API in c#, I’ve removed the username / password values.

var lead = new BaseCRM.Lead
{
data = new Data
{
first_name = “Joe”,
last_name = “bloggs”,
email = “joe.bloggs@gmail.com”,
website = “www.webtropy.com”,
address = new Address { },
custom_fields = new CustomFields { },
tags = new List<string>()
}
};
var strJson = JavascriptSerialize(lead);

WebClient wc = new WebClient();
try
{
var strSearch = “https://api.getbase.com/v2/leads&#8221;;
wc.Headers[HttpRequestHeader.Accept] = “application/json”;
wc.Headers[HttpRequestHeader.ContentType] = “application/json”;
wc.Headers[HttpRequestHeader.UserAgent] = “Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36”;
wc.Headers.Add(“Authorization”, “Bearer {{YOUR API KEY}}”);
var strSearchResponse = wc.UploadString(strSearch,strJson);
}
catch (WebException exception)
{
string responseText;

var responseStream = exception.Response.GetResponseStream();

if (responseStream != null)
{
using (var reader = new StreamReader(responseStream))
{
responseText = reader.ReadToEnd();
}
}
}

The code above creates a new “Lead” in the Base CRM system, it requires a few helper methods as follows;

public static T JavascriptDeserialize<T>(string json)
{
var jsSerializer = new JavaScriptSerializer { MaxJsonLength = Int32.MaxValue };
return jsSerializer.Deserialize<T>(json);
}

public static string JavascriptSerialize<T>(T obj)
{
var jsSerializer = new JavaScriptSerializer { MaxJsonLength = Int32.MaxValue };
return jsSerializer.Serialize(obj);
}

and the object model;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Yelper.BaseCRM
{
public class Address
{
public string line1 { get; set; }
public string city { get; set; }
public string postal_code { get; set; }
public string state { get; set; }
public string country { get; set; }
}

public class CustomFields
{
public string known_via { get; set; }
}

public class Data
{
public string first_name { get; set; }
public string last_name { get; set; }
public string organization_name { get; set; }
public int source_id { get; set; }
public string title { get; set; }
public string description { get; set; }
public string industry { get; set; }
public string website { get; set; }
public string email { get; set; }
public string phone { get; set; }
public string mobile { get; set; }
public string fax { get; set; }
public string twitter { get; set; }
public string facebook { get; set; }
public string linkedin { get; set; }
public string skype { get; set; }
public Address address { get; set; }
public List<string> tags { get; set; }
public CustomFields custom_fields { get; set; }
}

public class Lead
{
public Data data { get; set; }
}
}

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: