Python - Wrike API. Creating new tasks (HELP)
Hi,
I am trying to use python to create new tasks in Wrike. I am able to do this successfully but only for very basic fields such as title, description, and status. I am having trouble setting sub dicts, for example {"dates":{"start":"YYYY-MM-DD"}. Here's a sample of my code. When I try to add information for start and due dates I get status code 400.
def main():
folderId = "folderIDnumber"
headers = {'authorization': "bearer my_token_key"}
url = "https://www.wrike.com/api/v3"
data = formWrikeTaskJson(title="new task",
description="some details",
status=postStatus)
rPost = post2wrike(folderId,headers,url,data)
print rPost.status_code
def formWrikeTaskJson(title="New Task",description="",status="Active",customStatusId='',
starttime=datetime.datetime.today().strftime('%Y-%m-%d'),
endtime = datetime.datetime.today().strftime('%Y-%m-%d')):
data = {}
data["title"]=title
data["description"]=description
data["status"]=status
#data["dates"]={"start":starttime} this part does not work!
#data = json.dumps(data) neither does doing this in general
return data
def post2wrike(folderId,headers,url,json):
url = url+"/folders/{}/tasks".format(folderId)
rPost = requests.post(url, headers=headers,data=json)
return rPost
Any update on this? I'm having the same problem. Here is what I'm sending:
{"title": "This is a test 3", "description": "Description Test", "customStatus": "IEAB4DUKJMALDX2Q", "dates": {"type": "Milestone", "due": "2018-11-30"}}
I get the following error:
{'errorDescription': "Parameter 'dates' value is invalid", 'error': 'invalid_parameter'}
@Doug Hey, thanks for posting 🙂
I've raised a Support ticket for you, someone from the team will help you with this 👍
Lisa Community Team at Wrike Wrike Product Manager Become a Wrike expert with Wrike Discover
Lisa Wrike Team member Become a Wrike expert with Wrike Discover
Has there been an update on this? I can't find the support ticket that was supposedly created. I get the same error, except I'm trying to set the responsibles field as laid out in the task v4 api.
Hi Chad,
Here is what I did when updating the date for a task to set the start time. I'm using the arrow package for the dates. Hopes this helps.
Hi Doug,
Did you ever try to set the responsibles field?
I basically have the following:
task = {'title':'test', 'description':'test task','status':'Active','importance':'High','responsibles':["BOGUSIDHERE"]}
response = requests.request("POST", url, data=task, headers=header)
Now without the responsibles field in the task, it posts just fine. With it I get:
response.json()
{'errorDescription': "Parameter 'responsibles' value is invalid", 'error': 'invalid_parameter'}
I actually was able to figure it out like this:
responsibles = json.dumps(["{0}".format(k)]) # here k is the id of the person responsible
task = {'title':title, 'description':description,'status':'Active','importance':imp,'responsibles':responsibles}
requests.request("POST", url, data=task, headers=header)