Enterprise APIs are designed for organizations to create and manage challenges, users, and submissions programmatically. Using these APIs you can bring the OneCompiler platform features like Challenges & Studio to your website or application.

User Creation/Sync

Following is the sample cURL request to create new user programmatically

curl --location --request POST 'https://onecompiler.com/api/v1/createUser?access_token=your_access_token' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "Peter Griffin",
    "email": "[email protected]"
}'

Optional fields:

FieldDescription
externalIdUnique identifier from the external app, typically userId from your app
pictureURL to an image
thumbnailURL to an image, a smaller size if available, ex. 96x96

On successful creation you get a response like below

{
    "_id": "3yhxfe7yu",
    "name": "Peter Griffin",
    "userId": "petergriffin",
    "email": "[email protected]",
    "picture": "https://static.onecompiler.com/images/blank-profile.png",
    "thumbnail": "https://static.onecompiler.com/images/blank-profile.png",
    "hidePicture": true,
    "status": "unlisted",
    "created": "2022-10-04T11:36:27.105Z",
    "api": {
        "createdBy": "your_api_id",
        "token": "zag5vxxxxxxxxxxxxxxxxxxxxxx555"
    }
}

Please capture the api.token data and store it. You can start using this to make API calls as the above created user.

Signing In a user programmatically

To make a user login automatically for a session. Add the following query parameters to the eligible URL (ex. Embedded challenges)

  1. apiKey
  2. userApiToken

Example URL: https://onecompiler.com/embed/challenges/3w7dby3mt/beginners-coding-challenge?apiKey=your_api_id&userApiToken=user_specific_token

Advanced Challenge Options

PropertyDescription
Start/ End timeSets the challenge opening/ closing times for time bounded challenges
Enable FinishIf enabled, the user can finish the challenge otherwise challenge is open to modify submissions all the time
User Tracking -> Capture Tab changesRecords the number of times the user switches the tabs, required for Close challenge after x tab switches feature to work
User Tracking -> Capture userCapture feed of user photos via camera
Time Tracking -> Enable Time TrackingThis tracks the amount of time the user spends on each problem also at the complete challenge
Challenge Time Limit (minutes)This sets the time limit for the challenge, the user can open the challenge multiple time challenge will be closed on the total time allocated is over
Disable Copy, PasteThis stops copying/ pasting the code from the editor. Also, disable right click
Show Instructions on startThis shows an instructions page on Challenge Start. The challenge description is presented in the instructions
Hide score after problem titleThis hides the score (the star symbol) in the problems list
Hide challenge end timeHides the challenge end time in the challenge footer
Show tab change warningThis shows a warning message when the user tries to switch tabs on the Top middle section
Show report after finishThis enables users to see the report after finishing the challenge
Close challenge after x tab switchesChallenge closed if users switch the tab more than x times
Lab ModeThis disables the scoring and submission section (No user login required)
Show Results in Lab ModeThis works along with Lab Mode and enables the submission section (no user login required)
Record user sessionRecords the complete user session, video will be available in the report

Creating challenges programmatically

Following is the sample cURL shows creating challenges programmatically


curl --location 'https://onecompiler.com/api/v1/challenges/create?access_token=oe6unlt4cn71d6klbvqh8in09ew8cgv5e3709ly2nlwzbrri1rqz7xarvealutauj6ftrjzis74azcrqor1chjbh6qfq9tz673zitjkp5gf9zefqyl4nnvspf65id7fp' --header 'Content-Type: application/json' --data '{
    "challenge": {
        "title": "Demo challenge created using API",
        "markdown": "Description of the challenge - created using API",
        "tags": [
            "demo",
            "oc"
        ],
        "visibility": "unlisted",
        "properties": {
            "captureUser": "yes",
            "captureTabChanges": "yes",
            "startDate": "2024-01-01T18:30:00.000Z",
            "endDate": "2029-01-01T14:30:00.000Z",
            "enableFinish": "yes",
            "enableTimeTracking": "yes",
            "timeLimit": 60,
            "disableCopyPaste": true,
            "showInstructionsOnStart": true,
            "shuffleProblemOrder": true,
            "hideScoreAfterProblemTitle": true,
            "hideChallengeEndTime": true,
            "showNextChallengeOnLastProblemOnly": true,
            "showTabChangeWarning": true,
            "showReportAfterFinish": true,
            "maxTabSwitches": 5,
            "closeAfterTabSwitches": true,
            "enableSessionRecording": true
        }
    },
    "problems": [
        {
            "title": "Read name and say Hello",
            "markdown": "Take the name from STDIN and print Hello <name>",
            "properties": {
                "problemType": "code",
                "score": 5,
                "difficultyLevel": "medium",
                "options": {
                    "code": {
                        "supportedLanguages": null,
                        "validations": [
                            {
                                "id": 1,
                                "input": "Peter",
                                "output": "Hello Peter",
                                "label": "easy"
                            },
                            {
                                "id": 2,
                                "input": "Lois",
                                "output": "Hello Lois",
                                "label": "medium"
                            }
                        ],
                        "problemCategory": "programmingLanguages",
                        "ignoreCase": true,
                        "preloads": "3ygcd9fxd, 3ygcdatnw, 3ygcdcmfr, 3ygcdense",
                        "complimentaryScore": 0
                    }
                }
            }
        },
        {
            "title": "Even or Odd",
            "markdown": "Read the number as input and print even or odd",
            "properties": {
                "problemType": "code",
                "score": 2,
                "difficultyLevel": "easy",
                "options": {
                    "code": {
                        "supportedLanguages": [
                            "java",
                            "python"
                        ],
                        "validations": [
                            {
                                "id": 1,
                                "input": "6",
                                "output": "even",
                                "label": "easy"
                            },
                            {
                                "id": 2,
                                "input": "5",
                                "output": "odd",
                                "label": "medium"
                            }
                        ],
                        "problemCategory": "programmingLanguages",
                        "ignoreCase": true,
                        "preloads": "3ygcd9fxd, 3ygcdatnw, 3ygcdcmfr, 3ygcdense",
                        "complimentaryScore": 1,
                        "hint1": "First hint",
                        "hint2": "Second hint",
                        "hint3": "Third hint",
                        "scoreDeductionForHints": true,
                        "timeoutSolution": "This is the complete solution",
                        "scoreDeductionForSolution": true
                    }
                }
            }
        }
    ]
}'

Options & their possible values:

PropertyPossible Values
challenge.visibilitypublic / unlisted / private
problems.properties.problemTypecode / multipleChoice / fillInTheBlank / descriptive
problems.properties.difficultyLeveleasy / medium / hard
problems.properties.options.code.problemCategoryprogrammingLanguages / webLanguages / databases
problems.properties.options.code.validations.labeleasy / medium / hard

Read challenge high level summary

Following GET API call returns the high level summary of the challenge

https://onecompiler.com/api/v1/challenges/stats/summary?access_token=<your_api_token>&challengeIds=<one or more challengeIds (comma separated)>

example:

https://onecompiler.com/api/v1/challenges/stats/summary?access_token=xyz123456&challengeIds=3w7dby3mt

Response looks like following

{
  "status": "success",
  "statsSummary": {
      "3w7dby3mt": {
          "totalAttempted": 708, // Total number of users attempted the challenge
          "currentAttempting": 12, // Number of users currently attempting the challenge
          "totalChallengeScore": 20 // Max possible score i.e sum of scores of all problems
      }
  }
}

Read challenge user level details

Following GET API call returns the user level details of the challenge, it gives the list of users who attempted the challenge and their scores.
It also provides the total score the user got in the challenge.

https://onecompiler.com/api/v1/challenges/stats?access_token=<your_api_token>&challengeIds=<one or more challengeIds (comma separated)>

example:

https://onecompiler.com/api/v1/challenges/stats?access_token=xyz123456&challengeIds=3w7dby3mt

Response looks like following

{
  "status": "success",
  "stats": {
      "3w7dby3mt": [
          {
              "_id": "3w7dby3mt_3ttkdkdkd",
              "score": 10,
              "challenge": {
                  "_id": "3w7dby3mt"
              },
              "user": {
                  "_id": "3ttkdkdkd"
              },
              "created": "2023-06-30T12:33:30.985Z",
              "updated": "2023-06-30T13:06:26.240Z",
              "accessCode": "s51lkpwo7qbb96bokktj3q1xyo5cgqghjsok2x5dgmwdqgjme4v7z8wntxs3xl8nwiyg1sed66hwu78jxl08fiz7cfozdhuz5nbazrkwjn5vel01sopm5becyrhhybdu",
              "tabChanges": 6
          },
          {},
          {},
          .
          .
          .
      ]
}

Note: 'accessCode' is the unique token of the user's submission, you can use this to see or embed the user's submission in your website.

Read a user's submission

Following GET API call returns the user's submission details for a given challenge and user.

https://onecompiler.com/api/v1/challenges/submission/<challenge_id>/<user_id>?access_token=<your_api_token>

If you want to embed the submission in your website, you can use the following URL

https://onecompiler.com/embed/challenges/submission/<challenge_id>/<user_id>/<access_code_of_user_submission>

Note: 'access_code_of_user_submission' is the access code you get from the 'challenges/stats' API call.

MISC

SSO Integration /apis/enterprise/sso

Reports /apis/enterprise/reports