Swift HMRC Create Test User: HMRC Create Test User that is an Organization

Back to Index

This resource creates and returns a test user which is an organisation. The caller can specify the required service enrolments in the request body. If no request body is supplied, the test user is created with no service enrolments.

Documentation: https://developer.service.hmrc.gov.uk/api-documentation/docs/api/service/api-platform-test-user/1.0#_create-a-test-user-which-is-an-organisation_post_accordion

CURL Command

curl -X POST  https://test-api.service.hmrc.gov.uk/create-test-user/organisations \
-H 'Authorization: Bearer HMRC_SERVER_TOKEN' \
-H 'Accept: application/vnd.hmrc.1.0+json' \
-H 'Content-Type: application/json' \
-d '{
  "serviceNames": [
    "corporation-tax",
    "paye-for-employers",
    "submit-vat-returns",
    "national-insurance",
    "self-assessment",
    "mtd-income-tax",
    "mtd-vat",
    "lisa",
    "secure-electronic-transfer",
    "relief-at-source",
    "customs-services"
  ]
}'

Swift Example


func chilkatTest() {
    let rest = CkoRest()
    var success: Bool

    //  URL: https://test-api.service.hmrc.gov.uk/create-test-user/organisations
    var bTls: Bool = true
    var port: Int = 443
    var bAutoReconnect: Bool = true
    success = rest.Connect("test-api.service.hmrc.gov.uk", port: port, tls: bTls, autoReconnect: bAutoReconnect)
    if success != true {
        print("ConnectFailReason: \(rest.ConnectFailReason.intValue)")
        print("\(rest.LastErrorText)")
        return
    }

    //  See the Online Tool for Generating JSON Creation Code
    let json = CkoJsonObject()
    json.UpdateString("serviceNames[0]", value: "corporation-tax")
    json.UpdateString("serviceNames[1]", value: "paye-for-employers")
    json.UpdateString("serviceNames[2]", value: "submit-vat-returns")
    json.UpdateString("serviceNames[3]", value: "national-insurance")
    json.UpdateString("serviceNames[4]", value: "self-assessment")
    json.UpdateString("serviceNames[5]", value: "mtd-income-tax")
    json.UpdateString("serviceNames[6]", value: "mtd-vat")
    json.UpdateString("serviceNames[7]", value: "lisa")
    json.UpdateString("serviceNames[8]", value: "secure-electronic-transfer")
    json.UpdateString("serviceNames[9]", value: "relief-at-source")
    json.UpdateString("serviceNames[10]", value: "customs-services")

    rest.AddHeader("Content-Type", value: "application/json")
    rest.AddHeader("Authorization", value: "Bearer HMRC_SERVER_TOKEN")
    rest.AddHeader("Accept", value: "application/vnd.hmrc.1.0+json")

    let sbRequestBody = CkoStringBuilder()
    json.EmitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()
    success = rest.FullRequestSb("POST", uriPath: "/create-test-user/organisations", requestBody: sbRequestBody, responseBody: sbResponseBody)
    if success != true {
        print("\(rest.LastErrorText)")
        return
    }

    var respStatusCode: Int = rest.ResponseStatusCode.intValue
    if respStatusCode >= 400 {
        print("Response Status Code = \(respStatusCode)")
        print("Response Header:")
        print("\(rest.ResponseHeader)")
        print("Response Body:")
        print("\(sbResponseBody.GetAsString())")
        return
    }

    let jsonResponse = CkoJsonObject()
    jsonResponse.LoadSb(sbResponseBody)

    //  See the Online Tool for Generating JSON Parse Code
    var userId: String?
    var password: String?
    var userFullName: String?
    var emailAddress: String?
    var organisationDetailsName: String?
    var organisationDetailsAddressLine1: String?
    var organisationDetailsAddressLine2: String?
    var organisationDetailsAddressPostcode: String?
    var saUtr: String?
    var nino: String?
    var mtdItId: String?
    var empRef: String?
    var ctUtr: String?
    var vrn: String?
    var vatRegistrationDate: String?
    var lisaManagerReferenceNumber: String?
    var secureElectronicTransferReferenceNumber: String?
    var pensionSchemeAdministratorIdentifier: String?
    var eoriNumber: String?

    userId = jsonResponse.StringOf("userId")
    password = jsonResponse.StringOf("password")
    userFullName = jsonResponse.StringOf("userFullName")
    emailAddress = jsonResponse.StringOf("emailAddress")
    organisationDetailsName = jsonResponse.StringOf("organisationDetails.name")
    organisationDetailsAddressLine1 = jsonResponse.StringOf("organisationDetails.address.line1")
    organisationDetailsAddressLine2 = jsonResponse.StringOf("organisationDetails.address.line2")
    organisationDetailsAddressPostcode = jsonResponse.StringOf("organisationDetails.address.postcode")
    saUtr = jsonResponse.StringOf("saUtr")
    nino = jsonResponse.StringOf("nino")
    mtdItId = jsonResponse.StringOf("mtdItId")
    empRef = jsonResponse.StringOf("empRef")
    ctUtr = jsonResponse.StringOf("ctUtr")
    vrn = jsonResponse.StringOf("vrn")
    vatRegistrationDate = jsonResponse.StringOf("vatRegistrationDate")
    lisaManagerReferenceNumber = jsonResponse.StringOf("lisaManagerReferenceNumber")
    secureElectronicTransferReferenceNumber = jsonResponse.StringOf("secureElectronicTransferReferenceNumber")
    pensionSchemeAdministratorIdentifier = jsonResponse.StringOf("pensionSchemeAdministratorIdentifier")
    eoriNumber = jsonResponse.StringOf("eoriNumber")

}

Sample JSON Response Body

{
  "userId": "331803185953",
  "password": "arjfogpD7Yst",
  "userFullName": "Gabi Upton",
  "emailAddress": "gabi.upton@example.com",
  "organisationDetails": {
    "name": "Company KPUEH0",
    "address": {
      "line1": "13 Mortimer Square",
      "line2": "Fleet",
      "postcode": "TS3 1PA"
    }
  },
  "saUtr": "7000022933",
  "nino": "OC929674D",
  "mtdItId": "XYIT00000840710",
  "empRef": "886/MPCHETZIAC",
  "ctUtr": "8000061338",
  "vrn": "990724297",
  "vatRegistrationDate": "1999-02-18",
  "lisaManagerReferenceNumber": "Z3182",
  "secureElectronicTransferReferenceNumber": "309105308354",
  "pensionSchemeAdministratorIdentifier": "a0174585",
  "eoriNumber": "GB5052299822"
}