<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def job_tasks(self, job_id, type=None):
 """ With the tasks API, you can obtain a collection of resources that represent a task within a job. :param str job_id: The job id :param str type: type of task, valid values are m or r. m for map task or r for reduce task :returns: API response object with JSON data :rtype: :py:class:`yarn_api_client.base.Response` """

        path = '/ws/v1/history/mapreduce/jobs/{jobid}/tasks'.format(
            jobid=job_id)

        # m - for map
        # r - for reduce
        valid_types = ['m', 'r']
        if type is not None and type not in valid_types:
            msg = 'Job type %s is illegal' % (type,)
            raise IllegalArgumentError(msg)

        params = {}
        if type is not None:
            params['type'] = type

        return self.request(path, **params)