# Workflow: Migrate an API key integration to a private app

**URL:** <https://community.hubspot.com/t/workflow-migrate-an-api-key-integration-to-a-private-app/65954>\
**Category:** APIs & Integrations\
**Tags:** professional\
**Created:** [September 27, 2022, 11:29am UTC](https://community.hubspot.com/t/workflow-migrate-an-api-key-integration-to-a-private-app/65954 "2022-09-27T11:29:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LKlassen](https://avatars.discourse-cdn.com/v4/letter/l/f0a364/32.png) [@LKlassen](https://community.hubspot.com/u/LKlassen)\
**Post date:** [September 27, 2022, 11:29am UTC](https://community.hubspot.com/t/workflow-migrate-an-api-key-integration-to-a-private-app/65954/1 "2022-09-27T11:29:09Z")

</div>

We have to change our custom code in workflows (python) from Key to Token.  
In my console, the code works fine. Easy to change, but in the workflow I get an Error.  
console:

```auto
from hubspot import HubSpot
from hubspot.crm.quotes import ApiException

hubspot = HubSpot(access_token=token)
hubspot.crm.quotes.associations_api.get_all(quote_id="56948949", to_object_type="deal", limit=1)​

-> 
{'paging': None, 'results': [{'id': '5529167352', 'type': 'quote_to_deal'}]}

```

workflow

```auto
from hubspot import HubSpot
from hubspot.crm.quotes import ApiException

hubspot = HubSpot(access_token=os.getenv("HTOKEN"))
hubspot.crm.quotes.associations_api.get_all(quote_id="56948949", to_object_type="deal", limit=1)

->
[ERROR] ApiException: (401)
Reason: Unauthorized
HTTP response body: {"status":"error","message":"Authentication credentials not found. This API supports both API Key and OAuth 2.0 authentication and you can find more details at https://developers.hubspot.com/docs/methods/auth/oauth-overview","correlationId":"a166f3d7-1fb9-46f5-a7cf-9fee0787b985","category":"INVALID_AUTHENTICATION"}

```

---

<div class="post-metadata">

**Author:** ![coldrickjack](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/coldrickjack/32/6684_2.png) [@coldrickjack](https://community.hubspot.com/u/coldrickjack)\
**Post date:** [September 27, 2022, 11:58am UTC](https://community.hubspot.com/t/workflow-migrate-an-api-key-integration-to-a-private-app/65954/2 "2022-09-27T11:58:16Z")

</div>

Hi [@LKlaßen](https://community.hubspot.com/t5/user/viewprofilepage/user-id/287044)

At the very top of your custom coded workflow can you add this line of code and try again:

```lia-code-sample
import os

```

---

<div class="post-metadata">

**Author:** ![LKlassen](https://avatars.discourse-cdn.com/v4/letter/l/f0a364/32.png) [@LKlassen](https://community.hubspot.com/u/LKlassen)\
**Post date:** [September 27, 2022, 1:03pm UTC](https://community.hubspot.com/t/workflow-migrate-an-api-key-integration-to-a-private-app/65954/3 "2022-09-27T13:03:33Z")

</div>

Hi @coldrickjack thx for your reply!  
Already did this. The hole Test code that don’t work in the Workflow is:

```lia-code-sample
import os
from requests.auth import HTTPBasicAuth
import requests
from hubspot import HubSpot
from hubspot.crm.quotes import ApiException
from hubspot.crm.objects import SimplePublicObjectInput
import json
from datetime import datetime

def main(event):
 htoken = os.getenv("HTOKEN")
 print(type(htoken))
 hubspot = HubSpot(access_token=htoken)
 quote_Id = event.get("inputFields").get("quoteId")
 try:
 api_response = hubspot.crm.quotes.associations_api.get_all(
 quote_id=quote_Id, to_object_type="deal", limit=1)
 except ApiException as e:
 print("Exception when calling associations_api->get_all: %s\n" % e)
 return(api_response)

```

BUT same works in the console:

```lia-code-sample
import os
from requests.auth import HTTPBasicAuth
import requests
from hubspot import HubSpot
from hubspot.crm.quotes import ApiException
from hubspot.crm.objects import SimplePublicObjectInput
import json
from datetime import datetime

def main():
 htoken = ' **********'
 hubspot = HubSpot(access_token=htoken)
 quote_Id = '56948949'
 try:
 api_response = hubspot.crm.quotes.associations_api.get_all(
 quote_id=quote_Id, to_object_type="deal", limit=1)
 except ApiException as e:
 print("Exception when calling associations_api->get_all: %s\n" % e)
 return(api_response)

```

I can’t see why… with the key it worked fine

---

<div class="post-metadata">

**Author:** ![coldrickjack](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/coldrickjack/32/6684_2.png) [@coldrickjack](https://community.hubspot.com/u/coldrickjack)\
**Post date:** [September 27, 2022, 1:41pm UTC](https://community.hubspot.com/t/workflow-migrate-an-api-key-integration-to-a-private-app/65954/4 "2022-09-27T13:41:54Z")

</div>

Hey [@LKlaßen](https://community.hubspot.com/t5/user/viewprofilepage/user-id/287044)

I think the issue may be that the custom coded workflow actions use an older version of the HubSpot client v4.0.4. [Releases · HubSpot/hubspot-api-python · GitHub](https://github.com/HubSpot/hubspot-api-python/releases). Unfortunately there is no way to upgrade the client within a workflow. The only other thing I can think of is not to use the HubSpot client and instead use the Python requests 2.26.0 library. That works for me using below:

```lia-code-sample
import os
import requests
import json

def main(event):

 htoken = os.getenv('HTOKEN')
 quoteId = event.get("inputFields").get("quoteId")
 url = "https://api.hubapi.com/crm/v3/objects/quotes/" + quoteId + "/associations/deal?limit=500"
 headers = {'authorization': 'Bearer ' + htoken }

 r = requests.get(url, headers = headers)
 data = json.loads(r.text)
 print(data)

```
