# Problem connecting my script through the API to my account

**URL:** <https://integration.keap.com/t/problem-connecting-my-script-through-the-api-to-my-account/621>\
**Category:** API Q&A\
**Created:** [May 26, 2017, 9:26pm UTC](https://integration.keap.com/t/problem-connecting-my-script-through-the-api-to-my-account/621 "2017-05-26T21:26:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Customer\_Service](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@Customer\_Service](https://integration.keap.com/u/Customer_Service)\
**Post date:** [May 26, 2017, 9:26pm UTC](https://integration.keap.com/t/problem-connecting-my-script-through-the-api-to-my-account/621/1 "2017-05-26T21:26:02Z")

</div>

I’m using a command line php script (from [API Helper Libraries - Keap Developer Portal](https://developer.infusionsoft.com/resources/helper-libraries/) ) on my machine and I’m trying to figure out the rest api. I did find the long ‘key’ for my “Application/Account” that I normally log into (https://-AppId-.infusionsoft.com) as that is what I want my script to connect to. I just want to write a simple data retrieval script (contacts list for now) to store in a file for analysis later. This script (with more print statements) keeps returning “401 Unathorized” with {“error”:“invalid client”}. My browser can use Infusionsoft “Application/Account” after logging in so how can I get a script (somehow using that API) to retrieve the same info?

---

<div class="post-metadata">

**Author:** ![Pav](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/pav/32/124_2.png) [@Pav](https://integration.keap.com/u/Pav)\
**Post date:** [May 26, 2017, 10:09pm UTC](https://integration.keap.com/t/problem-connecting-my-script-through-the-api-to-my-account/621/2 "2017-05-26T22:09:17Z")

</div>

The Legacy API Key cannot be use for REST API.  
You need to register a Developer Account to obtain OAuth Keys.

Visit this page to get started: [Get Started - Keap Developer Portal](https://developer.infusionsoft.com/get-started/)

If you want to still want to use the Legacy API key, you need to use the XML-RPC API functions instead.

[https://developer.infusionsoft.com/docs/xml-rpc/](https://developer.infusionsoft.com/docs/xml-rpc/)

---

<div class="post-metadata">

**Author:** ![Customer\_Service](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@Customer\_Service](https://integration.keap.com/u/Customer_Service)\
**Post date:** [May 31, 2017, 4:53pm UTC](https://integration.keap.com/t/problem-connecting-my-script-through-the-api-to-my-account/621/3 "2017-05-31T16:53:38Z")

</div>

I’m trying to use the “Encrypted Key” found on that Admin-\>Settings-\>Application page. I hope thats what you mean by Legacy API key.  
It looks like I need to send just that code (somewhere…) to get an “authorization code”. Is this the same as an “access token” or “code”(mentioned in the helper SDK)? Then I send this to yet another url (somewhere else…) to get a token back which I can then use to make api calls.  
Another issue, I’m trying to enter the “Encrypted Key” on a variety of “Try it” api calls and it just fails. There’s some popup window with an allow button and then it returns to the page without having filled in the token. Do these pages not work?  
Can someone please provide sample code? Given that I want to use the Legacy API key(I put this in the clientId field), what do I fill in for the “clientSecret” field? I need this thing to authorize and get the token(not using oauth) and then I can go about using the xmlrpc api.

---

<div class="post-metadata">

**Author:** ![Pav](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/pav/32/124_2.png) [@Pav](https://integration.keap.com/u/Pav)\
**Post date:** [May 31, 2017, 7:55pm UTC](https://integration.keap.com/t/problem-connecting-my-script-through-the-api-to-my-account/621/4 "2017-05-31T19:55:05Z")

</div>

The Encrypted Key is the Legacy API Key.

You will NOT be able to use the Encrypted Key with the Try It calls at all. You need to use the OAuth Access Token to be able to do that.

If you follow the Get Started link, you will need to create a Developer Account, and register an Application to obtain the initial keys.

The PHP SDK Helper Library has sample code in its instructions that show how to authorize your script:

> **[GitHub - infusionsoft/infusionsoft-php: PHP client library for the...](https://github.com/infusionsoft/infusionsoft-php)**
>
> PHP client library for the Infusionsoft API. Contribute to infusionsoft/infusionsoft-php development by creating an account on GitHub.

If you still want to use the Encrypted Key, then you can only use these XML-RPC API Functions.  
Then you do not have to worry about Client ID, Client Secret, Redirect URLs, Access Tokens and Refresh Tokens.

[https://developer.infusionsoft.com/docs/xml-rpc/](https://developer.infusionsoft.com/docs/xml-rpc/)
