This resource creates and returns a test user which is an agent. 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.
curl -X POST https://test-api.service.hmrc.gov.uk/create-test-user/agents \
-H 'Authorization: Bearer HMRC_SERVER_TOKEN' \
-H 'Accept: application/vnd.hmrc.1.0+json' \
-H 'Content-Type: application/json' \
-d '{
"serviceNames": [
"agent-services"
]
}'
func chilkatTest() {
let rest = CkoRest()
var success: Bool
// URL: https://test-api.service.hmrc.gov.uk/create-test-user/agents
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: "agent-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/agents", 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 agentServicesAccountNumber: String?
userId = jsonResponse.StringOf("userId")
password = jsonResponse.StringOf("password")
userFullName = jsonResponse.StringOf("userFullName")
emailAddress = jsonResponse.StringOf("emailAddress")
agentServicesAccountNumber = jsonResponse.StringOf("agentServicesAccountNumber")
}
{
"userId": "370854406090",
"password": "olkuo6s1i8aH",
"userFullName": "Westley Uddin",
"emailAddress": "westley.uddin@example.com",
"agentServicesAccountNumber": "NARN0235694"
}