Skip to content
DataMiner DoJo

More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Search in posts
Search in pages
Search in posts
Search in pages
Log in
Menu
  • Blog
  • Questions
  • Learning
    • E-learning Courses
    • Open Classroom Training
    • Certification
      • DataMiner Fundamentals
      • DataMiner Configurator
      • DataMiner Automation
      • Scripts & Connectors Developer: HTTP Basics
      • Scripts & Connectors Developer: SNMP Basics
      • Visual Overview – Level 1
      • Verify a certificate
    • Tutorials
    • Video Library
    • Books We Like
    • >> Go to DataMiner Docs
  • Expert Center
    • Solutions & Use Cases
      • Solutions
      • Use Case Library
    • Markets & Industries
      • Media production
      • Government & defense
      • Content distribution
      • Service providers
      • Partners
      • OSS/BSS
    • DataMiner Insights
      • Security
      • Integration Studio
      • System Architecture
      • DataMiner Releases & Updates
      • DataMiner Apps
    • Agile
      • Agile Webspace
      • Everything Agile
        • The Agile Manifesto
        • Best Practices
        • Retro Recipes
      • Methodologies
        • The Scrum Framework
        • Kanban
        • Extreme Programming
      • Roles
        • The Product Owner
        • The Agile Coach
        • The Quality & UX Coach (QX)
    • DataMiner DevOps Professional Program
  • Downloads
  • More
    • Feature Suggestions
    • Climb the leaderboard!
    • Swag Shop
    • Contact
      • General Inquiries
      • DataMiner DevOps Support
      • Commercial Requests
    • Global Feedback Survey
  • PARTNERS
    • All Partners
    • Technology Partners
    • Strategic Partner Program
    • Deal Registration
  • >> Go to dataminer.services

Configuring multiple APIs not working in Dataminer

Solved315 views30th January 2025
1
Harinee G174 27th January 2025 0 Comments

I need to configure 2 different api with routes - "heartbeat" and "notifications" in the same script. Earlier when I clicked "Configure API", I was able to see a dialog box which had option to select either of the api to open and edit but now I am unable to see it which results in only one api hosted at a time which should not happen. Please advise how to configure both api's in my script.

Harinee G Selected answer as best 30th January 2025

2 Answers

  • Active
  • Voted
  • Newest
  • Oldest
1
Matthias Declerck [SLC] [DevOps Advocate]2.75K Posted 27th January 2025 2 Comments

Hi Harinee,

My advice would be to configure 1 API definition on the script and then update the script so the routes are divided within the same API definition. Different repsonse can then be passed for each route.

I have an example to showcase you on how you can change results based on route:

This example shows us that different data can be passed as output, based on the route that is given. For instance, the Info route will pass information (config) data, while Metrics will be effective measured data as JSON.

UPDATE: If there's a need to have separate handling, such as different token, then it is possible to have multiple definitions:

I do hope this answer will help you further.
Looking forward to your positive reply.

Matthias Declerck [SLC] [DevOps Advocate] Edited answer 27th January 2025
Harinee G commented 27th January 2025

I am using a similar way in handling both routes..not sure if I need to add something else here..

[AutomationEntryPoint(AutomationEntryPointType.Types.OnApiTrigger)]
public ApiTriggerOutput OnApiTrigger(IEngine engine, ApiTriggerInput requestData)
{
try
{
var method = requestData.RequestMethod;
var route = requestData.Route;
var body = requestData.RawBody;

engine.Log($"API Triggered: Route = {route}, Method = {method}, Body= {body}");

if (method != RequestMethod.Post)
{
return new ApiTriggerOutput
{
ResponseBody = "Only POST requests are supported.",
ResponseCode = (int)StatusCode.MethodNotAllowed,
};
}

if (route == "heartbeat")
{
return HandleHeartbeatRequest(engine, body);
}
else if (route == "notifications")
{
return HandleNotificationRequest(engine, body);
}
else
{
return new ApiTriggerOutput
{
ResponseBody = "Invalid route. Please check the endpoint URL.",
ResponseCode = (int)StatusCode.NotFound,
};
}
}
catch (Exception ex)
{
engine.Log($"Error: {ex.Message}");
return new ApiTriggerOutput
{
ResponseBody = "An internal server error occurred.",
ResponseCode = (int)StatusCode.InternalServerError,
};
}
}

Matthias Declerck [SLC] [DevOps Advocate] commented 27th January 2025

Hi,

I don't see exactly what the problem is now. Are the requests being handled and/or is the method POST actually used (did you test with GET)?

Small feedback on the code you give: I would add some additional sanity checks whether the route is valid on 'heartbeat' and 'notifications', case insenstive.

Updated code:

[AutomationEntryPoint(AutomationEntryPointType.Types.OnApiTrigger)]
public ApiTriggerOutput OnApiTrigger(IEngine engine, ApiTriggerInput requestData)
{
try
{
var method = requestData.RequestMethod;
var route = requestData.Route;
var body = requestData.RawBody;

engine.Log($"API Triggered: Route = {route}, Method = {method}, Body= {body}");

if (method != RequestMethod.Post)
{
return new ApiTriggerOutput
{
ResponseBody = "Only POST requests are supported.",
ResponseCode = (int)StatusCode.MethodNotAllowed,
};
}

if (string.IsNullOrWhiteSpace(route))
{
return new ApiTriggerOutput
{
ResponseBody = $"An empty route is passed.",
ResponseCode = (int)StatusCode.BadRequest,
};
}

if (route.Equals("heartbeat", StringComparison.OrdinalIgnoreCase))
{
return HandleHeartbeatRequest(engine, body);
}
else if (route.Equals("notifications", StringComparison.OrdinalIgnoreCase))
{
return HandleNotificationRequest(engine, body);
}
else
{
return new ApiTriggerOutput
{
ResponseBody = "Invalid route. Please check the endpoint URL.",
ResponseCode = (int)StatusCode.NotFound,
};
}
}
catch (Exception ex)
{
engine.Log($"Error: {ex.Message}");
return new ApiTriggerOutput
{
ResponseBody = "An internal server error occurred.",
ResponseCode = (int)StatusCode.InternalServerError,
};
}
}

You are viewing 1 out of 2 answers, click here to view all answers.
Please login to be able to comment or post an answer.

My DevOps rank

DevOps Members get more insights on their profile page.

My user earnings

0 Dojo credits

Spend your credits in our swag shop.

0 Reputation points

Boost your reputation, climb the leaderboard.

Promo banner DataMiner DevOps Professiona Program
DataMiner Integration Studio (DIS)
Empower Katas

Recent questions

How to implement bearer token refresh? 0 Answers | 3 Votes
Web Applications exception in Cube due to invalid certificate 0 Answers | 2 Votes
Redundancy Groups and Alarming – Duplicate Alarms 1 Answer | 1 Vote

Question Tags

adl2099 (115) alarm (62) Alarm Console (82) alarms (100) alarm template (83) Automation (223) automation scipt (111) Automation script (167) backup (71) Cassandra (180) Connector (109) Correlation (69) Correlation rule (52) Cube (151) Dashboard (194) Dashboards (188) database (83) DataMiner Cube (57) DIS (81) DMS (71) DOM (140) driver (65) DVE (56) Elastic (83) Elasticsearch (115) elements (80) Failover (104) GQI (159) HTTP (76) IDP (74) LCA (152) low code app (166) low code apps (93) lowcodeapps (75) MySQL (53) protocol (203) QAction (83) security (88) SNMP (86) SRM (337) table (54) trending (87) upgrade (62) Visio (539) Visual Overview (345)
Privacy Policy • Terms & Conditions • Contact

© 2025 Skyline Communications. All rights reserved.

DOJO Q&A widget

Can't find what you need?

? Explore the Q&A DataMiner Docs

[ Placeholder content for popup link ] WordPress Download Manager - Best Download Management Plugin