Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for API Points #41

Merged
merged 1 commit into from
Oct 19, 2023

Conversation

SapphicFire
Copy link
Contributor

This PR implements support for API points with a Scripted REST API. This API is bound to a specific role ACL, and allows invocation with varying payloads. This resolves #2.

Invocation

The SR API endpoint is /api/x_snc_pointsthing/points_thing/api_point and this accepts a POST with Content-Type application/json. The payload is formatted as follows:

{
    "reason": "Testing",
    "target": "U0K4BD8DC",
    "targetType": "slack_id",
    "points": 2,
    "sender": "Slacker"
}

Payload notes

  • Only the reason, target, and targetType keys are mandatory.
  • Target type accepts slack_id or name.
  • Points will be ignored if the value is NaN or a negative integer.
  • Sender translates to Giver, and takes a user_name.
    • If ignored, this will fall back to a global property, slacker.api_point_giver, which you can use if you would like to have points reflecting their source.

Sample Call

POST /api/x_snc_pointsthing/points_thing/api_point HTTP/1.1
Content-Type: application/json
Host: instance.service-now.com

{
"reason": "Testing",
"target": "U0K4BD8DC",
"targetType": "slack_id",
"points":2
}

Notes

I also added a Points field to the API Points table, tweaked the lists slightly, and extended the PointsThing SI for API-specific methods/behaviour. Because of who I am I also added a semicolon on a line in PointsThing because the linter warning bothered me.

…ole and ACL

feat: Added new SI for API support, staring with support for name/ID as input
feat: Added support for multiple points in an API request
fix: Added a semicolon on a line in PointsThing because the linter warning bothered me
@Lacah Lacah self-assigned this Oct 19, 2023
@@ -110,7 +110,7 @@ PointsThing.prototype = {
if (response_body.user.name) {
var grupdate = new GlideRecord('x_snc_pointsthing_user');
grupdate.get(record_id);
var name = response_body.user.profile[gs.getProperty('x_snc_pointsthing.leaderboard_name')] ? response_body.user.profile[gs.getProperty('x_snc_pointsthing.leaderboard_name')] : response_body.user.profile['real_name']
var name = response_body.user.profile[gs.getProperty('x_snc_pointsthing.leaderboard_name')] ? response_body.user.profile[gs.getProperty('x_snc_pointsthing.leaderboard_name')] : response_body.user.profile['real_name'];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@Lacah Lacah merged commit 2088ffe into ServiceNowDevProgram:main Oct 19, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create API so that points can come from other scopes or external APIs
2 participants