trycourier / courier-python Goto Github PK
View Code? Open in Web Editor NEWA Python Package for communicating with the Courier REST API.
Home Page: https://pypi.org/project/trycourier/
License: MIT License
A Python Package for communicating with the Courier REST API.
Home Page: https://pypi.org/project/trycourier/
License: MIT License
Tried to create ad hoc automation with delay and send steps, but not sure how can I pass to
in send step to point email of recipient. I noticed in the code that this step can receive profile - is this the way to pass recipient email? This is the code I am using:
import courier
from courier.client import Courier
...
response = client.automations.invoke_ad_hoc_automation(
request = courier.AutomationAdHocInvokeParams(
data = {
'email': data['email'],
'cancelation_token': cancelation_token
},
automation = courier.Automation(
cancelation_token=cancelation_token,
steps=[
courier.AutomationDelayStep(
action="delay",
duration="48 hours"
),
courier.AutomationSendStep(
profile={"email": data["email"]},
template=template,
action="send",
data=data['template_data']
)
]
)
)
)
Running it receive this error:
status_code: 400, body: {'message': 'Invalid Steps Definition: one or more steps are incorrectly defined.', 'type': 'invalid_request_error'}, {'status_code': 400, 'body': {'message': 'Invalid Steps Definition: one or more steps are incorrectly defined.', 'type': 'invalid_request_error'}}
3 validation errors for ParsingModel[MessageDetails]
__root__ -> delivered
field required (type=value_error.missing)
__root__ -> opened
field required (type=value_error.missing)
__root__ -> clicked
field required (type=value_error.missing)
@
def get(self, message_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> MessageDetails:
# ....
if 200 <= _response.status_code < 300:
return pydantic_v1.parse_obj_as(MessageDetails, _response.json()) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ problematic line
Consistent python syntax
Inconsistent
Go to: https://github.com/trycourier/courier-python
search for "print resp"
I was able to create a SubscriptionTopic
pydantic model instance with only the id
argument set, but this is not accepted by the create_or_replace
API for the Tenants client:
from courier import DefaultPreferences, SubscriptionTopic
from courier import Client
client = Courier(authorization_token="******")
client.tenants.create_or_replace(tenant_id="org_asdf", name="foobaz")
client.tenants.create_or_replace(
tenant_id="org_asdf",
name="foobaz",
default_preferences=DefaultPreferences(items=[SubscriptionTopic(id="foo")])
)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/rccausey/.cache/pypoetry/virtualenvs/notifications-api-6mUc-8uv-py3.11/lib/python3.11/site-packages/courier/tenants/client.py", line 117, in create_or_replace
raise BadRequestError(pydantic_v1.parse_obj_as(BadRequest, _response.json())) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
courier.commons.errors.bad_request_error.BadRequestError: status_code: 400, body: message='[{"error":"/default_preferences/items/0 must have required property \'status\'","path":"/default_preferences/items/0"}]' type='invalid_request_error'
The create or replace API docs specify that the status
field is required for a SubscriptionTopic
: https://www.courier.com/docs/reference/tenants/create-replace/
The Pydantic model should be updated to require the status
field so it matches the REST API.
This was observed while using trycourier = "6.0.2".
I am attempting to list my tenants, but the issue I am running into is that the TenantListResponse
has an empty items
in the response. It appears it is supposed to return a list of Tenant
objects in the items
attribute, but this is always empty. This is the case even when the has_more
attribute is True
, indicating the list was paginated and I can retrieve more tenants. Passing the resulting cursor also returns a TenantListResponse
with an empty items
.
>>> client = Courier(authorization_token=courier_api_key)
>>> tenants = client.tenants.list_()
>>> tenants
TenantListResponse(cursor='MTcxODMxODc1MzkyMSxNR0prWlRZME5EQXRZV1prTXkwMFpHRXpMVGd4WkdRdE1tVmtZamcxT1RoaE9EaGlMM1JsYzNRdmIzSm5YelZLYTFocVNsWmtRMlpZWTJKM1NFOUVVazFNVmpKcmFFRnNjQT09', has_more=True, items=[], next_url='/tenants?cursor=MTcxODMxODc1MzkyMSxNR0prWlRZME5EQXRZV1prTXkwMFpHRXpMVGd4WkdRdE1tVmtZamcxT1RoaE9EaGlMM1JsYzNRdmIzSm5YelZLYTFocVNsWmtRMlpZWTJKM1NFOUVVazFNVmpKcmFFRnNjQT09', url='/tenants', type='list')
>>> tenants.has_more
True
>>> tenants.items
[]
I want to send slack notification (message as an app to another workspace).
slack_app
slack_app
into my own_workspace as own_ws
.user_x
has installed my slack app into their workspace.I want to automate this sending notification business using third parties for example, using courier or using something else library.
I have webhook url of user_x
's slack workspace which i caught during oauth installation and that is something can be used to send messages but how to automate this sending notification via some third party.
How we can send notification/message into another workspace ? I did research a bit but could not find relevant information anywhere.
Sorry that creating this an issue, It is Question/discussion label. I could not find anything, hence posted here for some positive response.
The behavior of create_or_replace
for the Tenants client does not match the REST API nor its Python method signature.
When I attempt to create a tenant without specifying default_preferences
, I get the following error:
from courier import Client
client = Courier(authorization_token="******")
client.tenants.create_or_replace(tenant_id="org_asdf", name="foobaz")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/rccausey/.cache/pypoetry/virtualenvs/notifications-api-6mUc-8uv-py3.11/lib/python3.11/site-packages/courier/tenants/client.py", line 115, in create_or_replace
return pydantic_v1.parse_obj_as(Tenant, _response.json()) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rccausey/.cache/pypoetry/virtualenvs/notifications-api-6mUc-8uv-py3.11/lib/python3.11/site-packages/pydantic/v1/tools.py", line 38, in parse_obj_as
return model_type(__root__=obj).__root__
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rccausey/.cache/pypoetry/virtualenvs/notifications-api-6mUc-8uv-py3.11/lib/python3.11/site-packages/pydantic/v1/main.py", line 341, in __init__
raise validation_error
pydantic.v1.error_wrappers.ValidationError: 1 validation error for ParsingModel[Tenant]
__root__ -> default_preferences -> items
field required (type=value_error.missing)
This same call to the REST API directly works fine.
The API documentation here states that default_preferences
are not required, which also matches the Python method signature: https://www.courier.com/docs/reference/tenants/create-replace/
This was observed with trycourier = "6.0.2".
Trying to add recipients to a list and have followed the included example but a bad request error is returned. Best I can tell, the request data isn't getting encoded properly to the expected format from the API.
"name": "BadRequestError",
"message": "status_code: 400, body: message=' type must be object' type='invalid_request_error'",
"stack": "---------------------------------------------------------------------------
BadRequestError Traceback (most recent call last)
Cell In[26], line 1
----> 1 client.lists.add_subscribers(
2 list_id="undelivered",
3 request=[PutSubscriptionsRecipient(recipient_id="1354820")]
4 )
File d:\\dev\\courierPy\\venv\\lib\\site-packages\\courier\\lists\\client.py:708, in ListsClient.add_subscribers(self, list_id, request, idempotency_key, idempotency_expiry, request_options)
706 return
707 if _response.status_code == 400:
--> 708 raise BadRequestError(pydantic_v1.parse_obj_as(BadRequest, _response.json())) # type: ignore
709 try:
710 _response_json = _response.json()
BadRequestError: status_code: 400, body: message=' type must be object' type='invalid_request_error'"
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.