Solved

Unsuccessfully trying to add work schedule using the API

  • 17 February 2023
  • 5 replies
  • 119 views

Userlevel 7
Badge +19
  • Sr. Karbon Community Guide
  • 1243 replies

issue

I get 4005 (when I modify the structure) or 5001 (when I run according to documentation) when trying to add a work schedule via POST request.

details

The documentation seems a little light (didn’t include a few fields I thought would be necessary), and I’m getting an internal server error whenever I try to add a work schedule.

I performed a GET request on an existing work schedule I want to repeat. I am using the values from that get to populate my template POST request.

troubleshooting

  • After my first attempts didn’t work, I added WorkItemTitleDisplayText and AssigneeUserKey. They are not added in the documentation, but perhaps they must be added/updated via PUT once the schedule creates.
  • I noticed that the GET request returns a JSON element as a string. I de-escaped it to see if the API expected JSON instead of a string coming back, but I got a 4005 error.
  • The offset integer for the variable portion was passed as a string in the GET request but as an integer in the text portion, so I tried it as an integer. No luck.
  • I noticed the date for ending had a strange format from the GET request, so I tried “forever” and “Forever” to match the web app. Got a 4005 error.
  • Adding a real date to the end date field resulted in the same 5001 error from before.
  • I noticed that the work item key from the GET request was null. I don’t have a way to play around with that since there’s no other way to specify which work item gets the schedule, as far as I can tell. I thought it was odd.

I’m not sure what I’m missing

See here for code walls:

 Here’s my body:

{
"CreatedFromWorkItemKey": "3PNmk5cmNv8",
"RecurrenceFrequency": "Year",
"CustomFrequencyMultiple": 1,
"ScheduleStartDate": "2023-01-01",
"AssigneeUserKey": "4vD6m5Q9MdyP",
"WorkItemTitleDisplayText": "{Previous Repeat Period Date (YYYY - YYYY)} Form 1120 Corporate Income Tax Return",
"ScheduleDueDateMethod": "Day of (2nd, 3rd, ...) month after start month",
"PreventStartEndOnWeekend": false,
"InitializeTasksBeforeStartDateUnits": "Months",
"InitializeTasksBeforeStartDateMultiple": 3,
"WorkItemTitleDefinition": "[{\"Text\":null,\"Variable\":\"RepeatPeriod\",\"Offset\":\"-1\",\"Format\":\"YYYY - YYYY\"},{\"Text\":\" Form 1120 Corporate Income Tax Return\",\"Variable\":null,\"Offset\":0,\"Format\":null}]",
"CustomFrequencyUnits": "Months",
"ScheduleEndDate": "2027-01-01",
"ScheduleDueDateDays": 15,
"ScheduleDueDateMonthMultiple": 3,
"InitializeBeforeStartDateUnits": "Months",
"InitializeBeforeStartDateMultiple": 3
}

Here’s the response:

{
"error": {
"code": "5001",
"message": "Unexpected Internal Error. Please contact Karbon HQ Technical support with API Request Id of **masked**."
}
}

If I change ScheduleEndDate from "0001-01-01T00:00:00Z" to “Forever”, I get:

{
"error": {
"code": "4005",
"message": "Required payload data is missing: workSchedule"
}
}

Changing it to an actual date returns the 5001 error.

WorkItemTitleDefinition field passes a JSON element as a string when performing the GET request, so that’s my initial focus for troubleshooting. I de-escaped all the quotes to get it back to JSON and tried to submit but got the 4005 error.

{
"CreatedFromWorkItemKey": "3PNmk5cmNv8",
"RecurrenceFrequency": "Year",
"CustomFrequencyMultiple": 1,
"ScheduleStartDate": "2023-01-01",
"AssigneeUserKey": "4vD6m5Q9MdyP",
"WorkItemTitleDisplayText": "{Previous Repeat Period Date (YYYY - YYYY)} Form 1120 Corporate Income Tax Return",
"ScheduleDueDateMethod": "Day of (2nd, 3rd, ...) month after start month",
"PreventStartEndOnWeekend": false,
"InitializeTasksBeforeStartDateUnits": "Months",
"InitializeTasksBeforeStartDateMultiple": 3,
"WorkItemTitleDefinition": [
{
"Text":null,
"Variable":"RepeatPeriod",
"Offset":-1,
"Format":"YYYY - YYYY"},
{
"Text":" Form 1120 Corporate Income Tax Return",
"Variable":null,
"Offset":0,
"Format":null
}
],
"CustomFrequencyUnits": "Months",
"ScheduleEndDate": "0001-01-01T00:00:00Z",
"ScheduleDueDateDays": 15,
"ScheduleDueDateMonthMultiple": 3,
"InitializeBeforeStartDateUnits": "Months",
"InitializeBeforeStartDateMultiple": 3
}

I tried the “-1” offset in and out of quotes. Same 4005 error.

I tried running it without the assignee and description text fields. Same 4005 error.

 

icon

Best answer by StuartK 19 February 2023, 21:17

View original

5 replies

Userlevel 4
Badge +5

I am sorry I cannot help with the above.  I am actually hoping you may be able to help me with something.  

I love your postings on the Karbon Community boards.  I am an IPM user, which is still Karbon.  It turns out that IPM populates all of your tax jobs with no staff assignments to the role assignee.  Also, Intuit does not allow Excel bulk download and upload of these fields like Karbon does. 

I have used Pipedream and connected via API Karbon and Python.  I don't suppose you have ever written a Python script that would let me accomplish assigning all roes for tax jobs containing 2022 in the work title to:something like the following:

Admin on all work Admin roles = Joe

Partner on all work partner roles = John

Reviewer on all work Reviewer roles = Mary

Preparer on all work Preparer roles = Tom

 

I have 500+ jobs, so doing this manually will kill my tax season.  Any guidance would be great. 

 

Thanks,

Tom

 

PS, keep up the great work!

Userlevel 3
Badge +2

Hi @max - a couple of things here that stand out:

  • "WorkItemTitleDefinition" definitely needs to be an escaped JSON string (like your first example) - it’s not ideal, but its how it is at the moment
  • It looks like you’ve specified both a yearly and monthly repeat shedule?
    "CustomFrequencyUnits": "Months",
    "RecurrenceFrequency": "Year",

See below for a snippet I’ve used just now to ceate a repeating WorkSchedule to a Workitem:

 

{
"CreatedFromWorkItemKey": "4sxjjjxDqYRY",
"RecurrenceFrequency": "Year",
"CustomFrequencyMultiple": 1,
"ScheduleStartDate": "2023-02-01",
"ScheduleEndDate": "2024-03-01",
"ScheduleDueDateMethod": "DaysFromStartDate",
"ScheduleDueDateDays": 7,
"ScheduleDueDateMonthMultiple": 3,
"PreventStartEndOnWeekend": true,
"InitializeBeforeStartDateUnits": "Days",
"InitializeBeforeStartDateMultiple": 3,
"InitializeTasksBeforeStartDateUnits": "Days",
"InitializeTasksBeforeStartDateMultiple": 3,
"WorkItemTitleDefinition": "[{\"Text\":\"Payroll\",\"Variable\":null,\"Format\":null,\"Offset\":0},{\"Text\":null,\"Variable\":\"RepeatPeriod\",\"Format\":\"DD MMM, YYYY - DD MMM, YYYY\",\"Offset\":0}]"
}

 

Userlevel 7
Badge +19

Hi @Tom Kneeland, that’s a great question!

I picked it up on a new post:

 

Userlevel 7
Badge +19

Thanks @StuartK, I’ll test this.

Hi @max - a couple of things here that stand out:

  • "WorkItemTitleDefinition" definitely needs to be an escaped JSON string (like your first example) - it’s not ideal, but its how it is at the moment

I figured. Works for me. 😊

  • It looks like you’ve specified both a yearly and monthly repeat shedule?
    "CustomFrequencyUnits": "Months",
    "RecurrenceFrequency": "Year",

That’s how it’s represented in the docs:

And when I did a GET request on a prototypical work schedule, I got the two different frequencies represented:

I thought it was confusing.

 

Userlevel 7
Badge +19

I don’t know how I messed it up, but what you put here matches what’s in Postman by default and worked as expected.

 

{
"CreatedFromWorkItemKey": "4sxjjjxDqYRY",
"RecurrenceFrequency": "Year",
"CustomFrequencyMultiple": 1,
"ScheduleStartDate": "2023-02-01",
"ScheduleEndDate": "2024-03-01",
"ScheduleDueDateMethod": "DaysFromStartDate",
"ScheduleDueDateDays": 7,
"ScheduleDueDateMonthMultiple": 3,
"PreventStartEndOnWeekend": true,
"InitializeBeforeStartDateUnits": "Days",
"InitializeBeforeStartDateMultiple": 3,
"InitializeTasksBeforeStartDateUnits": "Days",
"InitializeTasksBeforeStartDateMultiple": 3,
"WorkItemTitleDefinition": "[{\"Text\":\"Payroll\",\"Variable\":null,\"Format\":null,\"Offset\":0},{\"Text\":null,\"Variable\":\"RepeatPeriod\",\"Format\":\"DD MMM, YYYY - DD MMM, YYYY\",\"Offset\":0}]"
}

 

A few observed peculiarities:

  • PUT doesn’t seem to work
    • GET KEY returns existing work schedule
    • PUT same KEY returns a 4004 Not Found message
  • POST seems to overwrite existing work schedule, so works like a PUT for my uses, however:
    • this creates an additional work schedule
    • the old work schedule still exists
    • the old work schedules are unattached to work but accessible in the app via url key and GET request. useless artifacts.
    • i need to do more testing, but it seems like any past incomplete work sticks to the old work schedule (I’m curious if the artifact work schedules will recur in some way. i will test)
  • In all cases, the “CreatedFromWorkItemKey” is null, when returned from a POST or GET request.
  • Adding "AssigneeUserKey": "MYKEY” to POST doesn’t throw an error, but also doesn’t impact the work schedule assigned user.
    • It seems like the assignee of the work at the time of work schedule creation is the work schedule assignee in all cases
  • there’s a limit to the number of past items karbon will allow you to create through the web app
    • the same restriction does not apply when adding via API (this opens the possibility that an inadvertent date when creating a work schedule could result in an assumed infinite number of work items)
    • too many past work items created by the work schedule seems to cause an error when updating a work schedule when attempting to make changes to the work schedule through the web app. the schedule will not save, throws no errors, and reverts on refresh.
    • since we cannot PUT, i’m left to POST a new work schedule
    • I’ll test the outcome of creating a second work schedule with many past items. i am betting the past work items from the first work schedule stick around and the new work schedule will make duplicate ones

Other observations:

  • Leaving out the “ScheduleEndDate” key and value results in a forever end date (this is expected and preferrable behavior)

that’s all for now, i guess. i plan to put my findings together in a community post, if that’s okay, so others can use the work schedule API well. i think it’s a powerful addition to the functionality. i plan to use it to automatically apply work schedules to certain work types. i’ll make a post about that as well once i have it working.

Reply