Put Request throwing 401 [no body] Unauthorized

37 views Asked by At

I am trying to call an api to put a request but it is throwing a 401 unauthorized error. I have added all the necessary headers but still getting the same error. I just need another eye on this; Code below:

    HttpHeaders headers = getJsonExchangeHeaders();
    headers.setBearerAuth(BearerTokenUtil.getBearerToken());

    HttpEntity<PhoneNumberVerificationDto> entity = new HttpEntity<>(phoneNumberVerificationDto, headers);
    ResponseEntity<String> response;
    try {
        response = restTemplate.exchange(URI.create(url), HttpMethod.PUT, entity, String.class);
        if (response.getStatusCode() == HttpStatus.OK) {
            log.info("Customer validation Success for MFA in IDP for: phone:{} with status: {}", phoneNumberVerificationDto.getPhoneNumber(), response.getStatusCode());
            return true;
        } else {
            log.error("Customer validation failed for MFA in IDP for: phone:{} with status: {}", phoneNumberVerificationDto.getPhoneNumber(), response.getStatusCode());
            return false;
        }
    } catch (RestClientException e) {
        throw new RestClientException("Idp facade API error for user with phone number " + phoneNumberVerificationDto.getPhoneNumber(), e);
    }
0

There are 0 answers