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

Hi,

I’m writing a Python application for our in-company internal use.
I’m using hubspot-api-client==6.0.0 package.
I’m trying to subsribe an email address using the marketing API like this:

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:

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?

@sam_at_humanz

Still having this issue?

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

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

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"}

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.

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