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 it this way:
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’m not able to understand how I do it using my postgres registration method.
Follows my py views.:
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 that strength?.
is well anyway, thank you very much for the help guy I managed to do the POST, and I made an improvement that I found pertinent
url ="https://www.rdstation.com.br/api/1.3/conversions"
 headers = {'Content-type': 'application/json'}
 data = {'name':lead.name,
 'email':lead.email,
 'identificador': 'form-landing-posp',
 'token_rdstation': 'meu_token'}
 r = requests.post(url, json=data, headers=headers)
 r.json()
– Raphael Melo De Lima
@Raphaelmelodelima Spend
headers
is useless and reductive, when using the parameterjson=
in therequests.post()
thecontent-type
is automatically set toapplication/json
without having to specify separately, so you should remove this parameter and do as in my reply.– nosklo