Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Help needed with The Automation REST API's

Peter Rossum_ van
Contributor
March 19, 2026

I try to create a Automation Rule with the REST API's
The Automation REST API
Getting an existing (example) rule by UID works fine using a personal API token as OAth2 or scoped does not work. But, okay with a personal token I can go on.
So, using the data from that example rule I try te create a new rule.
However I get the "bad request' error.
Before I copy the whole body in here, are there any simple things I can check?
The questions hat come to my mind are:
Should I pass optional properties as null values or empty arrays, or can I simply leave them out?
And should I also add a new UID for the new rule, or is that created when posting?
For the example rule that I use to copy, there are no connections used for the components. Is that okay?
Is de order of the properties an issue? Is is essential that those properties are like the documenation os the API?
So....
Is there anyone that has some expirence with creating an Automation Rule using this API?

2 answers

1 accepted

0 votes
Answer accepted
Marc -Devoteam-
Community Champion
March 20, 2026

Hi @Peter Rossum_ van 

Can you show the full rule and in details alls ateps in your rule.

Also show the audit log, what is that revieling.

Also what API cal you using, not al API endpoints can be used. Using a scoped token requires right permissions and scopes.

 

Peter Rossum_ van
Contributor
March 24, 2026

Marc,
Thanks for the response.
Here is my info.

I first retreive an example rule (that is present in Confluence) with this endpoint:

https://api.atlassian.com/automation/public/confluence/$($cloudID)/rest/v1/rule/$($ruleId)

That works fine

I use this endpoint to post a new rule:

https://api.atlassian.com/automation/public/confluence/$($cloudID)/rest/v1/rule

I created the body by copying it from the example rule and changed a few things regarding the ruleScopeARIs.

Finaly I POST this body:
(I initialy set the rule on DISABLED to prevent inmediate executing)

{
"connections": [],
"rule": {
"authorAccountId": "<copy-from-example>",
"actor": {
"type": "ACCOUNT_ID",
"actor": "<copy-from-example>"
},
"notifyOnError": "FIRSTERROR",
"labels": [],
"trigger": {
"component": "TRIGGER",
"schemaVersion": 1,
"type": "confluence.page-updated.trigger",
"value": {
"eventFilters": [
"ari:cloud:confluence:$($cloudID):space/<TargetSpaceID>"
],
"enableAdminKey": false
},
"connectionId": null,
"conditions": []
},
"uuid": "<new-UUID>",
"state": "DISABLED",
"description": "This rule sets the page status to 'Rough draft' when a page is updated and has no status.",
"ruleScopeARIs": [
"ari:cloud:confluence:$($cloudID):space/<TargetSpaceID>"
],
"collaborators": [],
"components": [
{
"component": "CONDITION",
"schemaVersion": 1,
"type": "platform.comparator.condition",
"value": {
"first": "{{page.status}}",
"second": "",
"operator": "EQUALS"
},
"connectionId": null,
"conditions": [],
"parentId": null,
"conditionParentId": null,
"children": []
},
{
"component": "ACTION",
"schemaVersion": -1,
"type": "confluence.change-page-status.action",
"value": {
"pageStatus": {
"color": "#ffc400",
"id": "5017600463",
"label": "Rough draft"
}
},
"connectionId": null,
"conditions": [],
"parentId": null,
"conditionParentId": null,
"children": []
}
],
"name": "Test rule PvR",
"writeAccessType": "OWNER_ONLY",
"canOtherRuleTrigger": false
}
}
The result is:

{ "timestamp": "2026-03-24T10:40:50.423\u002B00:00", "status": 400, "error": "Bad Request", "path": "/pro/public/rest/v1/rule" }

 

Marc -Devoteam-
Community Champion
March 24, 2026

Hi @Peter Rossum_ van 

Did you replace {cloudid} with your cloudid, gotten via using "https://your-site-name.atlassian.net/_edge/tenant_info"

Peter Rossum_ van
Contributor
March 24, 2026

Yes I did.
The API to get the example Rule from Confluence works.
But the API to create a new one does not work.

Marc -Devoteam-
Community Champion
March 24, 2026

Hi @Peter Rossum_ van 

Do you get the same error on setting the rule ENABLED?

 

Peter Rossum_ van
Contributor
March 24, 2026

Hi @Marc -Devoteam- 
Thanks for helping.
Yes, I got same error
It bothers me that the path that is mentioned in the "bad request" result is different then the endpoint iI use. What does that mean?

Marc -Devoteam-
Community Champion
March 24, 2026

Hi @Peter Rossum_ van 

I assume you set the space id as well.

I don't get this error as well, I can't find anything on this as well.

What if you use the get call and use that information to create a duplicate like rule on another space, does this work?

 

Peter Rossum_ van
Contributor
March 25, 2026

@Marc -Devoteam- ,

I really appreciate your help, man.
Your suggestion to use the get call is exactly what i do.
I replace certain parts and remove parts that are not needed.
I use a PowerShell Script to achieve this.
CloudID en SpaceID are replaced correct.
This is my coding:

$url = "https://api.atlassian.com/automation/public/confluence/$($cloudID)/rest/v1/rule/$($ruleId)"

# -----------------------------

# Get the existing rule configuration

$response = Invoke-RestMethod -Method Get -Uri $url -Headers $AuthHeader

# This works great!

# -----------------------------

$rule = $response.rule

$rule.trigger.value.eventFilters

# -----------------------------

$newRuleScopeARIs = @("ari:cloud:confluence:$($cloudID):space/262145")

$newRuleTrigger = $rule.trigger

$newRuleTrigger.value.eventFilters = $newRuleScopeARIs

$newRuleTrigger.PSObject.properties.remove('id')    # Remove the existing id property

$newRuleComponents = $rule.components

foreach ($component in $newRuleComponents) {

  $component.PSObject.properties.remove('id')       # Remove the existing id property

}

$newUUID = ([guid]::NewGuid()).ToString()

$newRuleData = @{

    "name" = "Test rule PvR"

    "actor" = $rule.actor

    "authorAccountId" = $rule.authorAccountId

    "canOtherRuleTrigger" = $rule.canOtherRuleTrigger

    "collaborators" = $rule.collaborators

    "components" = $rule.components

    "description" = $rule.description

    "labels" = $rule.labels

    "notifyOnError" = $rule.notifyOnError

    "state" = "DISABLED"

    "trigger" = $rule.trigger

    "writeAccessType" = $rule.writeAccessType

    "ruleScopeARIs" = $newRuleScopeARIs

    "uuid" = $newUUID

    }

$body = @{

    "rule" = $newRuleData

    "connections" = @()

} | ConvertTo-Json -Depth 5

$url = "https://api.atlassian.com/automation/public/confluence/$($cloudID)/rest/v1/rule"

$response = Invoke-RestMethod -Method Post -Uri $url -Body $body -Headers $AuthHeader
#
# Bad request

 

Marc -Devoteam-
Community Champion
March 25, 2026

Hi @Peter Rossum_ van 

Can you remove the UUID part and the user how executes this in power shell, does this user have permissions in Confluence and space permissions?

 

Peter Rossum_ van
Contributor
March 25, 2026

@Marc -Devoteam- 
I have admin permissions to both the source as well as the destination space.
Removing de UUID part does not help. Still error.
Question...
Is the ID of the Status I use for every space the same?
I use the default Status 'Rough draft'.
But I am not sure if that has the same ID for all spaces.

Marc -Devoteam-
Community Champion
March 25, 2026

Hi @Peter Rossum_ van 

This indeed differs per space.

I checked to spaces and ID's indeed differ.

So to make sure to create a rule with this action, you would first need to get the status id from the space.

Use; /wiki/rest/api/space/<spake-key>/state to get the id's of the statuses per space.

Like Bill Sheboy likes this
Peter Rossum_ van
Contributor
April 1, 2026

Hi @Marc -Devoteam- ,
Here is an update.
Still still "Bad request" :-(

I used the /wiki/rest/api/space/<spake-key>/state endpoint to get the id's of the available statuses of the space i want to create the rule in.
This is that list:

Statuses for space "DS":

id name color
-- ---- -----
0 Rough draft #ffc400
1 In progress #2684ff
2 Ready for review #57d9a3
3 Verified #1d7afc

It seems strange, but that space is probably the first that was created in my environment. But okay, I use StatusID "0".
This is the final REST API body I used:

 

{
"connections": [],
"rule": {
"name": "Test rule PvR",
"actor": {
"type": "ACCOUNT_ID",
"actor": "5eff44013bfa9f0bb09659a8"
},
"labels": [],
"components": [
{
"component": "CONDITION",
"schemaVersion": 1,
"type": "platform.comparator.condition",
"value": {
"first": "{{page.status}}",
"second": "",
"operator": "EQUALS"
},
"connectionId": null,
"conditions": [],
"parentId": null,
"conditionParentId": null,
"children": []
},
{
"component": "ACTION",
"schemaVersion": -1,
"type": "confluence.change-page-status.action",
"value": {
"pageStatus": {
"color": "#ffc400",
"id": "0",
"label": "Rough draft"
}
},
"connectionId": null,
"conditions": [],
"parentId": null,
"conditionParentId": null,
"children": []
}
],
"canOtherRuleTrigger": false,
"state": "DISABLED",
"authorAccountId": "5eff44013bfa9f0bb09659a8",
"trigger": {
"component": "TRIGGER",
"schemaVersion": 1,
"type": "confluence.page-updated.trigger",
"value": {
"eventFilters": [
"ari:cloud:confluence:a7bab0c0-ebdd-4e6f-a2fb-5b521fbfa871:space/262145"
],
"enableAdminKey": false
},
"connectionId": null,
"conditions": []
},
"writeAccessType": "UNRESTRICTED",
"description": "This rule sets the page status to Rough draft when a page is updated and has no status.",
"ruleScopeARIs": [
"ari:cloud:confluence:a7bab0c0-ebdd-4e6f-a2fb-5b521fbfa871:space/262145"
],
"collaborators": [],
"notifyOnError": "FIRSTERROR"
}
}
  

So still "Bad request".
I also tried the status with ID = 1 (and correponding label en color), but with the same result.
And also toggled again with ENABLED vs DISABLED. Also no success.
Any ideas left?

Marc -Devoteam-
Community Champion
April 1, 2026

Hi @Peter Rossum_ van 

What is the result when you build this rule in the GUI?

For authentication to the URL did you endcode your user and PAT to Base64?

What if you try to do this via Postman?

Peter Rossum_ van
Contributor
April 1, 2026

@Marc -Devoteam- ,

Finally success!
I feel so stupid....
I missed the "Content-Type: application/json" option in the header :-(
I walked over the whole source again and suddenly saw the mistake.
I was now able to create the rule and the rule worked perfect as well.
--
Thanks for your great help!

Like # people like this
Marc -Devoteam-
Community Champion
April 1, 2026

Hi @Peter Rossum_ van 

You're welcome.

Please accept my answer as a solution, if my answer helped to solve or provide a workaround to your request.

This will help other community member trying to solve the same or provide them with a work around

P.S. If the answer is very valuable to you, please share some kudos.

Like Peter Rossum_ van likes this
0 votes
Mark B Wager
Contributor
March 19, 2026

Hi Peter

Can you provide a screenshot? I'm struggling to understand exactly what you're trying to do.

Are you asking if anyone has successfully created a new Jira "Automation" rule via the Automation REST API, and what common gotchas cause a 400 Bad Request when you copy an existing rule’s JSON and POST it?

 

EXAMPLE:
POST
/gateway/api/automation/public/{product}/{cloudId}/rest/v1/rule

 

ANSWER:
Not all auth methods work.

Works

  • Personal API token (user-based)
  • Must be a user with permission to create automation rules (project admin or Jira admin, depending on scope)

Does NOT work

  • OAuth 2.0 (3LO)
  • Forge apps
  • App-scoped tokens

Atlassian explicitly documents that Forge and OAuth2 apps cannot access these rule management endpoints. [developer....assian.com]

 

Peter Rossum_ van
Contributor
March 24, 2026

@Mark B Wager ,
I am aware of that.
The API to get the example Rule from Confluence DOES work.
But the API to create a new one does not work.
(see above thread with Marc)

Peter Rossum_ van
Contributor
March 24, 2026

@Mark B Wager
B.t.w...   I try to create a rule within(!) a Confluence Space. For that I asume I need admin permission for that space.
On the other hand, I am also a Confluence Admin. But I do not want to create a global rule, just a rule inside a space.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events