# Handling Submissions with the Nettskjema API

# Overview

This vignette demonstrates how to handle form submissions and answers using the Nettskjema API. Specifically, you will learn how to: 1. Get an individual submission answer. 1. Download an individual submission as a PDF.

# Getting an Individual Submission Answer: `ns_get_submission`

The `ns_get_submission` function fetches a single submission’s answers based on a submission ID.

## Example: Fetch an Individual Submission

To retrieve an individual submission, use the submission ID (a unique identifier for each submission).

    library(nettskjemar)

    # Replace with your submission ID
    submission_id <- 27685292

    # Get the submission data
    submission <- ns_get_submission(submission_id)

    # Display the submission data
    submission
    #> $submissionMetadata
    #> $submissionMetadata$formId
    #> [1] 123823
    #>
    #> $submissionMetadata$submissionId
    #> [1] 27685292
    #>
    #> $submissionMetadata$answerTime
    #> [1] 74630
    #>
    #> $submissionMetadata$createdDate
    #> [1] "2023-06-01T20:57:15"
    #>
    #> $submissionMetadata$modifiedDate
    #> [1] "2023-06-01T20:57:15"
    #>
    #> $submissionMetadata$anonymous
    #> [1] FALSE
    #>
    #> $submissionMetadata$deliveryDestination
    #> [1] "DATABASE"
    #>
    #> $submissionMetadata$person
    #> $submissionMetadata$person$name
    #> NULL
    #>
    #> $submissionMetadata$person$email
    #> NULL
    #>
    #>
    #>
    #> $answers
    #> $answers[[1]]
    #> $answers[[1]]$submissionId
    #> [1] 27685292
    #>
    #> $answers[[1]]$answerId
    #> [1] 158263133
    #>
    #> $answers[[1]]$elementId
    #> [1] 1641697
    #>
    #> $answers[[1]]$externalElementId
    #> [1] "freetext"
    #>
    #> $answers[[1]]$textAnswer
    #> [1] "some text"
    #>
    #> $answers[[1]]$answerOptionIds
    #> list()
    #>
    #> $answers[[1]]$externalAnswerOptionIds
    #> list()
    #>
    #> $answers[[1]]$elementType
    #> [1] "QUESTION"
    #>
    #>
    #> $answers[[2]]
    #> $answers[[2]]$submissionId
    #> [1] 27685292
    #>
    #> $answers[[2]]$answerId
    #> [1] 158263124
    #>
    #> $answers[[2]]$elementId
    #> [1] 1641698
    #>
    #> $answers[[2]]$externalElementId
    #> [1] "radio"
    #>
    #> $answers[[2]]$answerOptionIds
    #> $answers[[2]]$answerOptionIds[[1]]
    #> [1] 3879435
    #>
    #>
    #> $answers[[2]]$externalAnswerOptionIds
    #> $answers[[2]]$externalAnswerOptionIds[[1]]
    #> [1] "1"
    #>
    #>
    #> $answers[[2]]$elementType
    #> [1] "RADIO"
    #>
    #>
    #> $answers[[3]]
    #> $answers[[3]]$submissionId
    #> [1] 27685292
    #>
    #> $answers[[3]]$answerId
    #> [1] 158263127
    #>
    #> $answers[[3]]$elementId
    #> [1] 1641699
    #>
    #> $answers[[3]]$externalElementId
    #> [1] "checkbox"
    #>
    #> $answers[[3]]$answerOptionIds
    #> $answers[[3]]$answerOptionIds[[1]]
    #> [1] 3879437
    #>
    #> $answers[[3]]$answerOptionIds[[2]]
    #> [1] 3879438
    #>
    #>
    #> $answers[[3]]$externalAnswerOptionIds
    #> $answers[[3]]$externalAnswerOptionIds[[1]]
    #> [1] "questionnaires"
    #>
    #> $answers[[3]]$externalAnswerOptionIds[[2]]
    #> [1] "events"
    #>
    #>
    #> $answers[[3]]$elementType
    #> [1] "CHECKBOX"
    #>
    #>
    #> $answers[[4]]
    #> $answers[[4]]$submissionId
    #> [1] 27685292
    #>
    #> $answers[[4]]$answerId
    #> [1] 158263135
    #>
    #> $answers[[4]]$elementId
    #> [1] 1641700
    #>
    #> $answers[[4]]$externalElementId
    #> [1] "dropdown"
    #>
    #> $answers[[4]]$answerOptionIds
    #> $answers[[4]]$answerOptionIds[[1]]
    #> [1] 3879439
    #>
    #>
    #> $answers[[4]]$externalAnswerOptionIds
    #> $answers[[4]]$externalAnswerOptionIds[[1]]
    #> [1] "4"
    #>
    #>
    #> $answers[[4]]$elementType
    #> [1] "SELECT"
    #>
    #>
    #> $answers[[5]]
    #> $answers[[5]]$submissionId
    #> [1] 27685292
    #>
    #> $answers[[5]]$answerId
    #> [1] 158263130
    #>
    #> $answers[[5]]$elementId
    #> [1] 1641701
    #>
    #> $answers[[5]]$externalElementId
    #> [1] "radio_matrix"
    #>
    #> $answers[[5]]$answerOptionIds
    #> $answers[[5]]$answerOptionIds[[1]]
    #> [1] 3879441
    #>
    #>
    #> $answers[[5]]$externalAnswerOptionIds
    #> $answers[[5]]$externalAnswerOptionIds[[1]]
    #> [1] "1"
    #>
    #>
    #> $answers[[5]]$elementType
    #> [1] "MATRIX_RADIO"
    #>
    #> $answers[[5]]$subElementId
    #> [1] 1649734
    #>
    #>
    #> $answers[[6]]
    #> $answers[[6]]$submissionId
    #> [1] 27685292
    #>
    #> $answers[[6]]$answerId
    #> [1] 158263132
    #>
    #> $answers[[6]]$elementId
    #> [1] 1641701
    #>
    #> $answers[[6]]$externalElementId
    #> [1] "radio_matrix"
    #>
    #> $answers[[6]]$answerOptionIds
    #> $answers[[6]]$answerOptionIds[[1]]
    #> [1] 3879442
    #>
    #>
    #> $answers[[6]]$externalAnswerOptionIds
    #> $answers[[6]]$externalAnswerOptionIds[[1]]
    #> [1] "2"
    #>
    #>
    #> $answers[[6]]$elementType
    #> [1] "MATRIX_RADIO"
    #>
    #> $answers[[6]]$subElementId
    #> [1] 1649735
    #>
    #>
    #> $answers[[7]]
    #> $answers[[7]]$submissionId
    #> [1] 27685292
    #>
    #> $answers[[7]]$answerId
    #> [1] 158263128
    #>
    #> $answers[[7]]$elementId
    #> [1] 1641701
    #>
    #> $answers[[7]]$externalElementId
    #> [1] "radio_matrix"
    #>
    #> $answers[[7]]$answerOptionIds
    #> $answers[[7]]$answerOptionIds[[1]]
    #> [1] 3879442
    #>
    #>
    #> $answers[[7]]$externalAnswerOptionIds
    #> $answers[[7]]$externalAnswerOptionIds[[1]]
    #> [1] "2"
    #>
    #>
    #> $answers[[7]]$elementType
    #> [1] "MATRIX_RADIO"
    #>
    #> $answers[[7]]$subElementId
    #> [1] 5973024
    #>
    #>
    #> $answers[[8]]
    #> $answers[[8]]$submissionId
    #> [1] 27685292
    #>
    #> $answers[[8]]$answerId
    #> [1] 158263121
    #>
    #> $answers[[8]]$elementId
    #> [1] 1641702
    #>
    #> $answers[[8]]$externalElementId
    #> [1] "checkbox_matrix"
    #>
    #> $answers[[8]]$answerOptionIds
    #> $answers[[8]]$answerOptionIds[[1]]
    #> [1] 3879443
    #>
    #> $answers[[8]]$answerOptionIds[[2]]
    #> [1] 3879444
    #>
    #>
    #> $answers[[8]]$externalAnswerOptionIds
    #> $answers[[8]]$externalAnswerOptionIds[[1]]
    #> [1] "IT"
    #>
    #> $answers[[8]]$externalAnswerOptionIds[[2]]
    #> [1] "colleague"
    #>
    #>
    #> $answers[[8]]$elementType
    #> [1] "MATRIX_CHECKBOX"
    #>
    #> $answers[[8]]$subElementId
    #> [1] 1649736
    #>
    #>
    #> $answers[[9]]
    #> $answers[[9]]$submissionId
    #> [1] 27685292
    #>
    #> $answers[[9]]$answerId
    #> [1] 158263125
    #>
    #> $answers[[9]]$elementId
    #> [1] 1641702
    #>
    #> $answers[[9]]$externalElementId
    #> [1] "checkbox_matrix"
    #>
    #> $answers[[9]]$answerOptionIds
    #> $answers[[9]]$answerOptionIds[[1]]
    #> [1] 13309370
    #>
    #>
    #> $answers[[9]]$externalAnswerOptionIds
    #> $answers[[9]]$externalAnswerOptionIds[[1]]
    #> [1] "admin"
    #>
    #>
    #> $answers[[9]]$elementType
    #> [1] "MATRIX_CHECKBOX"
    #>
    #> $answers[[9]]$subElementId
    #> [1] 1649737
    #>
    #>
    #> $answers[[10]]
    #> $answers[[10]]$submissionId
    #> [1] 27685292
    #>
    #> $answers[[10]]$answerId
    #> [1] 158263122
    #>
    #> $answers[[10]]$elementId
    #> [1] 1641703
    #>
    #> $answers[[10]]$externalElementId
    #> [1] "date"
    #>
    #> $answers[[10]]$textAnswer
    #> [1] "01.06.2023"
    #>
    #> $answers[[10]]$answerOptionIds
    #> list()
    #>
    #> $answers[[10]]$externalAnswerOptionIds
    #> list()
    #>
    #> $answers[[10]]$elementType
    #> [1] "DATE"
    #>
    #>
    #> $answers[[11]]
    #> $answers[[11]]$submissionId
    #> [1] 27685292
    #>
    #> $answers[[11]]$answerId
    #> [1] 158263123
    #>
    #> $answers[[11]]$elementId
    #> [1] 1641704
    #>
    #> $answers[[11]]$externalElementId
    #> [1] "time"
    #>
    #> $answers[[11]]$textAnswer
    #> [1] "12:00"
    #>
    #> $answers[[11]]$answerOptionIds
    #> list()
    #>
    #> $answers[[11]]$externalAnswerOptionIds
    #> list()
    #>
    #> $answers[[11]]$elementType
    #> [1] "DATE"
    #>
    #>
    #> $answers[[12]]
    #> $answers[[12]]$submissionId
    #> [1] 27685292
    #>
    #> $answers[[12]]$answerId
    #> [1] 158263136
    #>
    #> $answers[[12]]$elementId
    #> [1] 1641705
    #>
    #> $answers[[12]]$externalElementId
    #> [1] "datetime"
    #>
    #> $answers[[12]]$textAnswer
    #> [1] "12.06.2023 13:33"
    #>
    #> $answers[[12]]$answerOptionIds
    #> list()
    #>
    #> $answers[[12]]$externalAnswerOptionIds
    #> list()
    #>
    #> $answers[[12]]$elementType
    #> [1] "DATE"
    #>
    #>
    #> $answers[[13]]
    #> $answers[[13]]$submissionId
    #> [1] 27685292
    #>
    #> $answers[[13]]$answerId
    #> [1] 158263126
    #>
    #> $answers[[13]]$elementId
    #> [1] 1641706
    #>
    #> $answers[[13]]$externalElementId
    #> [1] "number_decimal"
    #>
    #> $answers[[13]]$textAnswer
    #> [1] "4,5"
    #>
    #> $answers[[13]]$answerOptionIds
    #> list()
    #>
    #> $answers[[13]]$externalAnswerOptionIds
    #> list()
    #>
    #> $answers[[13]]$elementType
    #> [1] "NUMBER"
    #>
    #>
    #> $answers[[14]]
    #> $answers[[14]]$submissionId
    #> [1] 27685292
    #>
    #> $answers[[14]]$answerId
    #> [1] 158263131
    #>
    #> $answers[[14]]$elementId
    #> [1] 1641707
    #>
    #> $answers[[14]]$externalElementId
    #> [1] "number_integer"
    #>
    #> $answers[[14]]$textAnswer
    #> [1] "77"
    #>
    #> $answers[[14]]$answerOptionIds
    #> list()
    #>
    #> $answers[[14]]$externalAnswerOptionIds
    #> list()
    #>
    #> $answers[[14]]$elementType
    #> [1] "NUMBER"
    #>
    #>
    #> $answers[[15]]
    #> $answers[[15]]$submissionId
    #> [1] 27685292
    #>
    #> $answers[[15]]$answerId
    #> [1] 158263129
    #>
    #> $answers[[15]]$elementId
    #> [1] 3472259
    #>
    #> $answers[[15]]$externalElementId
    #> [1] "slider"
    #>
    #> $answers[[15]]$textAnswer
    #> [1] "3"
    #>
    #> $answers[[15]]$answerOptionIds
    #> list()
    #>
    #> $answers[[15]]$externalAnswerOptionIds
    #> list()
    #>
    #> $answers[[15]]$elementType
    #> [1] "LINEAR_SCALE"
    #>
    #>
    #> $answers[[16]]
    #> $answers[[16]]$submissionId
    #> [1] 27685292
    #>
    #> $answers[[16]]$answerId
    #> [1] 158263134
    #>
    #> $answers[[16]]$elementId
    #> [1] 1641713
    #>
    #> $answers[[16]]$externalElementId
    #> [1] "attachment_1"
    #>
    #> $answers[[16]]$textAnswer
    #> [1] "sølvi.png"
    #>
    #> $answers[[16]]$answerOptionIds
    #> list()
    #>
    #> $answers[[16]]$externalAnswerOptionIds
    #> list()
    #>
    #> $answers[[16]]$answerAttachmentId
    #> [1] 538819
    #>
    #> $answers[[16]]$filename
    #> [1] "sølvi.png"
    #>
    #> $answers[[16]]$mediaType
    #> [1] "image/png"
    #>
    #> $answers[[16]]$size
    #> [1] 628613
    #>
    #> $answers[[16]]$elementType
    #> [1] "ATTACHMENT"
    #>
    #> $answers[[16]]$attachment
    #> $answers[[16]]$attachment$answerAttachmentId
    #> [1] 538819
    #>
    #> $answers[[16]]$attachment$filename
    #> [1] "sølvi.png"
    #>
    #> $answers[[16]]$attachment$mediaType
    #> [1] "image/png"
    #>
    #> $answers[[16]]$attachment$size
    #> [1] 628613

This function returns a list containing all answers for the specified submission.