Integrate RDStation with Django + Python to send lead

0

Good morning guys, I have a problem:

I have an LP that has to save the lead in the Postgres database and automatically send that lead to the RD platform using their API.

Using the curl I do as follows:

curl -v \
      -X POST \
      -H "Content-type: application/json" \
      -d '{ "email": "[email protected]",
            "name": "raphael melo de lima", 
            "identificador": "form-landing-posp", 
            "token_rdstation": "meu_token_do_rd" 
          }' \
      'https://www.rdstation.com.br/api/1.3/conversions'

So I can send the respective lead, but I can not figure out how I can do this using my registration method in postgres.

Follow my views.py :

from django.shortcuts import render, redirect
from .models import *
from .forms import *
from django.http import JsonResponse
import json

def create_lead(request):       
    form = LeadForm(request.POST or None)

    if form.is_valid():
        data = form.cleaned_data
        lead = Lead.objects.filter(email=data['email']).first()

        if lead:
            request.session['lead_id'] = lead.id
            return redirect('registrations:videos_list')

        lead = form.save()
        request.session['lead_id'] = lead.id
        return redirect('registrations:videos_list')

    return render(request, 'index.html', {'form':form})

def videos_list(request):

    if 'lead_id' in request.session:
        lead = Lead.objects.get(pk=request.session['lead_id'])


        return render(request, 'videos-list.html')

    return redirect('registrations:create_lead')

Can anyone give me this strength?

    
asked by anonymous 26.09.2018 / 16:12

1 answer

2

Using requests :

import requests

requests.post(
    'https://www.rdstation.com.br/api/1.3/conversions',
    json={
        'email': '[email protected]',
        'name': 'raphael melo de lima',
        'identificador': 'form-landing-posp',
        'token_rdstatuion': "meu_token_do_rd",
    }
)

Then just put this in your code, with the variables you want to send .... data['email'] and data['name'] for example?

    
26.09.2018 / 19:38