IBM Support

"Invalid or unacceptable JSON format" when scheduling job through API

Troubleshooting


Problem

I have code like this:
import os
import requests
from project_lib import Project
project = Project.access()
token = os.environ['USER_ACCESS_TOKEN']

project_id='9ac7f0d7-fe62-4ee8-9586-1b13711e6922'
job_id='b0b7dcfb-8f77-499a-a844-38419d524719'

header={'Authorization':'Bearer ' + token, 'Content-Type':'application/json'}
params={'job_id':job_id,'project_id':project_id}

url_connection='https://***/v2/jobs/'; + job_id + '?project_id=' + project_id
get_info_jobs=requests.get(url_connection,headers=header,verify=False)

current_time=get_info_jobs.json()['entity']['job']['schedule']

print(current_time)
0 10 * * *

cron_sched=current_time.split(' ')
new_hour=str(int(current_time.split(' ')[1])-1)
cron_sched[1]=new_hour
updated_time=\" \".join(cron_sched)

print(updated_time)
0 9 * * *

payload='{\"op\":\"replace\", \"path\":\"/metadata/name\",\"value\":\"test job\"}'
test=requests.patch(url_connection,data=payload,headers=header,verify=False)

print(test.json())

{'code': 400, 'error': 'Bad Request', 'reason': \"Invalid or unacceptable JSON format provided for 'body'\", 'message': 'The server cannot or will not process the request due to an apparent client error (e.g. malformed request syntax).'}

Symptom

I get error 400:
{'code': 400, 'error': 'Bad Request', 'reason': \"Invalid or unacceptable JSON format provided for 'body'\", 'message': 'The server cannot or will not process the request due to an apparent client error (e.g. malformed request syntax).'}

Document Location

Worldwide

[{"Type":"MASTER","Line of Business":{"code":"LOB76","label":"Data Platform"},"Business Unit":{"code":"BU048","label":"IBM Software"},"Product":{"code":"SSHGYS","label":"IBM Cloud Pak for Data"},"ARM Category":[{"code":"a8m0z000000GoylAAC","label":"Troubleshooting"}],"ARM Case Number":"TS011248900","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions"}]

Log InLog in to view more of this document

This document has the abstract of a technical article that is available to authorized users once you have logged on. Please use Log in button above to access the full document. After log in, if you do not have the right authorization for this document, there will be instructions on what to do next.

Document Information

Modified date:
30 November 2022

UID

ibm16842535