How to properly start (start_job) and complete (complete_job) a Job Card in ERPNext via API?
Problem Description:
I am trying to manage a Job Card in ERPNext via the API, but I am encountering a KeyError: ‘run_method’ error when attempting to start (start_job) and complete (complete_job) the Job Card. Can someone help me understand how to properly execute these actions?
Short Code Snippet:
cpp
Copy
// Starting the Job Card
void startJob() {
if (WiFi.status() == WL_CONNECTED && jobCardName.length() > 0) {
HTTPClient http;
String url = String(erpnextServer) + “/api/resource/Job Card/” + jobCardName + “/start_job”;
http.begin(url);
http.addHeader(“Content-Type”, “application/json”);
http.addHeader(“Authorization”, "token " + String(apiKey) + “:” + String(apiSecret));
// Sending a POST request to start the Job Card
int httpResponseCode = http.POST("");
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println("ERPNext response for starting Job Card:");
Serial.println(response);
} else {
Serial.println("HTTP Response Code: " + String(httpResponseCode));
Serial.println("Response: " + http.getString());
}
http.end();
}
}
// Completing the Job Card
void completeJob() {
if (WiFi.status() == WL_CONNECTED && jobCardName.length() > 0) {
HTTPClient http;
String url = String(erpnextServer) + “/api/resource/Job Card/” + jobCardName + “/complete_job”;
http.begin(url);
http.addHeader(“Content-Type”, “application/json”);
http.addHeader(“Authorization”, "token " + String(apiKey) + “:” + String(apiSecret));
// Sending a POST request to complete the Job Card
int httpResponseCode = http.POST("");
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println("ERPNext response for completing Job Card:");
Serial.println(response);
} else {
Serial.println("HTTP Response Code: " + String(httpResponseCode));
Serial.println("Response: " + http.getString());
}
http.end();
}
}
ERPNext Response:
json
Copy
{
“exception”: “KeyError: ‘run_method’”,
“exc_type”: “KeyError”,
“exc”: [
“Traceback (most recent call last):\n File “apps/frappe/frappe/app.py”, line 114, in application\n response = frappe.api.handle(request)\n File “apps/frappe/frappe/api/init.py”, line 49, in handle\n data = endpoint(**arguments)\n File “apps/frappe/frappe/api/v1.py”, line 82, in execute_doc_method\n method = method or frappe.form_dict.pop(“run_method”)\nKeyError: ‘run_method’\n”
]
}
Question:
- Can someone explain how to properly start and complete a Job Card via the API?
- Is there an alternative way to perform these actions if these endpoints are not supported?
Thank you in advance for your help!