# Error while using custom code to update task

**URL:** <https://community.hubspot.com/t/error-while-using-custom-code-to-update-task/62504>\
**Category:** Data Hub\
**Created:** [August 6, 2022, 4:27pm UTC](https://community.hubspot.com/t/error-while-using-custom-code-to-update-task/62504 "2022-08-06T16:27:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AbdulRahim](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@AbdulRahim](https://community.hubspot.com/u/AbdulRahim)\
**Post date:** [August 6, 2022, 4:27pm UTC](https://community.hubspot.com/t/error-while-using-custom-code-to-update-task/62504/1 "2022-08-06T16:27:43Z")

</div>

I am trying to update tasks using Python 3.9 for learning purposes.

I tried several ways to resolve this error but the error persists.

The error:

```lia-code-sample
[ERROR] ApiException: (401)
Reason: Unauthorized
HTTP response body: {"status":"error","message":"Authentication credentials not found."}

```

The code I am using:

```lia-code-sample
 url = 'https://api.hubapi.com/crm/v3/objects/tasks/' + task.id
 auth = os.getenv('HAPIKEY')
 payload = "{\"properties\":{\"hs_task_status\":\"COMPLETED\"}}"
 headers = {
 'accept': 'application/json',
 'content-type': 'application/json',
 'authorization': 'Bearer '+auth
 }
 response = requests.request(
 "PATCH", url, data=payload, headers=headers)

```

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [August 9, 2022, 11:09am UTC](https://community.hubspot.com/t/error-while-using-custom-code-to-update-task/62504/2 "2022-08-09T11:09:02Z")

</div>

Hi @AbdulRahim ,

It seems as if you are trying to pass an API key in the authorization header, which will not work.

[API keys are getting sunset](https://developers.hubspot.com/changelog/upcoming-api-key-sunset), so your go-to authentication method should be a [private app](https://developers.hubspot.com/docs/api/migrate-an-api-key-integration-to-a-private-app).

I’m pretty positive that if you use a private app token in your code instead of the API key, it should work. Just make sure you have the right scope selected.
