I am developing a workflow using Dataops - customcode to add something from Hubspot ticket to Azure DevOps work item as a comment.
Here is my script:
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
from azure.devops.v7_1.py_pi_api import JsonPatchOperation
import pprint
# Fill in with your personal access token and org URL
personal_access_token = 'xxxxxxxxxxxxxxxxxxxxxxxxx'
organization_url = 'https://dev.azure.com/xxxxxxxxx'
# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)
# Get a client (the "core" client provides access to projects, teams, etc)
core_client = connection.clients.get_core_client()
wit_client = connection.clients.get_work_item_tracking_client()
patch_document = [
JsonPatchOperation(
op="add",
path="/fields/System.History",
value={
"text": "sample comment",
},
)
]
wit_client.update_work_item(patch_document, "xxxxx")
My Python script works well locally but does not work on Hubspot workflow. Here is the error message
[ERROR] Runtime.ImportModuleError: Unable to import module 'hubspotHandler': No module named 'azure'
I am aware Hubspot dose not support the library named azure-devops right now so is there any way to import the module azure-devops?
In local machine, I use the command "pip install azure-devops"
thank you for reaching out to the community. The importing of other packages doesn't work, unfortunately, as you noticed.
The documentation is pretty clear about what kind of packages you can use:
requests 2.28.2
@hubspot/api-client ^8
google-api-python-client 2.74.0
mysql-connector-python 8.0.32
redis 4.4.2
nltk 3.8.1
I'm not familiar with Azure, but this looks like a simple API call to me. You could also do this with the requests library, I think. Have you tried that?
I resolved the issue by using another service - Azure Automation Account, and I will Hubspot webhook instead of Hubspot customcode.
And now, i have another script, the script will call to hubspot api and it works well locally but got SSL issue on Azure Automation Account.
Traceback (most recent call last): File "C:\userenv\lib\site-packages\urllib3\connectionpool.py", line 467, in _make_request self._validate_conn(conn) File "C:\userenv\lib\site-packages\urllib3\connectionpool.py", line 1099, in _validate_conn conn.connect() File "C:\userenv\lib\site-packages\urllib3\connection.py", line 653, in connect sock_and_verified = _ssl_wrap_socket_and_match_hostname( File "C:\userenv\lib\site-packages\urllib3\connection.py", line 806, in _ssl_wrap_socket_and_match_hostname ssl_sock = ssl_wrap_socket( File "C:\userenv\lib\site-packages\urllib3\util\ssl_.py", line 465, in ssl_wrap_socket ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname) File "C:\userenv\lib\site-packages\urllib3\util\ssl_.py", line 509, in _ssl_wrap_socket_impl return ssl_context.wrap_socket(sock, server_hostname=server_hostname) File "C:\Python\lib\ssl.py", line 500, in wrap_socket return self.sslsocket_class._create( File "C:\Python\lib\ssl.py", line 1040, in _create self.do_handshake() File "C:\Python\lib\ssl.py", line 1309, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\userenv\lib\site-packages\urllib3\connectionpool.py", line 793, in urlopen response = self._make_request( File "C:\userenv\lib\site-packages\urllib3\connectionpool.py", line 491, in _make_request raise new_e urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/src/tmp/94079701-23ba-4aab-877d-d1b7f0ba2be3/runbooks/azuredevops.py", line 15, in <module> api_response = client.crm.objects.notes.basic_api.create(simple_public_object_input_for_create=simple_public_object_input_for_create) File "C:\userenv\lib\site-packages\hubspot\crm\objects\notes\api\basic_api.py", line 185, in create return self.create_with_http_info(simple_public_object_input_for_create, **kwargs) # noqa: E501 File "C:\userenv\lib\site-packages\hubspot\crm\objects\notes\api\basic_api.py", line 266, in create_with_http_info return self.api_client.call_api( File "C:\userenv\lib\site-packages\hubspot\crm\objects\notes\api_client.py", line 378, in call_api return self.__call_api( File "C:\userenv\lib\site-packages\hubspot\crm\objects\notes\api_client.py", line 185, in __call_api response_data = self.request( File "C:\userenv\lib\site-packages\hubspot\crm\objects\notes\api_client.py", line 428, in request return self.rest_client.POST(url, query_params=query_params, headers=headers, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, body=body) File "C:\userenv\lib\site-packages\hubspot\crm\objects\notes\rest.py", line 207, in POST return self.request("POST", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, body=body) File "C:\userenv\lib\site-packages\hubspot\crm\objects\notes\rest.py", line 143, in request r = self.pool_manager.request(method, url, body=request_body, preload_content=_preload_content, timeout=timeout, headers=headers) File "C:\userenv\lib\site-packages\urllib3\_request_methods.py", line 144, in request return self.request_encode_body( File "C:\userenv\lib\site-packages\urllib3\_request_methods.py", line 279, in request_encode_body return self.urlopen(method, url, **extra_kw) File "C:\userenv\lib\site-packages\urllib3\poolmanager.py", line 444, in urlopen response = conn.urlopen(method, u.request_uri, **kw) File "C:\userenv\lib\site-packages\urllib3\connectionpool.py", line 877, in urlopen return self.urlopen( File "C:\userenv\lib\site-packages\urllib3\connectionpool.py", line 877, in urlopen return self.urlopen( File "C:\userenv\lib\site-packages\urllib3\connectionpool.py", line 877, in urlopen return self.urlopen( File "C:\userenv\lib\site-packages\urllib3\connectionpool.py", line 847, in urlopen retries = retries.increment( File "C:\userenv\lib\site-packages\urllib3\util\retry.py", line 515, in increment raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.hubapi.com', port=443): Max retries exceeded with url: /crm/v3/objects/notes (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)')))
Click here for troubleshooting help
#!/usr/bin/env python3
import hubspot
from pprint import pprint
from hubspot import HubSpot
from hubspot.crm.objects.notes import SimplePublicObjectInputForCreate, ApiException
my_token = 'pat-na1-1489556d-xxxx-xxxx-xxxx-xxxxxxxxxx'
api_client = HubSpot()
api_client.access_token = my_token
properties = {
"hs_note_body": "The note is copied from ADO work item using Automation Account",
"hs_timestamp": "2024-02-27T03:30:17.883Z",
"hubspot_owner_id": "xxxxxx" # ID of Hubspot user (using xxxx)
}
associations = [{
"types":[{
"associationCategory":"HUBSPOT_DEFINED",
"associationTypeId":xxx # Hubpot associationType ID (Here is ID between note engagement & ticket object)
}],
"to":{
"id":"xxxxxxx" # Hubspot ticket ID
}
}]
simple_public_object_input_for_create = SimplePublicObjectInputForCreate(associations=associations, properties=properties)
try:
api_response = api_client.crm.objects.notes.basic_api.create(simple_public_object_input_for_create=simple_public_object_input_for_create)
pprint(api_response)
except ApiException as e:
print("Exception when calling basic_api->create: %s\n" % e)
thank you for reaching out to the community. The importing of other packages doesn't work, unfortunately, as you noticed.
The documentation is pretty clear about what kind of packages you can use:
requests 2.28.2
@hubspot/api-client ^8
google-api-python-client 2.74.0
mysql-connector-python 8.0.32
redis 4.4.2
nltk 3.8.1
I'm not familiar with Azure, but this looks like a simple API call to me. You could also do this with the requests library, I think. Have you tried that?