Create a gist now

Instantly share code, notes, and snippets.

@eminetto /lambda.py Secret
Created Jan 4, 2017

What would you like to do?
import pycurl
from StringIO import StringIO
from urllib import urlencode
import json
def lambda_handler(event, context):
buffer = StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'https://api.hubapi.com/deals/v1/deal?hapikey=API_KEY_HUBSPOT')
c.setopt(c.WRITEFUNCTION, buffer.write)
c.setopt(c.HTTPHEADER, ['Content-type: application/json; Charset=UTF-8'])
parameters = {
'associations': {
'associatedCompanyIds' : [ ID_COMPANY ],
'associatedVids' : [ ID_USER ]
},
'portalId' : ID_PORTAL_HUBSPOT,
'properties' : [
{
'value' : 'Novo Contato Coderockr',
'name' : 'dealname'
},
{
'value' : '74c7ae28-364f-48ed-9a08-6e266cd3d282',
'name' : 'dealstage'
},
{
'value' : 'default',
'name' : 'pipeline'
},
{
'value' : 'ID_USER_HUBSPOT',
'name' : 'hubspot_owner_id'
},
{
'value' : event.get('name'),
'name' : 'name'
},
{
'value' : event.get('email'),
'name' : 'email'
},
{
'value' : event.get('company'),
'name' : 'company'
},
{
'value' : event.get('phone'),
'name' : 'phone'
},
{
'value' : event.get('phase'),
'name' : 'phase'
},
{
'value' : event.get('needs'),
'name' : 'needs'
},
{
'value' : event.get('features_description'),
'name' : 'features_description'
},
{
'value' : event.get('deadline'),
'name' : 'deadline'
},
{
'value' : event.get('budget'),
"name" : "budget"
},
{
'value' : event.get('description'),
'name' : 'description'
}
]
}
data = json.dumps(parameters)
c.setopt(c.POST, 1)
c.setopt(c.POSTFIELDS, data)
c.setopt(c.VERBOSE, 1)
c.perform()
c.close()
body = buffer.getvalue()
return {
'message' : 'OK'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment