Create a Job using the SDK API

Hi @PanjiBrotoisworo ,

I believe so. I’m not sure whether this is entirely how one would do it, but here is my attempt:

    def run_job(self, entity_id, params, method: str):
        url = f"{self.host}/workspaces/{self.workspace_id}/entities/{entity_id}/jobs/"
        payload = json.dumps({
            "params": params,
            "method_name": method,
        })
        response = requests.request("POST", url, headers=self.headers, data=payload)
        job_result = response.json()
        for i in range(120):
            response = requests.request("GET", job_result['url'], headers=self.headers)
            result = response.json()
            print(result['status'])
            if result['status'] == 'success':
                return result
            elif result['status'] == 'failed':
                raise UserError(result['message'])
            sleep(1)
        else:
            raise UserError(result['message'])
1 Like