Hello,
Hi everyone, we already use JMWE, and we need to send a WebHook similar to the sending already available in automation, see attached how it is done in automations, we need to do it in the same way via JSON:
And we also need to know where we put the shipping data:
Web request URL*
Headers
HTTP method*
Web request body*
Custom data*
Something like:
{
"options": [
{
"value": "{{key}} {{summary}}",
"disabled": false
}
]
}
you can use a Build-your-own (JMWE app) post-function, and use the callRest filter: https://appfire.atlassian.net/wiki/spaces/JMWEC/pages/465242995/callRest
There are a few examples on that page, let me know if you need additional help.
Hello @David Fischer , thank you very much for your feedback,
I'm sorry for the lack of knowledge, but I'm still confused, in this case where I put the information is in the Post Function? where can I use this callReset to perform?
In this case, we have JIRA's own WebHook, but there is no place to put the Body information, etc...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
why would you need to put any code in a Jira webhook? What are you trying to achieve exactly? Or rather, when? Can you describe your use case?
"Sending a webhook call" (or rather "making a REST API call" would be the proper expression) is not at all related to Jira WebHooks, which are simply a way to react to internal Jiera events.
If you want to send the REST API call during a workflow transition, you'll need to add a Build-your-own (JMWE app) post-function to that transition. If you want to send the REST API call in response to another Jira event, you can add the Build-your-own (JMWE app) post-function to an Event-based Action.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @David Fischer thank you very much for your feedback, it was very useful,
I managed to make a query via test but I can't do the PUT, I tried something like this:
{{ "https://instancia.atlassian.net/rest/api/3/issue/TVS-4925" | callRest(
options = { "auth":
{"username" : "email",
"password": "password"
}
})
| dump(2)}}
{{ callRest(verb="PUT",
body={
"fields": {
"summary" : "TESTS"
}
}
But it didn't work!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Error:
There was an error during the rendering of your template
(string) TypeError: Cannot read properties of null (reading 'type')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
first of all, if you're trying to call your Jira instance, you should use the callJira filter, which will automatically authenticate you with Jira.
Then the syntax becomes:
{{ "/rest/api/3/issue/TVS-4925" | callJira(
verb="PUT",
body={
"fields": {
"summary" : "TESTS"
}
})
}}
And if you want to modify the current issue, you can do:
{{ "/rest/api/3/issue/:issuekey" | callJira(
verb="PUT",
params={issuekey:issue.key},
body={
"fields": {
"summary" : "TESTS"
}
})
}}
Please look at https://appfire.atlassian.net/wiki/spaces/JMWEC/pages/465243039/callJira for details.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
I think I'm eating cake on some information:
{{ "myinstance.atlassian.net/rest/api/2/issue/:TVS-4925" | callRest(
verb="PUT",
params={issuekey:issue.key},
body={
"fields": {
"summary" : "TESTS"
}
})
}}
It is showing an error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You're supposed to use my code as it is:
- the url starts with /rest
- :issuekey in the url should be left as is. It will be replaced at execution time by the value passed in the params attribute:
params:{issuekey:issue.key}
(notice that "issuekey" is the same in params and the url. You could use "foo" instead, it's just the name of the placeholder that callJira will replace automatically)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello, @David Fischer
I'm not really leaving the place, I'm putting it as you told me and it doesn't work, I don't know where I could be going wrong:
Error return:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to use callJira not callRest. In my initial response, I didn't know you were calling Jira not an external service, and then I forgot to replace the filter in the code snippet. Sorry about that.
I'm updating my previous response accordingly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @David Fischer
It worked very well here, thank you very much, can I take advantage of this channel and ask my next question?
In this case, for example, for me to push a value from one field to another via Rest:
In JSON in Body I do it like this:
But when I do it in Rest in JMWE, the same typed speech appears.
I tried something like this:
{{ "/rest/api/3/issue/:issuekey" | callJira(
verb="PUT",
params={issuekey:issue.key},
body={
"fields": {
"summary" : "{{issue.customfield_10039}} - {{issue.customfield_10040}}"
}
})
}}
It came back to me:
But it was supposed to return this value here + this:
Can you help me?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You cannot put a template expression inside a template expression. But you can use standard JavaScript syntax:
summary" : issue.customfield_10039 + " - " + issue.customfield_10040
Of course, that will only work if both fields are text or number fields. For other types, you'll need to use the "issue fields" help tab to figure out how to access a text property of the object representing the value. For example, if customfield_10039 is a Single User picker, you could use
issue.customfield_10039.displayName
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @David Fischer
It worked very well, I just put the parameter like this to accept it:
"summary" : issue.fields.customfield_10039 + " - " + issue.fields.customfield_10100
Now we can go to the 3rd step if we can:
{{ "/rest/api/3/field/customfield_11401/context/11568/option" | callJira(
verb="POST",
params={issuekey:issue.key},
body={
"options": [
{
"value": issue.fields.issuekey + "-" +issue.fields.summary,
"disabled": false
}
]
}
})
}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
But it is generating error:
There was an error during the rendering of your template
(string) TypeError: Cannot read properties of null (reading 'type')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try removing the params parameter, which you don't need for that call. Also, it looks like you have one too many }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @David Fischer
I tried to apply it like this:
{{ "/rest/api/3/field/customfield_11401/context/11568/option" | callJira(
verb="POST",
body={
"options": [
{
"value": issue.fields.issuekey + "-" +issue.fields.summary,
"disabled": false
}
]
}
But it's still returning an error, could it be that I'm still doing something wrong?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you're missing the closing ) and then }} at the end:
{{ "/rest/api/3/field/customfield_11401/context/11568/option" | callJira(
verb="POST",
body={
"options": [
{
"value": issue.fields.issuekey + "-" +issue.fields.summary,
"disabled": false
}
]
}
)
}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @David Fischer
Very good, the error no longer generated here, however, when I run the test and when I run the test on the function, it is also not imputing the information in the given URL:
It would look like this: When I click on "WebHook Tests"
Post-Function executes the script:
After executing it, it imputes the information in the context of the field!
And it's not imputing!
I think I must still be doing something wrong!
{{ "/rest/api/2/field/customfield_11401/context/11568/option" | callJira(
verbo="POST",
body={
"opções": [
{
"valor": issue.fields.issuekey + "-" +issue.fields.summary,
"disabled": false
}
]
}
)
}}
The value should appear here:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you have translated the code to Portuguese! You need to use English in the code (as I provided earlier)
Also, if you want to see the result of the REST call, you can add | dump(2) when you're testing in the tester:
{{ "/rest/api/3/field/customfield_11401/context/11568/option" | callJira(
verb="POST",
body={
"options": [
{
"value": issue.fields.issuekey + "-" +issue.fields.summary,
"disabled": false
}
]
}
) | dump(2)
}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @David Fischer
Wow, that was ugly, I'm sorry!!!! Really, I'm so crowded here that I didn't even notice!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @David Fischer
It worked perfectly here, thank you very much for your help, it was very useful!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @David Fischer ,
I'm facing a similar problem, and I was wondering if you could help me.
I'm transferring our Jira's "Web request" automation rules to JMWE.
As such I'm trying to build a post-function that will post HTTP request to an internal API endpoint.
Here is the code I got this far:
{# Set the URL of the API endpoint #}
{% set url = "https://mycompany/endpoint" %},
{# Set the headers for the request, including the auth token #}
{% set headers = {
"Content-Type": "application/json",
"Authorization": "Token mytoken"
} %}
{# Set the body of the request, using the issue data #}
{% set body = {
"issueKey": issue.key
} %}
{# Make the POST request and store the response #}
{% set response = url | callRest( verb = "POST", headers , body ) | dump(2) %}
However, I'm having trouble getting pasted the Authorization. I'm getting an error 403.
I've 2nd checked the token, and it works. I'm guessing it may be something linked to the plug-in syntax ?
Would you be able to help me out?
Thanks in advance!
Hugo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's probably because you need to use named parameters to the callRest filter, which you did for the "verb" parameter but not the others. You need "body=body,headers=headers"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@David Fischer Thanks for the quick response!
I updated the parameters as recommended:
{# Set the URL of the API endpoint #}
{% set url = "https://company/endpoint" %},
{# Set the headers for the request, including the auth token #}
{% set headers = {
"Content-Type": "application/json",
"Authorization": "Token abcdefg"
} %}
{# Set the body of the request, using the issue data #}
{% set body = {
"issueKey": issue.key
} %}
{# Make the POST request and store the response #}
{% set response = url | callRest( verb = "POST", headers = headers , body = body) | dump(2) %}
Unfortunately, I having the same error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There is actually no headers parameter to the callRest filter, did you check the documentation?
To pass a header value, you pass it in a headers attribute of the options parameter:
options={headers:headers}
You should also check this documentation: https://www.npmjs.com/package/request#http-authentication
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It worked! Thanks a lot for your help and your time
I did read the documentation, however, as I didn't use the named parameters you mentioned in your previous message, even putting the headers in the options did not work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.