I am trying to write a simple script that posts worklogs for users based at data in another system. So we have an app that I read from each morning. Each record pertains to a user so I want to post a worklog item for those users daily. I'm using the API and a python script. Following the examples, I have it posting for me, but I can't get it to post for others. The documentation says it can, but I can't seem to find the right structure for the payload
payload = json.dumps( {
"timeSpentSeconds": 10000,
"author": {"name":"John Smith"},
"comment": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "I did no work for this.",
"type": "text"
}
]
}
]
},
"started": "2022-04-22T18:34:00.000+0000"
} )
No matter what format I use for author name it ignores the element and posts as me. What am I doing wrong?
Hi Tim,
You may try to create simple atlassian-connect app for this, install it as private app, and then write script to log work for other user, like this:
const addonHttpClient = addon.httpClient({ clientKey: req.context.clientKey })
const httpClient = addonHttpClient.asUserByAccountId(req.body.user) // logForOther
httpClient.post(...
Note, it will be possible to log work via api with Timesheet Reports and Gadgets soon too, see https://primetimesheet.atlassian.net/wiki/spaces/KB/blog/2019/03/12/575406081/Log+Work+for+Others+for+Timesheet+Reports+and+Gadgets+only also.
Thank you.
Hi Andriy,
Can you expand on your answer for me please? I can see that you create the httpclient, but where does req.context.clientkey come from? Is that my API key (<<key>> in my sample below)?
import requests
from requests.auth import HTTPBasicAuth
import json
url = "https://domain.atlassian.net/rest/api/3/issue/TSK-999/worklog"
auth = HTTPBasicAuth("tim@domain.com", "<<key>>")
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
payload = json.dumps( {
"timeSpentSeconds": 10000,
"author": {"name":"John Smith"},
"comment": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "I did no work here.",
"type": "text"
}
]
}
]
},
"started": "2022-04-22T18:34:00.000+0000"
} )
response = requests.request(
"POST",
url,
data=payload,
headers=headers,
auth=auth
)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry for confusion, It has to be part of atlassian-connect, here is code around it:
const express = require('express')
const app = express()
const ac = require('atlassian-connect-express')
const plugin = ac(express(), null, null, () => {
const schema = require('../app/models')(app, plugin)
const Configuration = schema.models.Configuration
const promise = logWork('7283b385-42ea-3550-ae3f-9cb9ca445ad0', '5e29a79aadb9030e6a441d2b')
}
const logWork = (clientKey, userAccountId) => {
var addonHttpClient = plugin.httpClient({ clientKey: clientKey })
var httpClient = addonHttpClient.asUserByAccountId(userAccountId)
...
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tim,
It's now possible to Log Work for Other user with the Timesheet Reports and Gadgets REST API, please see https://bitbucket.org/tempo-io/servertimesheet/wiki/cloud/REST%20endpoint#markdown-header-logging-work-for-other-user
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Tim Foster ,
in JIRA you can't log work for others using builtin feature (https://jira.atlassian.com/browse/JRACLOUD-1676). You need to use Tempo Plugin in order to add this capability https://marketplace.atlassian.com/apps/6572/tempo-timesheets-jira-time-tracking?tab=overview&hosting=cloud
Moreover, Tempo Rest APIs provide you the ability to add worklog for others https://apidocs.tempo.io/#worklogs
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for this Fabio,
If the tempo plugin is able to do this, and it's using the Jira API, can we not do the same thing with a call to the API, essentially a plugin of our own?
We already have a timesheet plugin that we've spend ages getting our users to work with. The only feature we'd gain from Tempo would be the ability to log on behalf of others so the cost outweighs the benefit for us.
The attached python script posts, but as the user making the API call. I guess I could make the api call as an admin, assign relevant permissions to the user I want to log for, reconnect to the api as them, log the worklog, then reconnect as the admin and drop their permissions. It's a very hacky approach though, and my understanding was that the API allowed this. I accept that this isn't possible through the interface.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tim Foster , I understand your point of view but, unfortunately, builtin Rest API does not provide this capability.
There's an open request for that https://jira.atlassian.com/browse/JRACLOUD-30197
Please vote and watch that ticket.
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.