Hi,
I’ve been able to create a job using the SDK API.
However, I’m a bit confused when trying to create a job using the REST API. I’ve seen the documentation but I’m not sure where to get the following required parameters. These are not required when creating a job in the SDK API:
- method_type: Type to the method to run the App Job.
- editor_session: UUID of the current editor session. This field is required when called under public endpoints.
When I make a POST request without those parameters I just get a 405 Not Allowed status. I’ve tried the code here but I still get an error.
Hi Panji,
First of all, as long as you are not trying to create a job for a public workspace, the editor_session is not required. If you are using a public workspace, you should create the session using: Create a new Editor Session | VIKTOR Documentation. Also, the method_type is not needed for a normal view or button, if you are trying to trigger something else like a preprocess or step method, let me know.
The 405 Not allowed generally means that you are using the wrong HTTP method for the url, so make sure that you are indeed using a POST on the valid url.
Your code should look roughly like this (if you use python). This should give you the url where you can fetch the job
import requests
import json
url = "https://<environment>.viktor.ai/api/workspaces/<workspace_id>/entities/<entity_id>/jobs/"
payload = json.dumps({
"method_name": "<you_controller_method_name>",
"params": {<your params here>},
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer <PersonalAccessToken>'
}
response = requests.post(url, headers=headers, data=payload)
print(response.json()["url"])
Hi @kvangiessen,
Thanks for the reply. It is now working. I think I was a bit tired at the time and did not notice the URL was wrong. I did not notice /api/
was missing in my URL.
I now get a 201 status.