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…

1 Like

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.

1 Like

I get that you guys are trying to help, but you are speaking french and asking me to read french when you say read the documentation, set up SDK and API connection, and pass header ‘X-Keap-API-Key’. What I’d really appreciate… what I think most regular everyday Keap customers considering or contemplating using KEAP API would appreciate is some basic step-by-step instruction and support on how exactly to make a connection using the different methods, explaining the cons and benefits or best usage of each method, and some basic examples of common request for each verb of put, get, post, and delete in each language or at minimum the most used language. That would at least serve as a launching point or a starter template that can be manipulated or changed to meet a user’s need.

In my situation, I have a “post to HTTP” step in a Keap automation that takes Keap data and posts it to a MySQL server using PHP which also generates a random $RefCode. It’s that $RefCode that I would like to have posted back to the Keap record using the $OwnEml and $VehVin variables as the verifying fields.

So you can see where I need to understand if this can be done as part of the same PHP code and if so how to connect, verify the record to post to, and then post the $Refcode with what I believe would need to be PHP converted to JSON.

So, I guess that is all the help this forum can offer? If so, wow… Thanks.

Hi, @Maria_Jimenez ,

Pav and I both are joe schmoe citizens like you. We do not work for keap.

The assistance we provide is often based on how busy our businesses are at the time.

That said, your question contained a LOT of technical terms and phrases that was (I’m sure by design) indicative of someone that understood what they were asking about. Now, it sounds more like you formed an expectation of what help you’d get but given your issue that you describe and the fact you later said it’s over your head, you really need to hire someone to help you because it involves a lot more than someone that isn’t a developer would likely be able to deal with.

I’m sorry that your expectations were not met but as I said, we can only do so much in what extra time we can offer.

1 Like

Well, it seems you understood that I understood the concept of what I was trying to accomplish but still only felt you could offer your time to help from your busy schedules if I was willing to pay. I’m glad there are others in this forum who understand the true meaning of what a COMMUNITY FORUM is supposed to do and be all about.

When Keap customers (real joe schmoes) like me, (not developers) come to forums like this with specific questions and at least show some semblance of comprehension. You would THINK that the moderators or “Solution Experts” would be willing to take the time on small things like mine to point out the nuances or at minimum provide some guidance. Not stand around like a lifeguard at a pool saying, “I’ll save you if I have time or you could pay me to do it.”

Now as I said, I’m glad there are others in this forum with a true attitude toward help. This person contacted me, we had actually made contact before, he saw my post/question read the thread, and reached out. Ask if I still needed help and ask if I had time for a Zoom meeting… (ON A SUNDAY!). We got together, he got what he needed and basically put the code together right in front of me. Could he have used my patchwork of code? Probably with more work, but he used his understanding of the API and his own, shall we say customized environment to set things up and make it happen. In an hour and a half, with some simple explanation and friendly conversation, HE HELPED! . I even offered to pay him something for his time and effort and he declined, saying, “this was something really quite simple and I’m just glad I could help.”

With that being said, there are good people in this forum willing to help, you just have to beat the grass a bit to clear the snakes and hope you can come acrossed someone like I did. I wish I could provide his info, but as he’s stated it was help he was glad he could offer and wasn’t really doing to find more work. I’m most truly grateful for his assistance.

1 Like

@Maria_Jimenez - I must say that this topic you have raised has been interesting and thoughtful to read.

Your Replies

I am going to say a few things from a developer point of view, so please do not take this wrong way as I see things differently. John may have additional points of view but usually we are on the same wavelengths.

The original post you raised on April 12th got me thinking that you were a developer, in which in turn I thought you would understand about the API documentation. When you did not come back straight away we guessed you understood things. Not everyone replies back to our answers, so we assume all is okay, unless they found another solution.

On June 20th, two months later from your originally post you came back to us. Although I must admit that Keap’s API documentation was not great at the very beginning, and sometimes you had to piece it all together. It has got better over the years, but it could still do with some improvement. I think from Keap’s point of view is if you are a Developer then you should understand all the Development jargon. I have seen other API documentation over the years that was more vague than Keap’s and had to search for answers.

You mentioned the following “…what I think most regular everyday Keap customers considering or contemplating using KEAP API…”. The vast majority of Keap’s customers are not developers, and would have no idea about the API. Their first port of call would be to use Zapier, which makes it easier to set up integrations. Unfortunately Zapier is limited to what it can do, so if customers need to do more then the API comes into play. I am sure @John_Borelli can confirm that when he deals with his clients that most would have no clue about the API, and they get him to do all the necessary technical work. Well that happens in my case.

In regards to the API Connection Methods, this is where it can become a hot issue. Each has their Pros and Cons, so all of us could end up arguing which is the best to use. Keap want developers to use the OAuth API Connection method for improved security. Which I agree on, but unfortunately it makes harder to develop against because you have to deal with the storage and retrieval of the Access and Refresh Tokens. That makes simple scripts become more complex then they need to be. Only last year Personal Access Tokens came out, which is like a halfway house having a permanent key again. In my opinion they could have extended the Legacy API Key with additional options. Anyway, you get the usual “its what the industry uses” response.

About Us

Years ago there was far more people including developers in the forum helping out each other. But as time has gone past, some have left due to various reasons. John and myself are not as active as we use to be, because we are constantly busy.

When we reply we give pointers to people on what to do, and even give out examples if need be. Usually people are happy with the responses. When it comes to scripting questions then we have to balance things. If this forum had people constantly asking for scripting help, we would be spending most of the week trying to answer, but that is all free advice. Unfortunately it does not pay our bills.

I see that you had a Good Samaritan who spotted your recent post and helped you out, then I applaud his effort in helping you out. It also tells us that other people are watching the forum and can give out help when needed.

Anyway, I am glad it is now sorted out for you. :slight_smile:

Demo API Script

One more thing, I just want to show you and other people something that can be achieved using the Legacy XML-RPC and API Key. This code below is a simple PHP script that sets the Current Date and Time in the Contact Record - “Job Title” field for Contact Id “123”. The API Connection needs to be set accordingly.

The point of this script is to show that there is no need for the SDK nor to have OAuth. It can be adjusted for simple processing needs.

<?php

    // Example PHP script to update the Contact Job Title field via the XML-RPC using the Legacy API Encrypted Key.

    ini_set("display_errors", 1);
    ini_set("display_startup_errors", 1);
    error_reporting(E_ALL);

    // API Connection.
    $app = "**ABCDEF**";    // Your Keap Account Name.
    $key = "**ABCDEF**";    // Your API Encrypted Key.

    // Contact Details To Update.
    $contact = 123;                  // Contact Id.
    $field   = "JobTitle";           // Contact Field to update.
    $value   = date("Y-m-d H:i:s");  // Contact Value to set.

    // API Request.
    $request = "<?xml version='1.0' encoding='UTF-8'?>
        <methodCall>
            <methodName>ContactService.update</methodName>
            <params>
                <param>
                    <value><string>$key</string></value>
                </param>
                <param>
                    <value><int>$contact</int></value>
                </param>
                <param>
                    <value>
                        <struct>
                            <member>
                                <name>$field</name>
                                <value>
                                    <string>$value</string>
                                </value>
                            </member>                
                        </struct>
                    </value>
                </param>
            </params>
        </methodCall>";

    $url       = "https://$app.infusionsoft.com:443/api/xmlrpc";
    $headers   = [ "Content-Type: text/xml", "Accept-Charset: UTF-8,ISO-8859-1,US-ASCII", "Expect:" ];
    $useragent = "XML-RPC Example";

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, $useragent);    
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_ENCODING, "");
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_SSLVERSION, 0);
    
    $output = curl_exec($ch);
    
    curl_close($ch);

    var_dump($output);```