OVERVIEW
In order to use the Publisher API, you will need to register an application via System admin, and then authorise a user (or many) to access that API. This is done via OAuth. Upon authentication, this user will be assigned an Authentication token which will need to be sent with each and every API call to identify which user is making the call.
Step 1: Register application
Register application at: https://<instance name>/<application context name>/listAPIRegistration.action
- As with the registration of applications for the Collaborate API, there are a number of settings that can be modified for each application that is registered:
- Application name - used by administrators to see which application is which
- Application display name - used by any external views to identify the application
- Application description
- Secret key - can be manually replaced by generating a new key
- Redirect URL - after registration is complete, this page is where a user is redirected to
- Allowed IP - a comma separated list of allowed IPs
- Token expires in - manually set token expiration duration
- Status - activate/disable an application
- Show allow/deny screen
- Token rate limit
- Token rate limit time (in minutes)
- Application rate limit
- Application rate limit time (in minutes)
Step 2: Generate Authentication code
Retrieve your assigned Client Id and Redirect URL.
- Generate your authentication code at: https://<instance name>/<application context name>/authorise.action?response_type=code&client_id=<Client Id>&redirect_uri=<Redirect URL>
- If you have not got an active Publisher session, you will be asked to log in with the credentials you want to authorise to access the API
- If "Show allow/deny" screen is set to true, you will be asked to confirm access to the API
- You will be redirected to your Redirect URL with a URL parameter "code" added: <Redirect URL>?code=<Authentication code>
Step 3: Generate Access token
Retrieve your Client Id, Secret key and Authentication code
- Open your choice of REST Client, this walkthrough will show Postman
- Via HTTP POST:
- Set URL as https://<instance name>/<application context name>/api/oauth2/token
- Set REST call type as POST
- In Headers tab, set Content-Type = application/x-form-urlencoded
- In Headers tab, set Accept = application/xml OR application/json (Optional, If this header is not set then the response will be in JSON By default)
- In Body tab choose your preferred method (here it's raw) and enter the parameters below:
code=<Authentication code>&client_id=<Client Id>&client_secret=<Client secret>&grant_type=authorization_code
- Click on Send. Publisher will return a HTTP response in your choice of format: JSON(Default) or XML (If set in Accept header)
Step 4: Generate refresh token
Your access token will only stay active for the amount of time specified when you registered your application. When this token expires, you will need to generate a new token using your Refresh token
- As with generating an access token, open your choice of REST Client, this walkthrough will show Postman
- Via HTTP POST:
- Set URL as https://<instance name>/<application context name>/api/oauth2/token
- Set REST call type as POST
- In Headers tab, set Content-Type = application/x-form-urlencoded
- In Headers tab, set Accept = application/xml OR application/json (Optional, If this header is not set then the response will be in JSON By default)
- In Body tab choose your preferred method (here it's raw) and enter the parameters below:
client_id=<Client id>&client_secret=<Client secret>&grant_type=refresh_token&refresh_token=<Refresh token>
- Click on Send. Publisher will return a HTTP response in your choice of format: JSON(Default) or XML (If set in Accept header)
Has to be something wrong with configuration of instance, if:
- Auth code for clientID being used within 30mins
- clientID and defined secret key are correct
- The above is failing even in Postman
If that's the case, then there is nothing you can do but wait for support to figure it out
Hi,
Yes, my code does include a function to URL encode the secret key, however the secret key only contains alpha/numeric characters, and one underscore character, so there shouldn't be anything that requires encoding.
If you know C#, this is the bit of code that generates the parameters for the call:-
string message = string.Format("code={0}&client_id={1}&client_secret={2}&grant_type=authorization_code",
HttpUtility.UrlEncode(code),
ClientID,
HttpUtility.UrlEncode(SecretKey));
Thanks.
Are you (url)encoding the secret key? Normally (for Collaborate) I often see '/' in generated keys, more than anything else, so %2F for example.
I am unable to retrieve an access token. I can get the authorisation code, but when I try to get the access token I just get a 400 error back
Request:-
POST /hoganlovellsp4/api/oauth2/token HTTP/1.1
Host: hoganlovellsp4.highq.com
Accept: text/json
Content-Type: application/x-form-urlencoded
Cookie: JSESSIONID=EFA09890B08033B45A8F2A5B1C0628F3; ROUTEID=.pubapp2b436
Content-Length: 106
code=ZEEJ0R3Mfp&client_id=103&client_secret=[SECRET]&grant_type=authorization_code
Response:-
{"error":{"summary":"Request resource or xml is not valid","ref":"400"}}
I have tried a number of things;
In the documentation, it says use "application/x-form-urlencoded" for Content-Type, but I believe it is normally "application/x-www-form-urlencoded" so I tried that, but still got the error.
I tried sending "grant_type=authorisation_code" (s instead of z), but still got the error.
I tried changing Accept to "text/xml", but that returns a 500 Internal Server Error.
I have tried this from within the application I am building and Postman, but get the same results.
Can anyone suggest what I am doing wrong?
Thanks.
Comments
9 Comments