API3
axismatt at May 4th, 2020 06:03 — #1
In the Onepage CRM web application there is the ability to export contacts. https://help.onepagecrm.com/article/81-how-to-export-contacts-from-onepagecrm. Can this be done programmatically via API or Webhook?
victor at May 6th, 2020 11:39 — #2
Hi @axismatt!
Thanks for your question. Unfortunately, there is no option to do this via API or Webhook right now.
mlaplante at August 31st, 2023 19:14 — #3
Hi! We are 3 years later... is it available right now? How can I program a quick export of all my contacts with a specific status?
johnmag at September 1st, 2023 09:02 — #4
Hi @mlaplante,
Thanks for getting in touch.
Can I ask what your use case is here to help better understand the problem?
Would fetching contacts with specific status from the API work rather than an export for you?
A GET of contacts with a specific status would return the contact data, that you can then process any way you like, similar to an export.
See our docs on fetching contacts from the API here
There is no option to export contacts from the API and we have no plans to add this.
Please see our swagger docs for all of the available API endpoints.
Let me know if this works for you.
Kind regards,
John
mlaplante at September 1st, 2023 12:34 — #5
Hi thanks for answering, I really appreciate!
Here is my problem : I have a database of over 3000 clients. At hight season peak, about 300 clients of those 3000 can have the status "waiting for signature" at the same time. Created through Python, I can have a daily CSV of about 30 clients (people that we are waiting for their signature since more than a week) that might be found in this specific status . I want to do massive update and change the status for 'Rappel (remind) de signature' of those specific 30 clients at the same time. When I asked on the forum, I was thinking of exporting in a csv all clients with "Attente (waiting) de signature" status, compare the 2 csv and import back only those ones with status to change.
But i continued to test, and I am almost there. Instead, If I find a client with "Attente de signature" (waiting for) and NAS is the same from my csv and client infos (custom field), then i try to make the status update. here is my python code:
page = 1
per_page = 100 # Vous pouvez ajuster cette valeur en fonction de vos besoins
while True:
response = requests.get(url, params={'page': page, 'per_page': per_page}, auth=HTTPBasicAuth(user_id, api_key))
data = response.json()
try:
new_contacts = pd.DataFrame(data['data']['contacts']) # Accéder aux contacts via la clé 'data'
contacts_onepage = pd.concat([contacts_onepage, new_contacts], ignore_index=True)
except KeyError:
print("La clé 'contacts' n'est pas présente dans la réponse. Vérifiez la structure de la réponse.")
break
# Incrémenter la page pour passer à la suivante
page += 1
# Stopper la boucle si on a atteint 300 contacts ou plus
if len(contacts_onepage) >= 300:
break
contacts_onepage = contacts_onepage.head(300)
df_csv = pd.read_csv("C:/Users/User/Downloads/NAS.csv")
for , row in contactsonepage.iterrows():
contact_id = row['contact']['id'] # Accéder à l'ID du contact
contact_custom_fields = row['contact']['custom_fields'] # Accéder aux champs personnalisés
contact_nas = None
for field in contact_custom_fields:
if field['custom_field']['name'] == 'NAS':
contact_nas = field['value']
break
if contact_nas and contact_nas in df_csv['NAS'].values and row['contact']['status'] == 'Attente de signature':
payload = {
'contact_id': contact_id,
'last_name': row['contact']['last_name'],
'first_name' : 'Mange dlamour',
'status': 'Rappel de signature',
'partial': 'true'
}
response = requests.put(
f"https://app.onepagecrm.com/api/v3/contacts/{contact_id}.json",
auth=HTTPBasicAuth(user_id, api_key),
json=payload)
# Vérifier le code de statut de la réponse
if response.status_code == 200:
print(f"Statut mis à jour pour le contact avec l'ID {contact_id}")
else:
print(f"Échec de la mise à jour pour le contact avec l'ID {contact_id}")
print("Code d'erreur HTTP:", response.status_code)
print("Contenu de la réponse API:", response.content)
I am almost there. Status doesn't update, so I tried a random fisrt name, and first name update it self, so there something with status... I also tried 'status_id', it seams that 'Rappel de signature' has its personnal code but it still doesnt work.
If I may, I have a few other questions :
I understand that I can do only 100 request to not bust the server. 100 request per what ? Per hour? If so, is it possible to request only the clients with 'Attente de signature' ? As I have max 300 clients at that status at the same time, It would be acceptable to run the program 3 times in 3 hours to test my 'Attente de signature' clients 1 to 100, then 101 to 200 and 201 to 300.
Otherwise to sort the clients by status and make sure Attente de signature comes first (could be 'aaatentente de signature' ?
If it's only 100 requests at the time, why my code was able to seek through 300 clients?
Thanks a lot!!
mlaplante at September 1st, 2023 15:16 — #6
Got it !!
for status update : payload = {
'contact_id': contact_id,
'last_name': row['contact']['last_name'],
'first_name': 'Mange dlamour',
'status': [{
'id': '607394f4ccd15a61b437a713',
'status': 'Rappel de signature'
}],
'partial': 'true'
}
it needed to be define as an array! If I may ask another question : Over the 300 contact it seems to jump some contacts for no reason. I sorted my contacts by last_name. It jumped many clients and at the last 300's start with F... Ishoulb ba at C or D considering my 3000 clients...
vladimir at September 4th, 2023 17:30 — #7
Hi mlaplante!
If you need to fetch only 300 first records, you can do it without loops, manually by issuing the request 3 times:
response1 = requests.get(url, params={'page': 1, 'per_page': 100}, auth=HTTPBasicAuth(user_id, api_key))
response2 = requests.get(url, params={'page': 2, 'per_page': 100}, auth=HTTPBasicAuth(user_id, api_key))
response3 = requests.get(url, params={'page': 3, 'per_page': 100}, auth=HTTPBasicAuth(user_id, api_key))
Also you can put your condition into requests in order to get only contacts with status='Rappel de signature'
1. You fetch existing statuses from your account
statuses_response = requests.get('/api/v3/statuses', params={'page': 1, 'per_page': 100}, auth=HTTPBasicAuth(user_id, api_key))
2. The you find the status you want ('Rappel de signature' in your case) and add this condition to the main request
signature_reminder_status_id = statuses_response.find('Rappel de signature')['id'] # somehow you do it
url = "/api/v3/contacts?status_id=#{signature_reminder_status_id}"
response1 = requests.get(url, params={'page': 1, 'per_page': 100}, auth=HTTPBasicAuth(user_id, api_key))
response2 = requests.get(url, params={'page': 2, 'per_page': 100}, auth=HTTPBasicAuth(user_id, api_key))
response3 = requests.get(url, params={'page': 3, 'per_page': 100}, auth=HTTPBasicAuth(user_id, api_key))
So you'll get first 300 contacts with the status you want. I hope this could help you
Thank you,
Vladimir.
Powered by Discourse, best viewed with JavaScript enabled