jpetrucciani / hubspot3

python3.6+ hubspot client based on hapipy, but modified to use the newer endpoints and non-legacy python
MIT License
147 stars 73 forks source link

Forms API requires URL Encoding #31

Closed advance512 closed 5 years ago

advance512 commented 5 years ago

To get the Forms API submission to work, I had to do the following:

        dataToSubmit = dict(data)
        dataToSubmit['hs_context'] = json.dumps(context)

        # Build the request body, URL encoded
        urlEncodedData = urlencode(dataToSubmit, quote_via=quote_plus)

        formsClient.submit_form(
            portal_id=config.hubspot.HUBSPOT_PORTAL_ID,
            form_guid=formGuid,
            data=urlEncodedData,
        )

I think support for URL Encoding the data makes sense here, this should not be required to be done outside of the class itself. Without this, form submission fails.

jpetrucciani commented 5 years ago

Makes sense - I'll take a look into this

jpetrucciani commented 5 years ago

I've got this added into the latest release 3.2.9 as well - you can now pass the data kwarg directly into that method, and it will URL Encode automatically for you. I've also added the option to pass context as a dict in the kwargs, which will automatically json.dumps the contents and add them to the data before URL Encoding.

This simplifies the above into the following:

form_submission_client.submit_form(
    portal_id=config.hubspot.HUBSPOT_PORTAL_ID,
    form_guid=form_guid,
    data=data,          # as a dict, will be url encoded for you
    context=context     # as a dict, will be json.dumps'd and added into data
)

Let me know if you have any issues with that! I'll close the issue, but feel free to reopen - Thanks for the ideas!

advance512 commented 5 years ago

Your quick response here is laudable. Awesome job!! Thank you.