Skip to main content
Solved

Creating TimeEntry via API


Forum|alt.badge.img

I have this call:

###

PUT {{url}}/entity/Default/22.200.001/TimeEntry

Authorization: Bearer {{authToken}}

Content-Type: application/json

 

{

  "Summary" : {"value" : "Time entry summary"},

  "Date" : {"value" : "2024-08-29T09:00:00" },

  "Employee" : {"value" : "EMP001" },

  "ProjectID" : {"value" : "CA.1001" },

  "ProjectTaskID" : {"value" : "ANNUAL PAID" },

  "EarningType" : {"value" : "VL" },

  "TimeSpent" : {"value" : "08:00" }

}

 

The response comes back with an error (shortened):

{ "id": "5fd70d80-0b66-ef11-96a7-00155dc9a206", "rowNumber": 1, "note": { "value": "" }, "error": "Inserting 'Time Activity' record raised at least one error. Please review the errors.",

"Employee": { "value": "EMP001", "error": "Employee 'EMP001' cannot be found in the system." },

 

Now, ‘EMP001’ definitely exists and is ‘Active”. I have even tried add the user to the “Administrator” role, but I still get the error.

 

Any ideas would be appreciated.

Best answer by ebenroux

It turns out that there are a couple of ways to capture time on behalf of someone else.  However, both depend on an employee which means that, in my case anyway, even though I’m using a “system user” I would still need to create an employee to link to that user.

The first way is to use the “Company Tree”.  Any employees below my system employee would show up as selectable in the time entry employee list.  There doesn’t appear to be a way to manage the company tree using the API, though.

This brings up the other way, which is to add the system employee as a delegate to each other employee.  The delegate *can* be set via the API so this is what we are going with for now.

View original
Did this topic help you find an answer to your question?

14 replies

Nilkanth Dipak
Jr Varsity III
Forum|alt.badge.img+7

Hi @ebenroux,

Are you able to create time Activity on screen level by providing those details only?
Is the employee has  access to that Particular project?
 


Forum|alt.badge.img
  • Author
  • Freshman II
  • 10 replies
  • August 30, 2024

Hi @Dipak Nilkanth,

I logged in using the automation user and on the “Employee Time Cards” screen I do not see any employees.  Come to think of it, when I log in with my own user (and I’m in the administrator role) I can only see myself.

Is there a way to give a particular user access to capture time cards for anyone (which is what I need to automate)?

 


Forum|alt.badge.img+7
  • Captain II
  • 295 replies
  • August 30, 2024

HI @ebenroux 

 

I stumbled into an issue with this, not through an API, but it turned out to be a simple tickbox: 

if you look at the source code for the AMClockItem EmployeeID and the ProductionEmployeeAttribute source code, you will see that this tickbox is needed.

As I am sure you know, you will need to use the Production Employee details to log in with the API.

 

Hope this helps!

Aleks 


Forum|alt.badge.img
  • Author
  • Freshman II
  • 10 replies
  • August 30, 2024

Hi Aleks @aiwan,

 

Thanks for the feedback.  Oddly enough, I do not have that check-box on my employee (and I’m an admin):

 

 

Could be that our company does not have, or use, the module.  Or it could be permissions.  Since I am a developer I have no experience in Acumatica itself so I may simply be missing something.  That being said, my aim is to use a system account of sorts.  There will be a login (called “Automation”) with its own role along with permissions.  The “Automation” user isn’t an employee at all, though.  I do need that user to be able to do all manner of things such as create employees, projects, and register time entries for any arbitrary employee (for leave / public holidays).

I’ll keep digging...

 

Regards,

Eben 


Forum|alt.badge.img+7
  • Captain II
  • 295 replies
  • August 30, 2024

Hi @ebenroux,

 

Do you use the manufacturing module? If not then that tickbox wont be there.

 

From the API call it looks like youre using a project module screen, we don’t use that module but I will dig a bit in the source code to see if there’s anything there, before I do that, could you share the ScreenID/Name please?

 

Aleks


Forum|alt.badge.img
  • Author
  • Freshman II
  • 10 replies
  • August 30, 2024

Hi Aleks,

 

Thanks for the assistance…

 

Here is the screen I’m after:

 

 

When I click on the “Employee” search it only lists me (for my “Automation” user no-one shows up):

 

 

Hopefully that helps :)

 

Regards,

Eben


Forum|alt.badge.img
  • Author
  • Freshman II
  • 10 replies
  • August 30, 2024

By the way, we do not use the manufacturing module AFAIK.


Forum|alt.badge.img+7
  • Captain II
  • 295 replies
  • August 31, 2024

Hi @ebenroux 

 

i believe the attribute which is linked to this selector limits you to only pick the user that is logged in.

you could use a cache attached event to remove the attribute and use your own pxselector however I am not 100% sure if this will affect functionality 

 

Aleks 


Forum|alt.badge.img+7
  • Captain II
  • 295 replies
  • September 2, 2024

Hi @ebenroux 

 

I can confirm this is because of the attribute within the Selector, it has a join between CREmployee.userID & Users.pKID. Therefore with this attribute you will be unable to pick another user.

 

When using the API, you will have to log in as the user which wants to record the time, or you can write your own attribute for the field which allows the “Automation” user to log in as anyone.

 

hope this helps!

Aleks


Forum|alt.badge.img
  • Author
  • Freshman II
  • 10 replies
  • September 2, 2024

@aiwan 

Hi Aleks,

 

Thanks a stack for all the info.  From the UI it is possible to impersonate someone using the ”SIGN IN AS USER” functionality.  However, I have no idea how one would do this using the API.  According to this post, and also my other question, it doesn’t seem as though there is anything available related to users via the API.

“...or you can write your own attribute for the field which allows the “Automation” user to log in as anyone”.  I have no idea how to do this.  We have a meeting this Wednesday with our Acumatica partner so perhaps they can guide us.  

 

Regards,

Eben

 


Forum|alt.badge.img+7
  • Captain II
  • 295 replies
  • September 2, 2024

Hi @ebenroux,

 

No problem, glad I could help.

I have a hunch that you would have to extend the default endpoint to include the Users Screen, I’m no guru with API’s, I can just about use Postman…

As the sys admin, is there a way for you to distinguish the users in the API?

This means no messing around with logging in as one user and changing to another, and changing attributes on fields.

 

Aleks


Forum|alt.badge.img
  • Author
  • Freshman II
  • 10 replies
  • September 2, 2024

Hi @aiwan,

I’d like to avoid extending anything if at all possible.  We have multiple tenants and I assume that each would need this extension.  I guess, as a last resort, it is something we may need to consider.

As for the sys admin side of things, there doesn’t appear to be a way to specify a user in the API… which is what I think you are asking.  One can specify things such as employees, but in the case of the time entry specifying an employee other than the logged-on one doesn’t work --- as has been established.

There are a number of ways to obtain a session to Acumatica.  One way is to log in as a user.  For that you’d need the actual user’s credentials.  Since we are wanting to create entries for arbitrary employees this will not work.  We integrate using Azure AD (Entra) so we wouldn’t have access to passwords (which is a bad idea in any event).  What I’m doing to logging on using the Resource Owner Password Credentials flow of the OAuth implementation.  However, that still represents a specific user, albeit a system user called “Automation”.

It seems as though, if the restriction in the system is that only the logged-on user can capture time entries for themself, that impersonation via the API is the only other option.

Anyway, I’ll see what the partner comes up with.  Thanks again for your interest.

Regards,

Eben


Forum|alt.badge.img
  • Author
  • Freshman II
  • 10 replies
  • Answer
  • September 4, 2024

It turns out that there are a couple of ways to capture time on behalf of someone else.  However, both depend on an employee which means that, in my case anyway, even though I’m using a “system user” I would still need to create an employee to link to that user.

The first way is to use the “Company Tree”.  Any employees below my system employee would show up as selectable in the time entry employee list.  There doesn’t appear to be a way to manage the company tree using the API, though.

This brings up the other way, which is to add the system employee as a delegate to each other employee.  The delegate *can* be set via the API so this is what we are going with for now.


Forum|alt.badge.img+7
  • Captain II
  • 295 replies
  • September 4, 2024

Thanks for the update @ebenroux 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings