Can you update custom fields with API in the same code used to "Post" to HTTPS in automation

I have set up an automation that contains a landing page form that collects customer profile data using basic and custom form fields. As part of this automation, I have created a “Send to HTTP Post” that takes this data, creates a RefCode, and submits it to a database table outside of Keap. Once completed, it sends me an email with the submitted data and the RefCode.

I am wondering if it is possible that while I have all this data in variables (more specifically, the email, vehicle id, and RefCode), can I add to the PHP an API that OAuth’s a request to find the customer profile in Keap using email and the custom field (Vehicle ID) and then update that profile with the RefCode so that it can later be available in Keap and can be presented to the customer after invoice payment for use as an access key to a 3rd Party Gateway link that will be sent via automated email after payment as part of the same automation.

My code to Send the HTTP Post is currently working fine… I’ve found some sample code for the OAuth and I saw a few samples of PHP from the Keap developer site that I think would be what’s needed to make it happen. I’m just not familiar enough with all the coding to bring all the PHP, OAuth ( and JSON, if needed) together or if it is even possible.

Some help and guidance would be great… I’m willing to learn and ultimately want to understand exactly the what, how, and why of everything that goes into my site and its process.

Willing to provide a sample of my HTTP post and other code on request when and if necessary…

Yes, you can do that, and many other things as well.

Now the problem you have got here is understanding how to put this all together. The old way (which you can still do today) would be to use the API Encrypted Key in your script. Now-a-days it is recommended that you use OAuth, which is more involved as you have a time limited Access Token that needs refreshing every so often. You would need scripts to make the authorisation request and updating of the tokens.

Check out John Borelli video about OAuth: Using OAuth2 and Infusionsoft API/REST - YouTube

Using the Software Development Kit (SDK) will save you time, as it makes it easier to communicate to the API via your script. You just need to read through the various documentation to understand what to do.

From what I am seeing the API Documentation only explains the SDK functions in the older XML-RPC documentation, and not the newer REST documentation. You need to look at the sample on the right and click the “PHP” button to see the SDK example.

Retrieving a Contact: xml-rpc - Keap Developer Portal

Updating a Contact: xml-rpc - Keap Developer Portal

Note, if you are updating a Custom Field you need to prefix the name with an underscore, eg: “_VehicleID”.

In the HTTP Post I recommend you past the Contact Id via the “~Contact.Id~” Merge Field.
That way you have the referring Contact, and you do not need to look up by their Email Address.

Once you get past the initial stages of setting up the SDK and API Connection, then it becomes easier to deal with the API. You just need to read the documentation and experiment to understand it.

Hope that gives you a start.

Hi, @Maria_Jimenez ,

So in addition to what @Pav has said here, there are also two additional methods of authentication available to you now, if oauth becomes too much to work out. Oauth has been a bit of a challenge for some which is why I did the video pav linked you to.

You now have personal access tokens and service access tokens. The downside here is that you have to use curl to the endpoints (I use postman to help build these and then create the code for functions automatically) and pass a header parameter named ‘X-Keap-API-Key’ with the personal or service token set as the value. This simplifies authentication and keeps you from having to work out the oauth work flow.

Then from there use the same authentication method in the methods pav has linked you to and you should be good.