+ Start a Discussion
Alejandro ValcarcelAlejandro Valcarcel 

json response after sf.Create.contact

Hi, I'm new to SF, Python and Flask. Wich are the tools I'm using to build up a little web UI for registering (creating anew contact on SF). I found Simple-Salesforce and works pretty well for me. So, right now I have this code wich is working perfectly so far:
# User Registration
@app.route('/register', methods=['GET', 'POST'])
def register():
    form = RegisterForm(request.form)
    if request.method == 'POST' and form.validate():
        FirstName = request.form['FirstName']
        LastName = request.form['LastName']
        AccountId = request.form['AccountId']
        Birthdate = request.form['Birthdate']
        #password = sha256_crypt.encrypt(str(form.password.data))
        Home_Endpoint__c = request.form['Home_Endpoint__c']

        # Execute query
        sf.Contact.create({'LastName':LastName,'FirstName':FirstName,'AccountId':AccountId, 'Birthdate':Birthdate, 'Home_Endpoint__c':Home_Endpoint__c, 'Test_User__c':1 })
        flash('You are now registered', 'success')

    return render_template('register.html', form=form)

What I need is to catch/read the SF Dictionary JSON response with the new created Id as shown on the simple-salesforce examples section:
Record Management

To create a new ‘Contact’ in Salesforce:


This will return a dictionary such as {u'errors': [], u'id': u'003e0000003GuNXAA0', u'success': True}
So I can keep working with the new registered member on other further processes.

I will appreciate if someone gives me a hand on this.
Hello Alejandro,

The syntax for the callback function is:
function callback(Error error, Array results, Object event) { // ... }
For more details, please refer to Salesforce documentation:

If it helps you, please mark it as best answer.

Alejandro ValcarcelAlejandro Valcarcel

You are suggesting a JS function but I was looking for a Python code solution. Fortunately I already solved this. Thank you anyway.