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”
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.
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 ?
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.
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
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.
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 -
I have fetched the access token and the refresh token from the Rest API call.
I have created a token object and assigned those values in that token object.
Then I have tried to call a function of the sdk but it is saying me that my token is expired.
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.
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>';
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.
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)
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.