Approve Workflow action from API

I want to approve workflow through API but getting below error.

Code to approve Workflow Action:
header = {‘content-type’: ‘application/json’, ‘X-Frappe-CSRF-Token’: cookies[‘X-Frappe-CSRF-Token’]}
payload = json.dumps({‘doc’: ‘{“doctype”: “Expense Claim”, “name”: "’ + expense_id + ‘", “workflow_state”: "’+workflow_state+‘"}’,
‘action’: status})
response = requests.post(base_url + “/api/method/frappe.model.workflow.apply_workflow”, data=payload,
cookies=cookies, headers=header)
Workflow action is Approve/Rejected defined in workflow

Error:
frappe.model.workflow.WorkflowTransitionError: Not a valid Workflow Action.

Hmm :thinking: @Majid_Asghar,

Please try this.

payload = {
    "doc": {
        "doctype": "Expense Claim",
        "name": expense_id,
        "workflow_state": workflow_state
    },
    "action": status
}
payload_json = json.dumps(payload)

headers = {
    "Content-Type": "application/json",
    "X-Frappe-CSRF-Token": cookies.get("X-Frappe-CSRF-Token")
}

response = requests.post(
    base_url + "/api/method/frappe.model.workflow.apply_workflow",
    data=payload_json,
    cookies=cookies,
    headers=headers
)

# Print response content for debugging
print(response.content)

Thank You!