Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1486

What does callback parameter expect in below code?

$
0
0

`Hi There,

Greetings!

I have written one script to fetch SAML linked usernames and all usernames across Enterprise using Graph QL query in JSS. The script checks both the usernames, compares it and prints the output of username accross Enterprise. The script is used to fetch Github usernames for one of our Enterprises.

This is the script:

`const axios = require('axios');module.exports = async (input, callback, error) => {  try {    let request = input.request;    let secrets = input.secrets;    let emailFromGoogle = request.body.primaryEmail;    const auth = secrets.bearer_token;    const query = `     query {      enterprise(slug: "Enterprise") {        members(first: 100) {          pageInfo {            hasNextPage            hasPreviousPage            endCursor          }          edges {            node {              ... on User {                login                url              }              ... on EnterpriseUserAccount {                login                url                name              }            }          }        }        ownerInfo {          samlIdentityProvider {            externalIdentities(first: 100) {              totalCount              edges {                node {                  guid                  samlIdentity {                    nameId                  }                  user {                    login                  }                }              }              pageInfo {                hasNextPage                endCursor              }            }          }        }      }    }    `;    const options = {      method: 'POST',      url: 'https://api.github.com/graphql',      headers: {'Authorization': `Bearer ${auth}`,'Content-Type': 'application/json'      }    };    const response = await axios({ ...options, data: { query: query } });    const identities = response.data.data.enterprise.ownerInfo.samlIdentityProvider.externalIdentities.edges;    const members = response.data.data.enterprise.members.edges;    const result = members.map(edge => {      const identity = identities.find(identity => identity.node.samlIdentity.nameId === emailFromGoogle);      const isLinked = identity && edge.node.login === identity.node.user.login;      console.log('Login:', edge.node.login, 'Linked:', isLinked);      return {        login: edge.node.login,        linked: isLinked      };    });    const stringifiedResult = JSON.stringify(result, null, 2);    console.log('Result:', stringifiedResult);    result.forEach(user => {      if (user.linked) {        console.log(user.login); // Print the 'login' if 'linked' is true      }    });    callback(null, {      statusCode: 200, // Ensure to provide a valid HTTP status code      body: stringifiedResult // Return the stringified result as the response body    });  } catch (err) {    console.error('Error:', err);    error({      statusCode: 500, // Ensure to provide a valid HTTP status code      body: JSON.stringify({ error: err.message }) // Return the error message as the response body    });  }};`

I am using it as a Transformation Script to run it in Bettercloud. It is throwing the below error after execution. Please let me know what to change in callback parameter.

Output Error:

Please let me know if anything more is required.

Regards,

Tried it in VS code perfect output but callback is not properly done

{"success": false,"error": "{\"statusCode\":500,\"body\":\"{\\\"error\\\":\\\"Invalid status code: {\\\\n  statusCode: 200,\\\\n  body: '[\\\\\\\\n'+\\\\n    '  {\\\\\\\\n'+\\\\n    '    \\\\\\\"login\\\\\\\": \\\\\\\"login"\\\\\\\"\\\\\\\\n'+\\\\n    '  },\\\\\\\\n'+\\\\n    '  {\\\\\\\\n'+\\\\n    '    \\\\\\\"login\\\\\\\": \\\\\\\"login\\\\\\\"\\\\\\\\n'+\\\\n    '  },\\\\\\\\n'+\\\\n    '  {\\\\\\\\n'+\\\\n    '    \\\\\\\"login\\\\\\\": \\\\\\\"login\\\\\\\"\\\\\\\\n'+\\\\n    '  }\\\\\\\\n'+\\\\n    ']'\\\\n}\\\"}\"}","result": "{\"statusCode\":500,\"body\":\"{\\\"error\\\":\\\"Invalid status code: {\\\\n  statusCode: 200,\\\\n  body: '[\\\\\\\\n'+\\\\n    '  {\\\\\\\\n'+\\\\n    '    \\\\\\\"login\\\\\\\": \\\\\\\"login\\\\\\\"\\\\\\\\n'+\\\\n    '  },\\\\\\\\n'+\\\\n    '  {\\\\\\\\n'+\\\\n    '    \\\\\\\"login\\\\\\\": \\\\\\\"login\\\\\\\"\\\\\\\\n'+\\\\n    '  },\\\\\\\\n'+\\\\n    '  {\\\\\\\\n'+\\\\n    '    \\\\\\\"login\\\\\\\": \\\\\\\"login\\\\\\\"\\\\\\\\n'+\\\\n    '  }\\\\\\\\n'+\\\\n    ']'\\\\n}\\\"}\"}","duration": 999,"logs": ["INFO 2024-06-18T13:05:39+00:00 - Login:","INFO 2024-06-18T13:05:39+00:00 - Login:","INFO 2024-06-18T13:05:39+00:00 - Login:","INFO 2024-06-18T13:05:39+00:00 - Result:","ERROR 2024-06-18T13:05:39+00:00 - Error:"  ],"status": 500```.`

Viewing all articles
Browse latest Browse all 1486

Trending Articles