Sending a response code

Sending an Interaction response code can be useful when displaying Optimizations programmatically and capturing the user's response.

Tip: When sending an Interaction response code programmatically, ensure the Interaction is a fully qualified URI, containing the scheme, authority, and path. For example, ios://touchpoint/interaction.

To send a response code, call the method shown below by passing the response code and the corresponding Interaction path as parameters:

if let responseCode = try? MXOResponseCode(withResponseCode: "responseCode"), let interaction = try? MXOInteraction(withString: "/InteractionPath") {
	do {
		try MedalliaMXO.sendInteraction(responseCodeRequest: MXOResponseCodeRequest { builder in
                	builder.interaction = interaction
                        builder.responseCode = responseCode
                        builder.onError = { error in
                        	print("Error sending response code: \(error.localizedDescription)")
                        }
                        builder.onSuccess = { response in
                        	do {
                                	try MedalliaMXO.process(response: response)
                            	} catch {
                                	print("Error processing response: \(error)")
                            	}
                        }
                })
	} catch {
		print("Error sending response code: \(error.localizedDescription)")
	}
}
__block NSError *error;
__block MXOResponseCode *responseCode = [MXOResponseCode initWithResponseCode:@"responseCode" error:&error];
MXOInteraction *interaction = [MXOInteraction initWithString:@"/InteractionPath" error:&error];
[MedalliaMXO sendInteractionResponseCode:[MXOResponseCodeRequest initWithBuilder:^(MXOResponseCodeRequestBuilder * _Nonnull builder) {
	builder.interaction = interaction;
        builder.responseCode = responseCode;
        builder.onError = ^(NSError *error) {
            NSLog(@"Error sending response code: %@", [error debugDescription]);
        };
        builder.onSuccess = ^(MXOInteractionResponse *response) {
            [MedalliaMXO processResponse:response error:&error];
        };
}] error:&error];

This sends a PUT request to Medallia Experience Orchestration.