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: android://touchpoint/interaction.

To send a response code, call the mxoSendInteractionResponseCode Kotlin top-level function or the MedalliaMXO.sendInteractionResponseCode Java method, with the response code and the corresponding Interaction path as parameters, as shown below:

Kotlin
Java
import com.medallia.mxo.interactions.MXOInteraction import com.medallia.mxo.interactions.MXOResponseCode import com.medallia.mxo.mxoSendInteractionResponseCode import java.net.URI scope.launch { mxoSendInteractionResponseCode { interaction = MXOInteraction(URI("/InteractionPath")) responseCode = MXOResponseCode("responseCode") } }import com.medallia.mxo.MedalliaMXO; import com.medallia.mxo.interactions.MXOResponseCodeRequest; import com.medallia.mxo.interactions.MXOInteraction; import com.medallia.mxo.interactions.MXOResponseCode; import java.net.URI; final MXOResponseCodeRequest responseCodeRequest = new MXOResponseCodeRequest.Builder() .responseCode(new MXOResponseCode("responseCode")) .interaction(new MXOInteraction(URI.create("/InteractionPath"))) .build(); try { MedalliaMXO.sendInteractionResponseCode(responseCodeRequest); } catch (Exception e) { e.printStackTrace(); }

To capture errors, set the throwErrors parameter to true and wrap the method in a try/catch block, as shown below:

Kotlin
Java
import com.medallia.mxo.interactions.MXOInteraction import com.medallia.mxo.mxoSendInteractionResponseCode import com.medallia.mxo.interactions.MXOResponseCode import com.medallia.mxo.MXOErrorApi import com.medallia.mxo.MXOErrorSdk import java.net.URI scope.launch { try { mxoSendInteractionResponseCode(throwErrors = true) { interaction = MXOInteraction(URI("/InteractionPath")) responseCode = MXOResponseCode("responseCode") } } catch (error: MXOErrorSdk) { Log.e(TAG, "SDK Error: ${error.errorMessage}") } catch (error: MXOErrorApi) { Log.e(TAG, "Api Error: ${error.errorMessage}") } }import com.medallia.mxo.MedalliaMXO; import com.medallia.mxo.interactions.MXOResponseCodeRequest; import com.medallia.mxo.interactions.MXOInteraction; import com.medallia.mxo.interactions.MXOResponseCode; import com.medallia.mxo.MXOErrorApi; import com.medallia.mxo.MXOErrorSdk; import java.net.URI; final MXOResponseCodeRequest responseCodeRequest = new MXOResponseCodeRequest.Builder() .responseCode(new MXOResponseCode("responseCode")) .interaction(new MXOInteraction(URI.create("/InteractionPath"))) .build(); try { MedalliaMXO.sendInteractionResponseCode(true, sendPropertiesRequest); } catch (ExecutionException e) { e.printStackTrace(); } catch (MXOErrorApi mxoErrorApi) { mxoErrorApi.printStackTrace(); } catch (MXOErrorSdk mxoErrorSdk) { mxoErrorSdk.printStackTrace(); } catch (Exception e) { e.printStackTrace(); }

This sends a PUT request to Medallia Experience Orchestration.