'POST /api/request_types
Creates a new request type (external_service configuration).'

@web.expose_api
def create(self, trans, payload, **kwd):

    if (not trans.user_is_admin()):
        trans.response.status = 403
        return 'You    are    not    authorized    to    create    a    new    request    type    (external_service    configuration).'
    xml_text = payload.get('xml_text', None)
    if (xml_text is None):
        trans.response.status = 400
        return "Missing    required    parameter    'xml_text'."
    elem = XML(xml_text)
    request_form_id = payload.get('request_form_id', None)
    if (request_form_id is None):
        trans.response.status = 400
        return "Missing    required    parameter    'request_form_id'."
    request_form = trans.sa_session.query(trans.app.model.FormDefinition).get(trans.security.decode_id(request_form_id))
    sample_form_id = payload.get('sample_form_id', None)
    if (sample_form_id is None):
        trans.response.status = 400
        return "Missing    required    parameter    'sample_form_id'."
    sample_form = trans.sa_session.query(trans.app.model.FormDefinition).get(trans.security.decode_id(sample_form_id))
    external_service_id = payload.get('external_service_id', None)
    if (external_service_id is None):
        trans.response.status = 400
        return "Missing    required    parameter    'external_service_id'."
    external_service = trans.sa_session.query(trans.app.model.ExternalService).get(trans.security.decode_id(external_service_id))
    request_type = request_type_factory.from_elem(elem, request_form, sample_form, external_service)
    role_ids = payload.get('role_ids', [])
    roles = [trans.sa_session.query(trans.model.Role).get(trans.security.decode_id(i)) for i in role_ids]
    permissions = {}
    if roles:
        for (k, v) in trans.model.RequestType.permitted_actions.items():
            permissions[trans.app.security_agent.get_action(v.action)] = roles
    if permissions:
        trans.app.security_agent.set_request_type_permissions(request_type, permissions)
    trans.sa_session.add(request_type)
    trans.sa_session.flush()
    encoded_id = trans.security.encode_id(request_type.id)
    item = request_type.to_dict(view='element', value_mapper={'id': trans.security.encode_id, 'request_form_id': trans.security.encode_id, 'sample_form_id': trans.security.encode_id})
    item['url'] = url_for('request_type', id=encoded_id)
    return [item]
