Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Folio ERM Agreement API

A draft Open API Specification (OAS) v3 is available at https://raw.githubusercontent.com/ostephens/folio-erm-agreements-api-os/main/dist.yaml

This file can be downloaded and used to generate API Collections in Postman (join the #postman #learning-apis channel on the Folio Slack for more information). The OAS definition can also be pasted directly into the Swagger API editor to get an interactive version of the API

If using Postman, it is recommended to setup Postman environments with the following variables:

  • okapiPort (port number, if there is one, for Okapi)
  • okapiProtocol (http or https)
  • okapiUrl (url for the okapi server omitting protocol and port)
  • username (valid Folio user)
  • password (p/w for the Folio user)
  • x-okapi-tenant-value (to be used as the value for x-okapi-tenant for all requests)
  • x-okapi-token-value  (to be used as the value for x-okapi-token for all requests. Using the script below if the x-okapi-token is not set, it will be set automatically)
  • baseUrl (the url for Okapi, using the script below this will be built automatically from the okapiProtocol, okapiUrl and okapiPort)

For the Collection you have generated from the OAS definition, add the following as a Pre-request script. This will ensure that:

...

const xOkapiTenantValue = pm.environment.get("x-okapi-tenant-value");
const okapiPort = pm.environment.get("okapiPort");
const okapiProtocol = pm.environment.get("okapiProtocol");
const okapiUrl = pm.environment.get("okapiUrl");
const username = pm.environment.get("username");
const password = pm.environment.get("password");
const baseUrl = `${okapiProtocol}://${okapiUrl}${okapiPort?':'+okapiPort:''}`

pm.environment.set("baseUrl", baseUrl)
const loginRequest= {
url: `${baseUrl}/authn/login`,
method: 'POST',
header: [
"Content-type: application/json",
`x-okapi-tenant:${xOkapiTenantValue}`],
body: {
mode: 'raw',
raw: JSON.stringify({ "username": username,"password":password })
}
};

if (!pm.environment.get("x-okapi-token-value")) {
pm.sendRequest(loginRequest, function (err, res) {
pm.test('response should be okay to process', function () {
pm.expect(err).to.equal(null);
pm.expect(res).to.have.property('code', 200);
pm.expect(res).to.have.property('status', 'OK');
pm.response.to.have.header("x-okapi-token");
});
var token=res.headers.get("x-okapi-token")
pm.environment.set("x-okapi-token-value", token);
console.log(err?err:res.json());
console.log(res.json());
});
}


// example containing a test ** under the Tests tab only
pm.sendRequest('https://postman-echo.com/get', function (err, res) {
if (err) { console.log(err); }
});

//////
// Set okapi headers for authorisation to work
pm.request.headers.upsert({key: 'x-okapi-tenant', value: pm.environment.get('x-okapi-tenant-value') })
pm.request.headers.upsert({key: 'x-okapi-token', value: pm.environment.get('x-okapi-token-value') })


Folio ERM License RAML

...