SMS送信(即時送信)
from datetime import datetime
from karaden.config import Config
from karaden.param.message_create_params import MessageCreateParams
from karaden.model.message import Message
from karaden.exception.bad_request_exception import BadRequestException
from karaden.exception.forbidden_exception import ForbiddenException
from karaden.exception.invalid_params_exception import InvalidParamsException
from karaden.exception.not_found_exception import NotFoundException
from karaden.exception.too_many_reqests_exception import TooManyRequestsException
from karaden.exception.unauthorized_exception import UnauthorizedException
from karaden.exception.unexpected_value_exception import UnexpectedValueException
from karaden.exception.unknown_error_exception import UnknownErrorException
from karaden.exception.unprocessable_entity_exception import UnprocessableEntityException
Config.api_key = 'PJ-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
Config.api_version = '2023-01-01'
Config.tenant_id = 'xxxxxxxx-yyyy-zzzz-xxxx-123456789012'
body = """
送信テスト
https://www.nttcoms.com/
"""
params = (
MessageCreateParams
.new_builder()
.with_service_id(1)
.with_to('090********')
.with_body(body)
.with_tags(['testtag'])
.with_is_shorten(False)
.build()
)
request_options = Config.as_request_options()
try:
message = Message.create(params, request_options)
print(vars(message))
except BadRequestException as e:
print("BadRequestExceptionが返されました")
print(vars(e))
except ForbiddenException as e:
print("ForbiddenExceptionが返されました")
print(vars(e))
except InvalidParamsException as e:
print("InvalidParamsExceptionが返されました")
error_obj = e.error
error_object = error_obj.errors
if(error_object):
print(vars(error_object))
except NotFoundException as e:
print("NotFoundExceptionが返されました")
print(vars(e))
except TooManyRequestsException as e:
print("TooManyRequestsExceptionが返されました")
print(vars(e))
except UnauthorizedException as e:
print("UnauthorizedExceptionが返されました")
print(vars(e))
except UnexpectedValueException as e:
print("UnexpectedValueExceptionが返されました")
print(vars(e))
except UnknownErrorException as e:
print("UnknownErrorExceptionが返されました")
print(vars(e))
except UnprocessableEntityException as e:
print("UnprocessableEntityExceptionが返されました")
error_obj = e.error
error_object = error_obj.errors
if(error_object):
print(vars(error_object))
except Exception as e:
print("[Error!]")
print(vars(e))
SMS送信(予約送信)
from datetime import datetime
from karaden.config import Config
from karaden.param.message_create_params import MessageCreateParams
from karaden.model.message import Message
from karaden.exception.bad_request_exception import BadRequestException
from karaden.exception.forbidden_exception import ForbiddenException
from karaden.exception.invalid_params_exception import InvalidParamsException
from karaden.exception.not_found_exception import NotFoundException
from karaden.exception.too_many_reqests_exception import TooManyRequestsException
from karaden.exception.unauthorized_exception import UnauthorizedException
from karaden.exception.unexpected_value_exception import UnexpectedValueException
from karaden.exception.unknown_error_exception import UnknownErrorException
from karaden.exception.unprocessable_entity_exception import UnprocessableEntityException
Config.api_key = 'PJ-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
Config.api_version = '2023-01-01'
Config.tenant_id = 'xxxxxxxx-yyyy-zzzz-xxxx-123456789012'
dt = datetime.fromisoformat('2023-01-01T12:00:00+09:00')
body = """
送信テスト
https://www.nttcoms.com/
"""
params = (
MessageCreateParams
.new_builder()
.with_service_id(1)
.with_to('090********')
.with_body(body)
.with_tags(['testtag'])
.with_is_shorten(False)
.with_scheduled_at(dt)
.build()
)
request_options = Config.as_request_options()
try:
message = Message.create(params, request_options)
print(vars(message))
except BadRequestException as e:
print("BadRequestExceptionが返されました")
print(vars(e))
except ForbiddenException as e:
print("ForbiddenExceptionが返されました")
print(vars(e))
except InvalidParamsException as e:
print("InvalidParamsExceptionが返されました")
error_obj = e.error
error_object = error_obj.errors
if(error_object):
print(vars(error_object))
except NotFoundException as e:
print("NotFoundExceptionが返されました")
print(vars(e))
except TooManyRequestsException as e:
print("TooManyRequestsExceptionが返されました")
print(vars(e))
except UnauthorizedException as e:
print("UnauthorizedExceptionが返されました")
print(vars(e))
except UnexpectedValueException as e:
print("UnexpectedValueExceptionが返されました")
print(vars(e))
except UnknownErrorException as e:
print("UnknownErrorExceptionが返されました")
print(vars(e))
except UnprocessableEntityException as e:
print("UnprocessableEntityExceptionが返されました")
error_obj = e.error
error_object = error_obj.errors
if(error_object):
print(vars(error_object))
except Exception as e:
print("[Error!]")
print(vars(e))
SMS送信結果取得(一括)
from datetime import datetime
from karaden.config import Config
from karaden.param.message_list_params import MessageListParams
from karaden.model.message import Message
from karaden.exception.bad_request_exception import BadRequestException
from karaden.exception.forbidden_exception import ForbiddenException
from karaden.exception.invalid_params_exception import InvalidParamsException
from karaden.exception.not_found_exception import NotFoundException
from karaden.exception.too_many_reqests_exception import TooManyRequestsException
from karaden.exception.unauthorized_exception import UnauthorizedException
from karaden.exception.unexpected_value_exception import UnexpectedValueException
from karaden.exception.unknown_error_exception import UnknownErrorException
from karaden.exception.unprocessable_entity_exception import UnprocessableEntityException
Config.api_key = 'PJ-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
Config.api_version = '2023-01-01'
Config.tenant_id = 'xxxxxxxx-yyyy-zzzz-xxxx-123456789012'
params = (
MessageListParams
.new_builder()
.with_service_id(1)
.with_to('090********')
.with_status('done')
.build()
)
request_options = Config.as_request_options()
try:
collection = Message.list(params, request_options)
for item in collection._properties['data']:
print(item.__dict__)
print("------------------------------")
print(vars(collection))
except BadRequestException as e:
print("BadRequestExceptionが返されました")
print(vars(e))
except ForbiddenException as e:
print("ForbiddenExceptionが返されました")
print(vars(e))
except InvalidParamsException as e:
print("InvalidParamsExceptionが返されました")
error_obj = e.error
error_object = error_obj.errors
if(error_object):
print(vars(error_object))
except NotFoundException as e:
print("NotFoundExceptionが返されました")
print(vars(e))
except TooManyRequestsException as e:
print("TooManyRequestsExceptionが返されました")
print(vars(e))
except UnauthorizedException as e:
print("UnauthorizedExceptionが返されました")
print(vars(e))
except UnexpectedValueException as e:
print("UnexpectedValueExceptionが返されました")
print(vars(e))
except UnknownErrorException as e:
print("UnknownErrorExceptionが返されました")
print(vars(e))
except UnprocessableEntityException as e:
print("UnprocessableEntityExceptionが返されました")
error_obj = e.error
error_object = error_obj.errors
if(error_object):
print(vars(error_object))
except Exception as e:
print("[Error!]")
print(vars(e))
SMS送信結果取得(レコード単位)
from datetime import datetime
from karaden.config import Config
from karaden.param.message_detail_params import MessageDetailParams
from karaden.model.message import Message
from karaden.exception.bad_request_exception import BadRequestException
from karaden.exception.forbidden_exception import ForbiddenException
from karaden.exception.invalid_params_exception import InvalidParamsException
from karaden.exception.not_found_exception import NotFoundException
from karaden.exception.too_many_reqests_exception import TooManyRequestsException
from karaden.exception.unauthorized_exception import UnauthorizedException
from karaden.exception.unexpected_value_exception import UnexpectedValueException
from karaden.exception.unknown_error_exception import UnknownErrorException
from karaden.exception.unprocessable_entity_exception import UnprocessableEntityException
Config.api_key = 'PJ-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
Config.api_version = '2023-01-01'
Config.tenant_id = 'xxxxxxxx-yyyy-zzzz-xxxx-123456789012'
params = (
MessageDetailParams
.new_builder()
.with_id('12345678-aabb-1234-abcd-123456789123')
.build()
)
request_options = Config.as_request_options()
try:
message = Message.detail(params, request_options)
print(vars(message))
except BadRequestException as e:
print("BadRequestExceptionが返されました")
print(vars(e))
except ForbiddenException as e:
print("ForbiddenExceptionが返されました")
print(vars(e))
except InvalidParamsException as e:
print("InvalidParamsExceptionが返されました")
error_obj = e.error
error_object = error_obj.errors
if(error_object):
print(vars(error_object))
except NotFoundException as e:
print("NotFoundExceptionが返されました")
print(vars(e))
except TooManyRequestsException as e:
print("TooManyRequestsExceptionが返されました")
print(vars(e))
except UnauthorizedException as e:
print("UnauthorizedExceptionが返されました")
print(vars(e))
except UnexpectedValueException as e:
print("UnexpectedValueExceptionが返されました")
print(vars(e))
except UnknownErrorException as e:
print("UnknownErrorExceptionが返されました")
print(vars(e))
except UnprocessableEntityException as e:
print("UnprocessableEntityExceptionが返されました")
error_obj = e.error
error_object = error_obj.errors
if(error_object):
print(vars(error_object))
except Exception as e:
print("[Error!]")
print(vars(e))
SMS送信キャンセル
from datetime import datetime
from karaden.config import Config
from karaden.param.message_cancel_params import MessageCancelParams
from karaden.model.message import Message
from karaden.exception.bad_request_exception import BadRequestException
from karaden.exception.forbidden_exception import ForbiddenException
from karaden.exception.invalid_params_exception import InvalidParamsException
from karaden.exception.not_found_exception import NotFoundException
from karaden.exception.too_many_reqests_exception import TooManyRequestsException
from karaden.exception.unauthorized_exception import UnauthorizedException
from karaden.exception.unexpected_value_exception import UnexpectedValueException
from karaden.exception.unknown_error_exception import UnknownErrorException
from karaden.exception.unprocessable_entity_exception import UnprocessableEntityException
Config.api_key = 'PJ-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
Config.api_version = '2023-01-01'
Config.tenant_id = 'xxxxxxxx-yyyy-zzzz-xxxx-123456789012'
params = (
MessageCancelParams
.new_builder()
.with_id('12345678-aabb-1234-abcd-123456789123')
.build()
)
request_options = Config.as_request_options()
try:
message = Message.cancel(params, request_options)
print(vars(message))
except BadRequestException as e:
print("BadRequestExceptionが返されました")
print(vars(e))
except ForbiddenException as e:
print("ForbiddenExceptionが返されました")
print(vars(e))
except InvalidParamsException as e:
print("InvalidParamsExceptionが返されました")
error_obj = e.error
error_object = error_obj.errors
if(error_object):
print(vars(error_object))
except NotFoundException as e:
print("NotFoundExceptionが返されました")
print(vars(e))
except TooManyRequestsException as e:
print("TooManyRequestsExceptionが返されました")
print(vars(e))
except UnauthorizedException as e:
print("UnauthorizedExceptionが返されました")
print(vars(e))
except UnexpectedValueException as e:
print("UnexpectedValueExceptionが返されました")
print(vars(e))
except UnknownErrorException as e:
print("UnknownErrorExceptionが返されました")
print(vars(e))
except UnprocessableEntityException as e:
print("UnprocessableEntityExceptionが返されました")
error_obj = e.error
error_object = error_obj.errors
if(error_object):
print(vars(error_object))
except Exception as e:
print("[Error!]")
print(vars(e))