Get username and password of a contact using REST

Hi,
I want to get a Contact’s Username and password by using REST API.
I am following this URL: Keap REST API
to get details of a contact .
But I am not getting the Username and password.
Check Attachment .

GET /contacts/{id}
At this request there are option parameter, “optional_properties”


Please advise how to get that.

Hi @Melodie_moore,

The available fields appear to be very limited as REST is still being built out. I don’t know of a current way to retrieve username and password with REST. You could certainly do it with the current api or the isdk though.

1 Like

Thank you.
I believe it could be retrieve by REST API.
Anyways to become confirm by the API developers whether it is possible or not ?

Hi @Melodie_moore, at this time we don’t have any plans to support those two fields in the REST API. As @John_Borelli mentioned, you can still get and set them through XML-RPC.

@Nicholas_Trecina
Thank you for quick response.
My System has been developed using REST. The Authentication (Tokens) are also generating using REST.
So, if I go for XML-RPC or SDK, the Authentication might conflict, right ?

@Melodie_moore,

If you use the API (not isdk although there is an OAuth version of the isdk as well) then you would be able to use the exact same OAuth token for both api and REST calls.

May use same “OAuth token” for REST and isdk?
Because ISDK seems good to me than XML-RPC ?
But, I want to avoid the " OAuth token " conflict.

There is a new version of the isdk and also a current version of the api (available on github) that both use oauth for authentication. The same token you are getting and using for REST can be used for oauth access with the others

Great. So both Refresh Token and Access Token could be use for both REST and isdk, right ?

Correct, the OAuth flow (using a refresh and access token) will work for both REST and XML-RPC APIs. The PHP SDK supports using both APIs as well as handles the OAuth flow for you.

Correct. The access token just manages access not api versions. Using OAuth with any version will validly be able to use the same tokens.

I have tried to use the Access token and Refresh token received from the Rest API in the php sdk. But unfortunately I am getting token expiration exception. I am describing below what I have tried so far -

  1. I have fetched the access token and the refresh token from the Rest API call.
  2. I have created a token object and assigned those values in that token object.
  3. Then I have tried to call a function of the sdk but it is saying me that my token is expired.
  4. Although the Rest API is still using the same Access token.

Here I am providing my code

<?php
    if(empty(session_id())) session_start();

    require_once 'vendor/autoload.php';
    include('db_conn.php');

    $last_tokens_sql = "SELECT * FROM ********* ORDER BY id DESC LIMIT 1";

    $last_tokens = $conn->query($last_tokens_sql);
    if ($last_tokens->num_rows > 0) {
        // output data of each row
        while($row = $last_tokens->fetch_assoc()) {

        $extraInfo = array(
                               'token_type' => 'bearer',
                               'scope' => 'full|**************'
                          );

        $token = new \Infusionsoft\Token();
        $token->accessToken = $row['access_token'];
        $token->refreshToken = $row['refresh_token'];
        $token->endOfLife = 86400;
        $token->extraInfo = $extraInfo;

    }
} else {
        echo "0 results";
}
$conn->close();


$infusionsoft = new \Infusionsoft\Infusionsoft(array(
    'clientId'     => '***************************',
    'clientSecret' => '****************',
    'redirectUri'  => '************************',
)); 

$infusionsoft->setToken($token); 

if($infusionsoft->isTokenExpired()){
    echo '<a href="' . $infusionsoft->getAuthorizationUrl() . '">Click here to authorize</a>';
} else {
    // Save the serialized token to the current session for subsequent requests
    $_SESSION['token'] = serialize($infusionsoft->getToken());

    $email = '*********************';
    $selectedFields = array('FirstName','LastName','Email','Username','Password');
    // MAKE INFUSIONSOFT REQUEST
    $test = $infusionsoft->contacts()->findByEmail($email, $selectedFields);
    print "<pre>";print_r($test);exit;
}

Every time I am shown the url “Click here to authorize”

Please advice how I can overcome this anomaly…Thanks in advance.

Another thing -
Please let me know if I can upload any image?
Thanks.

@Melodie_moore,

Here is what I use to authorize with but this is meant to be a one time authorize and then tokens are only managed from the database. This is NOT meant to be run every time an application/program is run. Notice that the ‘code’ parameter is used to mitigate what stage of the OAuth process the program is managing. Also, I’m not a big fan of combining sessions and database calls as it creates confusion as to what your real token values are. Again, this is the OAuth process and NOT how you use the access token. As to the refresh token, that is normally used in a refresh cycle separate from the use of the access token:

require(“OAuth2-iSDK/src/isdk.php”);

$app = new iSDK();

if (!isset($_GET[‘code’])) {
$app->setClientId(CLIENT_ID);
$app->setSecret(CLIENT_SECRET);
$app->setRedirectURL(REDIRECT_URL . REDIRECT_FILENAME);

echo "<p>Click the link below to allow access to your Infusionsoft application.</p>";
echo '<a href="' . $app->getAuthorizationURL() . '">Authorize My Application</a>';

} else {
$app->setClientId(CLIENT_ID);
$app->setSecret(CLIENT_SECRET);
$app->setRedirectURL(REDIRECT_URL . REDIRECT_FILENAME);
$auth=null;
$auth=$app->authorize($_GET[‘code’]);
$refresh=$app->refreshAccessToken();
echo $refresh;
}

What are you attempting to do with what you’ve posted? There are stages in OAuth and the steps you are using would not be used in the end application. So is this just your working on the “I need to get a new token” method or is this meant to be what you envision as part of the regular app process?

I keep saying I’m going to do a video to explain all this, I just need to buckle down and do it.

Hello,
I have somehow figured out the token issue. Now it is working like a charm. Thank you very much for you cooperation.

Though I am stuck with a new problem now. I want to add social data (Facebook, Twitter etc.). But unfortunately I can not find any function for doing this in php-sdk or Rest API. Please advice me how can I add social data of a contact.

Thanks in advance.

When you say php-sdk, I’m not sure at this point if we’re referring to the legacy or current api…you cannot yet do this with REST. The approach will still be the same with either api though. You’ll need to use the data object to write to the SocialAccount table just as you would write to any table but with the correct fields (see image)

Thank you for your quick reply.

Yes I have found your table definition. But I can not find any function for adding Social data in your documentation here (xml-rpc - Keap Developer Portal).

Please advice me which function I can use to insert Social Data.

Thank you.

Use the data object:
https://developer.infusionsoft.com/docs/xml-rpc/#data-create-a-record

Something like:
$app->dsAdd(‘SocialAccount’,array(‘AccountName’=>‘Facebook’,‘AccountType’=>‘Social’,‘ContactId’=>12345));

Thank you very much.

I have used this function which is returning me an ID, it is working well.

  1. So I have created a new record of a particular contact right?
  2. How can I put the value of the AccountName? I mean how can I add the Facebook link of that contact?

Let me give an example -
Suppose I have created a contact with following values using $infusionsoft->contacts()->add($data) -

FirstName : John
LastName : Doe
Email : john@doe.com
Username : john_doe
Password : 123456

Now I want to add this contacts Facebook URL in the Facebook field like the following -

Facebook : ‘Redirecting...

and also will need to retrieve it. How and by using which function I can do it?

Hello,

I am failing to add my contacts Facebook id even after relentless trying. Please give me some direction so that I can overcome this obstacle.

Thanks in advance.