4834 Invalid Ticket ID with Auth Tokens

4834 Invalid Ticket ID with Auth Tokens

I have been trying to make a short python script to inject leads into Zoho crm, and have been bumping into this 4834 error. Here is my code, could someone explain what I am doing wrong?





#!python2


import urllib
import urllib2   #get the python 2 web interface up in here
import json

def main():
    d = Lead( "<myemail>@gmail.com", "<mypassword>", "Marshall", "W3bS7@rtup", "Devin", "333-333-3333", "devin@webstartup.com", "www.webstartup.com", "<myAuthToken>")

    d.writeToZoho()

class Lead():

    def __init__(self, leadOwner, leadOwnerPassword, lastName, institution = "Unknown", firstName = "", phoneNumber = "", email = "", website = "", authToken = None):
        self.leadOwner = leadOwner
        self.leadOwnerPassword = leadOwnerPassword
        self.firstName = firstName
        self.lastName = lastName
        self.phoneNumber = phoneNumber
        self.email = email
        self.institution = institution
        self.website = website
        self.description = "SOURCE: Mimir Leads"
        self.xml = self._createXMLString()
        if authToken == None:
            self.authToken = self._getAuthToken()
        else:
            self.authToken = authToken


    def _createXMLString(self):
        xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
        xml += "<Leads>\n"
        xml += "<row no=\"1\">\n"
        xml += self._FLStringGen("Lead Owner", self.leadOwner)
        xml += self._FLStringGen("Company", self.institution)
        xml += self._FLStringGen("First Name", self.firstName)
        xml += self._FLStringGen("Last Name", self.lastName)
        xml += self._FLStringGen("Email", self.email)
        xml += self._FLStringGen("Phone", self.phoneNumber)
        xml += self._FLStringGen("Website", self.website)
        xml += self._FLStringGen("Description", self.description)
        xml += "</row>\n"
        xml += "</Leads>"

        return xml

    def _FLStringGen(self, flName, flValue):
        return "<FL val=\"" + flName + "\">" + flValue + "</FL>\n"

    def writeToZoho(self):
        url = "https://crm.zoho.com/crm/private/xml/Leads/insertRecords?newFormat=1&authtoke="+self.authToken+"&scope=crmap"

        #params = {'newFormat':1, 'authtoke':self.authToken, 'scope':'crmap', 'xmlData':self.xml}
        params = {'xmlData':self.xml}
        data = urllib.urlencode(params)
        request = urllib2.Request(url, data)
        response = urllib2.urlopen(request)
        print response.read()

    def getRecords(self):
        url = "https://crm.zoho.com/crm/private/xml/Leads/getRecords?authtoken=" + self.authToken + "&scope=crmapi"
        response = urllib2.urlopen(url)
        print response.read()

    def _getAuthToken(self):
        url = "https://accounts.zoho.com/apiauthtoken/nb/create?SCOPE=ZohoCRM/crmapi&EMAIL_ID="
        url += self.leadOwner + "&PASSWORD=" + self.leadOwnerPassword
        return (urllib2.urlopen(url)).read()



main()