This article contains more detailed information on the different features of the NinjaCat Agency Management Open API. The two documents attached at the bottom of the article are visual supplements illustrating the event flow of the SSO (Single Sign-On) features.
Section Links
Authentication
This rest method is used for all authentication to make all subsequent requests to the API. This method allows you to get back an access token for authentication purposes when making requests in this API.
When making this request you will need the authorization header with the Client Id and Client Secret for basic auth. You will need to base64 encode both the Client id and Client Secret with the following format, {{Client_Id}}:{{Client_Secret}}. Here is an example of what the authorization header should look like.
The Agency Identifier Key needs to be set in the x-api-header.
Here is an example of what the x-api-header header should look like:
x-api-header : {{agency_identifier_key}}.
All other requests will require an Authorization header with the access token returned by this method. Example format that is expected to pass in the access token with the Authorization header.
Authorization : Bearer {{access_token}}
URL |
https://api.ninjacat.io/oauth2/token |
Method |
POST |
Security |
Basic Auth Username: AGENCY_CLIENT_ID Password: AGENCY_CLIENT_SECRET |
Headers |
Accept: application/json Cache-Control: no-cache Content-Type: application/x-www-form-urlencoded x-api-key: AGENCY_IDENTIFIER _KEY |
Sample Call |
PHP: $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://api.ninjacat.io/oauth2/token'); $request->setRequestMethod('POST'); $request->setOptions(array()); $request->setHeaders(array( 'Accept' => 'application/json', 'Cache-Control' => 'no-cache', 'Content-Type' => 'application/x-www-form-urlencoded', 'x-api-key' => 'AGENCY_IDENTIFIER _KEY', 'Authorization' => 'Basic ' . base64_encode("AGENCY_CLIENT_ID:AGENCY_CLIENT_SECRET") )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody();
|
Single Sign-On
Overview
To use the NinjaCat Single Sign-on with our Open API you need to first Authenticate with the API to get your bearer token.
Once you have a bearer token, you can use that token to get a list of all users within NinjaCat, create or update additional users (and set / change their permissions or advertisers they have access to) as well as get a one time URL which will allow a user to log in to NinjaCat automatically.
A simple flow might look like this:
- Call Authentication Get Token to get the Bearer Token
- Call the Agency Users methods to get a list of users within NinjaCat
- Find the appropriate user you want to log in or create a user using the Add Agency User method within the API.
- Use the ID of the User found or created to get a Login Link for that user.
- Redirect the user with the login link to automatically log them into NinjaCat.
- You can redirect a user to a specific page within NinjaCat by appending a “redirectto” parameter to the url (that is URL encoded).
Get Login Link
This rest method is used to generate one use login links that have a time to live of 5 minutes. This can be used to automatically log a user into the platform using the API.
When making this request you will need the authorization access token you acquired in the Authentication method above. You will also need the Client Id and the Agency Identifier Key.
The Agency Identifier Key needs to be set in the x-api-header and the Client Id in the Client-Id header.
The User ID of the user you want to authenticate and login to the platform should be passed as a URL parameter.
URL |
https://api.ninjacat.io/management_open_api/login/{{user_id}} |
Method |
POST |
Security |
Bearer Token Authentication : Bearer {{access_token}} |
Headers |
Accept: application/json Cache-Control: no-cache Content-Type: application/x-www-form-urlencoded x-api-key: AGENCY_IDENTIFIER _KEY Client-Id: AGENCY_CLIENT_ID |
Sample Call |
PHP: $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://api.ninjacat.io/management_open_api/login/’ . USER_ID); $request->setRequestMethod('POST'); $request->setOptions(array()); $request->setHeaders(array( 'Accept' => 'application/json', 'Cache-Control' => 'no-cache', 'Content-Type' => 'application/x-www-form-urlencoded', 'x-api-key' => 'AGENCY_IDENTIFIER _KEY', 'Authorization' => 'Bearer ' . ACCESS_TOKEN) )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody();
|
Redirection of Login Link
Once you have a login link you are able to redirect the user to anywhere that they have access to within the NinjaCat platform. This is done by adding the “redirectto” URL parameter top the Login Link URL.
Note: The redirectto parameter must be URL encoded to work.
{{LoginLink}}??redirectto=agency%2Freporting%2Ftemplate_builder
Get Agency Users
This rest method is used to get a list of Agency Users that can be accessed in the platform. They can be used with the GetLoginLink API call to log a user into the platform.
When making this request you will need the authorization access token you acquired in the Authentication method above. You will also need the Client Id and the Agency Identifier Key.
The Agency Identifier Key needs to be set in the x-api-header and the Client Id in the Client-Id header.
URL |
https://api.ninjacat.io/management_open_api/agency_users |
Method |
POST |
Security |
Bearer Token Authentication : Bearer {{access_token}} |
Headers |
Accept: application/json Cache-Control: no-cache Content-Type: application/x-www-form-urlencoded x-api-key: AGENCY_IDENTIFIER _KEY Client-Id: AGENCY_CLIENT_ID |
Sample Call |
PHP: $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://api.ninjacat.io/management_open_api/agency_users’); $request->setRequestMethod('POST'); $request->setOptions(array()); $request->setHeaders(array( 'Accept' => 'application/json', 'Cache-Control' => 'no-cache', 'Content-Type' => 'application/x-www-form-urlencoded', 'x-api-key' => 'AGENCY_IDENTIFIER _KEY', 'Authorization' => 'Bearer ' . ACCESS_TOKEN) )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody();
|
Comments
0 comments
Article is closed for comments.