User Creation/Sync

Following is the sample cURL request to create new user programatically

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]"
}'

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 programatically

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 programatically

Following is the sample cURL shows creating challenges programatically

curl --location 'https://onecompiler.com/api/v1/challenges/create?access_token=your_token' \
--header 'Content-Type: application/json' \
--data '{
  "challenge": {
    "title": "Demo challenge created using API",
    "markdown": "Description of the challenge - created using API",
    "tags": [],
    "visibility": "unlisted",
    "properties": {
      "challengeType" : "code",
        "captureUser" : "yes",
        "captureTabChanges" : "yes",
        "startDate" : "2023-07-04T10:09:00.000Z",
        "endDate" : "2023-07-29T10:09:00.000Z",
        "enableFinish" : "yes",
        "enableTimeTracking" : "yes",
        "timeLimit" : 60,
        "disableCopyPaste" : true,
        "showInstructionsOnStart" : true,
        "hideScoreAfterProblemTitle" : true,
        "hideChallengeEndTime" : true,
        "showNextChallengeOnLastProblemOnly" : true,
        "showTabChangeWarning" : true,
        "showReportAfterFinish" : true,
        "closeAfterTabSwitches" : true,
        "maxTabSwitches" : 3,
        "labMode" : true,
        "showResultsInLabMode" : true,
        "enableSessionRecording" : true
    }
  },
  "problems": [
    {
      "title": "Print Hello World",
      "markdown": "print the word, Hello World",
      "properties": {
        "problemType": "code",
        "score": 2,
        "options": {
          "code": {
            "supportedLanguages": null,
            "validations": [
              {
                "id": 1,
                "input": "NA",
                "output": "Hello World",
                "label": ""
              }
            ],
            "preloads" : "3ygcd9fxd, 3ygcdatnw, 3ygcdcmfr, 3ygcdense",
            "preloadsParsed" : {
                "java" : "3ygcd9fxd",
                "python" : "3ygcdatnw",
                "c" : "3ygcdcmfr",
                "cpp" : "3ygcdense"
            }
          }
        }
      }
    },
    {
      "title": "Even or Odd",
      "markdown": "Read the number as input and print even or odd",
      "properties": {
        "problemType": "code",
        "score": 2,
        "options": {
          "code": {
            "supportedLanguages": [
              "java",
              "python"
            ],
            "validations": [
              {
                "id": 1,
                "input": "6",
                "output": "even"
              },
              {
                "id": 2,
                "input": "5",
                "output": "odd"
              }
            ]
          }
        }
      }
    }
  ]
}'

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,
          "currentAttempting": 12
      }
  }
}

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.