Provisioning template revision via API

Using Foreman 1.10.3. Basically, I'm trying to diff provisioning templates
outside of Foreman using the API. My thought was to grab the latest
version, then the previous revision and diff 'em. I'm successfully
retrieving the latest version of the provision template but failing to get
any previous revisions. The docs
<API documentation>
make me believe it can be done but are a little terse in how to use the
endpoint.

$ curl -s -H "Accept:application/json" -k -u ${FOREMAN_USER}:${FOREMAN_PASS}
https://foreman.domain.com/api/provisioning_templates/80 |jq
<works>

$ curl -s -H "Accept:application/json" -k -u ${FOREMAN_USER}:${FOREMAN_PASS}
https://foreman.domain.com/api/provisioning_templates/revision |jq
{
"error": {
"message": "Resource provisioning_template not found by id ''"
}
}

$ curl -s -H "Accept:application/json" -k -u ${FOREMAN_USER}:${FOREMAN_PASS}
https://foreman.domain.com/api/provisioning_templates/revision?id=80 |jq
{
"error": {
"message": "Resource provisioning_template not found by id '80'"
}
}

$ curl -s -H "Accept:application/json" -k -u ${FOREMAN_USER}:${FOREMAN_PASS}
https://foreman.domain.com/api/provisioning_templates/revision?id=80&amp;version=1
>jq
{
"error": {
"message": "undefined method `template' for
#<Setting::Auth:0x007f3f9883e350>"
}
}

$ curl -s -H "Accept:application/json" -k -u ${FOREMAN_USER}:${FOREMAN_PASS}
https://foreman.domain.com/api/provisioning_templates/revision?version=1 |jq
{
"error": {
"message": "undefined method `template' for
#<Setting::Auth:0x0000000a29e9b0>"
}
}

Any thoughts?

Thanks,
-Chris

> Using Foreman 1.10.3. Basically, I'm trying to diff provisioning
> templates outside of Foreman using the API. My thought was to grab the
> latest version, then the previous revision and diff 'em. I'm
> successfully retrieving the latest version of the provision template but
> failing to get any previous revisions. The docs
> <API documentation>
> make me believe it can be done but are a little terse in how to use the
> endpoint.

It's a bad API, as it requires an ID of an audit entry that changes the
template to retrieve the contents of the template. You would need to use
/api/v2/audits to find the IDs, I don't think any data is supplied under
the template about its version history or audit entries.

> $ curl -s -H "Accept:application/json"-k -u
> ${FOREMAN_USER}:${FOREMAN_PASS}https://foreman.domain.com/api/provisioning_templates/revision?version=1

Then use this request, /api/v2/provisioning_templates/revision?version=1
where 1 is the ID of the audit entry that changes the template. It will
return a raw template, not JSON.

> {
> "error":{
> "message":"undefined method `template' for
> #<Setting::Auth:0x0000000a29e9b0>"
> }
> }

This may happen when the audit number is incorrect and doesn't point to
a template change.

··· On 14/06/16 20:37, Chris Clonch wrote:


Dominic Cleal
dominic@cleal.org

Thanks! /api/v2/audits was all that is needed since it already includes
the current and the previous versions.

-Chris

··· On Wednesday, June 15, 2016 at 3:26:59 AM UTC-4, Dominic Cleal wrote: > > It's a bad API, as it requires an ID of an audit entry that changes the > template to retrieve the contents of the template. You would need to use > /api/v2/audits to find the IDs, I don't think any data is supplied under > the template about its version history or audit entries. >