Attendance Bug fixes

1. Fetch Slack Integration Details

  • Use the GraphQL endpoint (https://api-amdital.dev.diginnovators.site/wp/api/v1) to get existing integration details for Slack.
  • Use the following Dio (Dart) code to make the request:

dart
var headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer <TOKEN>',
};
var data = '''{
  "query":"query { amditalIntegrations(company_id: 2) { id company_id name api_key private_key api_url is_enabled }}"
}''';

var dio = Dio();
var response = await dio.request(
  'https://api-amdital.dev.diginnovators.site/wp/api/v1',
  options: Options(
    method: 'POST',
    headers: headers,
  ),
  data: data,
);

if (response.statusCode == 200) {
  print(json.encode(response.data));
} else {
  print(response.statusMessage);
}

  • Sample Response:
  • The response will include a list of integration objects with keys such as id, company_id, name, api_key, etc.

2. Validate Slack Integration Data

  • Parse the response from the first API.
  • Check if a Slack integration is present (i.e., there is an object with name: “Slack” or other identifying field) and all required fields/parameters are populated (such as api_key, private_key, api_url, and is_enabled).
  • If the Slack integration or any required parameter is missing:
  • Do not proceed further.
  • Leave the code for the above API as is.

3. Mark Attendance via Slack (if integration is valid)

  • If Slack integration exists and all parameters are valid, proceed to call the attendance API.
  • Use the following Dio code for this POST request:

dart
var data = FormData.fromMap({
  'user_id': '<SLACK_USER_ID>',
  'channel_id': '<SLACK_CHANNEL_ID>',
  'text': 'back'
});

var dio = Dio();
var response = await dio.request(
  'https://api-amdital.dev.diginnovators.site/wp-json/amdital/v1/slack-attendance',
  options: Options(
    method: 'POST',
  ),
  data: data,
);

if (response.statusCode == 200) {
  print(json.encode(response.data));
} else {
  print(response.statusMessage);
}

  • This API returns a boolean response indicating the success or failure of the attendance marking for that user.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

More posts