Versjonssammenligning

Nøkkel

  • Denne linjen ble lagt til.
  • Denne linjen ble fjernet.
  • Formateringen ble endret.

An earlier versjon of the Altinn REST API required the all forms, subforms and binary attachments to be included in a single POST with a max size limited to 50MB. Building permit applications often contain several large attachments. Including them in a single message is both cumbersome and the max limit could easily be reached. An improvement was added in Altinn version 17.1 (summer 2017) allowing attachments to be streamed and the complete message to be built in several steps.

...

StepTaskREST API
1

Initiate main form Rammesøknad with complete flag set to false.

This starts a Altinn draft submission for the form. 

POST: https://tt02.altinn.no/api/910297937/messages?complete=false

Paste code macro
languagejson
{
    "Type": "FormTask",
    "ServiceCode": 4397,
    "ServiceEdition": 2,
    "_embedded": {
        "forms": [
            {
                "Type": "MainForm",
                "DataFormatId": "5693",
                "DataFormatVersion": "42425",
                "FormData": "<rammesøknad xml>"
            }
        ]
    }
}



Response header from Altinn contains a "Location" field with the ID of the message. A message starting with the letter a (a5988855) indicates a draft message that can be altered. 

Location: https://tt02.altinn.no/api/910297937/messages/a5988855

2Initiate the Gjennomføringplan subform. A data section is added to the API message specifying that we are adding a "SubForm" and adding the XSD (data model) identifiers for Gjennomføringsplan V4. 

POST: https://tt02.altinn.no/api/910297937/messages/a5988855/forms

Paste code macro
languagejson
data: {
    "Type": "SubForm",
    "DataFormatId": 5786,
    "DataFormatVersion": 42725,
}



The current state of the object can always be checked from Altinn. 

We can see that the second form has been added. 

GET: https://tt02.altinn.no/api/910297937/Messages/a5988855?language=1044

Paste code macro
languagejson
{
    "MessageId": "a5988855",
    "Subject": "Søknad om rammetillatelse, Testergate 99, ProjectApiTest",
    "Status": "Utfylling",
    "LastChangedDateTime": "2018-05-02T13:19:33.19",
    "CreatedDate": "2018-05-02T13:19:33.117",
    "LastChangedBy": "FILIP MOHAMED",
    "ServiceOwner": "Direktoratet for byggkvalitet",
    "Type": "FormTask",
    "ServiceCode": "4397",
    "ServiceEdition": 2,
    "AvailableAction": 2,
    "_links": {
        "self": {
            "href": "https://tt02.altinn.no/api/910297937/messages/a5988855"
        },
        "print": {
            "href": "https://tt02.altinn.no/api/910297937/messages/a5988855/print",
            "mime-type": "application/pdf"
        },
        "metadata": {
            "href": "https://tt02.altinn.no/api/metadata/formtask/4397/2"
        },
        "portalview": {
            "href": "https://tt02.altinn.no/Pages/ServiceEngine/FormsEngine/FillInForm.aspx?ReporteeElementID=a5988855&ESC=4397&ESEC=2"
        },
        "form": [
            {
                "href": "https://tt02.altinn.no/api/910297937/messages/a5988855/forms/3791203",
                "name": "Søknad om rammetillatelse, Nygate 33, Prosjektnavn",
                "signinglocked": false,
                "signedbydefault": true
            },
            {
                "href": "https://tt02.altinn.no/api/910297937/messages/a5988855/forms/3791204",
                "name": "GjennomføringsplanV4",
                "signinglocked": false,
                "signedbydefault": true
            }
        ]
    }
}


3Add XML data to Gjennomføringplan

PUT: https://tt02.altinn.no/api/910297937/messages/a5988855/forms/3791204

Paste code macro
languagejson
data: {
    "Type": "SubForm",
    "DataFormatId": "5786",
    "DataFormatVersion": "42725",
    "FormData": "<xml for gjennonforingsplan>"
},

Altinn response will be somewhat cryptic:

Status Code: 204 No Content
4

Streaming an attachment

POST: https://tt02.altinn.no/api/910297937/messages/a5988855/attachments/
Advarsel

It is important to URL-encode filenames since a valid filename can contain characters which are reserved in an URL.

Example: situasjonsplan&fasade_tegning#3.pdf 

It is a valid filename, but will break an URL when trying to uploading the file. The reason for this is that both & and # have special meaings in an URL.

More information on the subject: https://developers.google.com/maps/documentation/urls/url-encoding


After the upload, the message status has an added attachment:


Paste code macro
languagejson
{
    "MessageId": "a5988855",
    "Subject": "Søknad om rammetillatelse, Nygate 33, Prosjektnavn",
    "Status": "Utfylling",
    "LastChangedDateTime": "2018-05-02T13:35:14.767",
    "CreatedDate": "2018-05-02T13:30:54.823",
    "LastChangedBy": "FILIP MOHAMED",
    "ServiceOwner": "Direktoratet for byggkvalitet",
    "Type": "FormTask",
    "ServiceCode": "4397",
    "ServiceEdition": 2,
    "AvailableAction": 2,
    "_links": {
        "self": {
            "href": "https://tt02.altinn.no/api/910297937/messages/a5988855"
        },
        "print": {
            "href": "https://tt02.altinn.no/api/910297937/messages/a5988855/print",
            "mime-type": "application/pdf"
        },
        "metadata": {
            "href": "https://tt02.altinn.no/api/metadata/formtask/4397/2"
        },
        "portalview": {
            "href": "https://tt02.altinn.no/Pages/ServiceEngine/FormsEngine/FillInForm.aspx?ReporteeElementID=5988855&ESC=4397&ESEC=2"
        },
        "attachment": [
            {
                "href": "https://tt02.altinn.no/api/910297937/messages/a5988855/attachments/2848411",
                "name": "minSituasjonsplan.pdf",
                "encrypted": false,
                "signinglocked": false,
                "signedbydefault": false,
                "filesize": 2138079
            }
        ],
        "form": [
            {
                "href": "https://tt02.altinn.no/api/910297937/messages/a5988855/forms/3791203",
                "name": "Søknad om rammetillatelse, Nygate 33, Prosjektnavn",
                "signinglocked": false,
                "signedbydefault": true
            },
            {
                "href": "https://tt02.altinn.no/api/910297937/messages/a5988855/forms/3791204",
                "name": "GjennomføringsplanV4",
                "signinglocked": false,
                "signedbydefault": true
            }
        ]
    }
}


5

Submitting the final package.

When the main form, sub forms and attachments are ready for final submittal and signature in Altinn, with the flags "complete" and "sign" set to true. Request data payload contains the form ID in Altinn. 



Paste code macro
languagejson
{
    "Type": "FormTask",
    "ServiceCode": "4397",
    "ServiceEdition": 2
}


Remember that after final submittal, the ID number starting with an a (a5988855 in this case) will change to a different number starting with the letter b (b1234567). This is the final ID number for the signed form and is equal to the archive reference number in Altinn if the letter b is replaced with AR (AR1234567).


Example code from the "DiBK Testmotor" can be found here:

...