Hi, from what I'm seeing, there are different endpoints for creating a new contact and a new action. Is it possible to create both with the same request? I'm using python. Here's what worked to create a contact:

new_contact = {"first_name": user.first_name, "last_name": "OPT web form",\
        "emails": [{ "type": "home", "value": user.email}], \
        "phones": [{ "type": "mobile", "value": user.phone}] }

    crm = requests.post("https://app.onepagecrm.com/api/v3/contacts", json=new_contact, auth=(app.config['ONEPAGECRM_ID'], app.config['ONEPAGECRM_PW']))

I then tried this, which still created the contact but (predictably) failed to create the action. I'm hoping it's not necessary to create the contact, get the contact id with another request, then create a new action.

 new_contact = {"first_name": user.first_name, "last_name": "OPT web form",\
        "emails": [{ "type": "home", "value": user.email}], \
        "phones": [{ "type": "mobile", "value": user.phone}], \
        "data": {
            "action":{"text":"Reply to new contact email",
            "date": datetime.now().strftime('%Y-%m-%d')}
            }
        }
    crm = requests.post("https://app.onepagecrm.com/api/v3/contacts", json=new_contact, auth=(app.config['ONEPAGECRM_ID'], app.config['ONEPAGECRM_PW']))

Hi dannypernik

Thanks for reaching out

I'm afraid, Contacts and Actions are 2 different restful resources unlike emails or phones which are Contact's properties, so, currently, it has to be done in two steps

Please let me know if you have any further questions
Sajed Almorsy

So then would it be the case that I need to create the new contact in a post request, then retrieve the new contact_id in a get request, then create the action for that contact in a post request? Will the data update quickly enough to get the contact_id immediately after creating the contact?

Hi dannypernik

When you create a contact with a POST request, the newly created contact (with its ID) is returned in the response already, so you can use the ID from the response to create the action.

So, you only need to make 2 POST requests to create the contact and then the action for that contact.
And you can make the second request (that creates the action) right after you get the contact ID from the response to the first POST request (that creates the contact), updates are immediately available.

Please let me know if you have any further questions
Sajed Almorsy

Ohh that makes too much sense smile thanks for your help!

Uploading...
Saving...
You have a post draft in progress. Click anywhere in this box to resume editing.