# Error 500 on creating a subscription using Marketing API/Subscription Preferences

**URL:** <https://community.hubspot.com/t/error-500-on-creating-a-subscription-using-marketing-api-subscription-preferences/64450>\
**Category:** APIs & Integrations\
**Tags:** python, sdk\
**Created:** [September 5, 2022, 11:09am UTC](https://community.hubspot.com/t/error-500-on-creating-a-subscription-using-marketing-api-subscription-preferences/64450 "2022-09-05T11:09:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam\_at\_humanz](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@sam\_at\_humanz](https://community.hubspot.com/u/sam_at_humanz)\
**Post date:** [September 5, 2022, 11:09am UTC](https://community.hubspot.com/t/error-500-on-creating-a-subscription-using-marketing-api-subscription-preferences/64450/1 "2022-09-05T11:09:03Z")

</div>

Hi,

I’m writing a Python application for our in-company internal use.  
I’m using [hubspot-api-client==6.0.0](https://pypi.org/project/hubspot-api-client/) package.  
I’m trying to subsribe an email address using the marketing API like this:

```lia-code-sample
email = 'test@example.com'
sub_id = '12345'
subbody = PublicUpdateSubscriptionStatusRequest(email, subscription_id=sub_id, legal_basis='PROCESS_AND_STORE', legal_basis_explanation='Test explanation')
api_response = self.__client.communication_preferences.status_api.subscribe(subscription_request)
print(f"success = {api_response.status == 'SUBSCRIBED'}")

```

I’m getting 500 error:

```lia-code-sample
hubspot.communication_preferences.exceptions.ApiException: (500)
Reason: Internal Server Error
HTTP response headers: HTTPHeaderDict({'Date': 'Mon, 05 Sep 2022 10:58:10 GMT', 'Content-Type': 'application/json;charset=utf-8', 'Content-Length': '100', 'Connection': 'keep-alive', 'CF-Ray': '745e72bfcb50731a-LHR', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'Vary': 'Accept-Encoding', 'CF-Cache-Status': 'DYNAMIC', 'Access-Control-Allow-Credentials': 'false', 'X-HubSpot-Correlation-Id': '38e195ac-db40-45a7-b36d-70ad918e9ca4', 'X-HubSpot-RateLimit-Interval-Milliseconds': '10000', 'X-HubSpot-RateLimit-Max': '100', 'X-HubSpot-RateLimit-Remaining': '99', 'X-HubSpot-RateLimit-Secondly': '10', 'X-HubSpot-RateLimit-Secondly-Remaining': '9', 'Report-To': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=nUVZ9X9WtYYqv%2BeUaERekzoa3p7ElvkYUARljV9Acl%2FSVK2NgF3iYmOPWGSPu2DpnDZrbcD%2Fl3JkkmJou%2FPkUy1eEpnSEpBboBc19avNJnEQd%2F9sdLLDGm3181Ux3ydk"}],"group":"cf-nel","max_age":604800}', 'NEL': '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}', 'Server': 'cloudflare', 'alt-svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400'})
HTTP response body: {"status":"error","message":"internal error","correlationId":"38e195ac-db40-45a7-b36d-70ad918e9ca4"}

```

Any ideas?

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [September 6, 2022, 3:58pm UTC](https://community.hubspot.com/t/error-500-on-creating-a-subscription-using-marketing-api-subscription-preferences/64450/2 "2022-09-06T15:58:16Z")

</div>

[@sam\_at\_humanz](https://community.hubspot.com/t5/user/viewprofilepage/user-id/443881)

Still having this issue?

Could you try to replace your variables with the actual values to see if that works?

---

<div class="post-metadata">

**Author:** ![sam\_at\_humanz](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@sam\_at\_humanz](https://community.hubspot.com/u/sam_at_humanz)\
**Post date:** [September 7, 2022, 6:45am UTC](https://community.hubspot.com/t/error-500-on-creating-a-subscription-using-marketing-api-subscription-preferences/64450/3 "2022-09-07T06:45:05Z")

</div>

Hi @dennisedson  
Just tried with actual values, still getting 500:

```lia-code-sample
hubspot.communication_preferences.exceptions.ApiException: (500)

Reason: Internal Server Error

HTTP response headers: HTTPHeaderDict({'Date': 'Wed, 07 Sep 2022 06:43:41 GMT', 'Content-Type': 'application/json;charset=utf-8', 'Content-Length': '100', 'Connection': 'keep-alive', 'CF-Ray': '746d78b70ffc0672-LHR', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'Vary': 'Accept-Encoding', 'CF-Cache-Status': 'DYNAMIC', 'Access-Control-Allow-Credentials': 'false', 'X-HubSpot-Correlation-Id': '1ab315ff-6472-45a0-8afa-af3f331e6c83', 'X-HubSpot-RateLimit-Interval-Milliseconds': '10000', 'X-HubSpot-RateLimit-Max': '100', 'X-HubSpot-RateLimit-Remaining': '99', 'X-HubSpot-RateLimit-Secondly': '10', 'X-HubSpot-RateLimit-Secondly-Remaining': '9', 'Report-To': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=nGviEpw3%2BW2RNu2ylqrWmOASe9%2FO21I54vRd9sfZoMMH%2F91wj%2Fp8ErjufdTTvBXtWCCWh6r1agLUXHn2icwKs9JrYe0uP%2FbGYsuKIPTESiQqvirnGY0FQBiqd5I18AOl"}],"group":"cf-nel","max_age":604800}', 'NEL': '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}', 'Server': 'cloudflare', 'alt-svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400'})
HTTP response body: {"status":"error","message":"internal error","correlationId":"1ab315ff-6472-45a0-8afa-af3f331e6c83"}

```

---

<div class="post-metadata">

**Author:** ![sam\_at\_humanz](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@sam\_at\_humanz](https://community.hubspot.com/u/sam_at_humanz)\
**Post date:** [November 13, 2022, 9:13am UTC](https://community.hubspot.com/t/error-500-on-creating-a-subscription-using-marketing-api-subscription-preferences/64450/4 "2022-11-13T09:13:45Z")

</div>

Hey

Just sharing the solution:  
subscription\_id is actually the list id, not the subscriber id.  
So I just iterate all the different lists we have in our account and unsubscribe by email address.

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [September 7, 2022, 1:21pm UTC](https://community.hubspot.com/t/error-500-on-creating-a-subscription-using-marketing-api-subscription-preferences/64450/5 "2022-09-07T13:21:13Z")

</div>

@JBeatty , anything jumping out at you as a problem here?
