Issues with Beta API for get identity in spring boot project

Hi,

I can see response for get identity API /beta/identities?filters=alias eq “123456” in postman.

I am updating existing spring boot project to replace the deprecated API with above endpoint. But I get 400.

I print the URL for debugging and it looks correct. I even used the same URL I have in spring boot code in postman and I get the response in postman. But spring boot code is returning 400.

See error in logs below. I renamed org name in URL for security purposes.

2024-03-22 15:39:51,991 DEBUG com.mycompany.contractormgmt.service.IDNService - IDN User details URL: [Preformatted text](https://mycompany-sb.api.identitynow.com/beta/identities?filters=alias%20eq%20%22123456%22)
2024-03-22 15:39:52,093 DEBUG com.mycompany.contractormgmt.service.IDNService - IDNService :: getUserDetailsFromIDN :: HttpStatusCodeException = org.springframework.web.client.HttpClientErrorException$BadRequest: 400 : “{“detailCode”:“400.1 Bad request content”,“trackingId”:“96f48240c65042ba95d963814350cdf9”,“messages”:[{“locale”:“en-US”,“localeOrigin”:“DEFAULT”,“text”:“The request was syntactically correct but its content is semantically invalid.”},{“locale”:“und”,“localeOrigin”:“REQUEST”,“text”:“The request was syntactically correct but its content is semantically invalid.”}],“causes”:}”

Are you able to inspect the logs to check what is request being sent? Exactly what is the URL formed

Hi @peratkar,

Try same thing with postman and as you say it’s work perfectly.

You must double check your query param filters if it’s really in your script.

For example when add something wrong (double quote in filters param value) in query params i have same error :

This is what i am printing the URL in logs. https://mycompany-sb.api.identitynow.com/beta/identities?filters=alias%20eq%20%22123456%22

If I take same URL and send the request in postman, it returns 200 response. But in code it is returning 400

here is the code as well…

String authHeader = "Bearer " + authService.getIDNAccessToken();
    logger.trace("IDNService :: getUserDetailsFromIDN :: Bearer authHeader = " + authHeader);

    HttpHeaders headers = new HttpHeaders();
    headers.add(ContractorManagementConstants.AUTHORIZATION, authHeader);
    headers.add(ContractorManagementConstants.ACCEPT, MediaType.APPLICATION_JSON_VALUE);

    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(config.getIdn().getUserDetails().getUrl())
            .queryParam("filters", "alias eq \"" + userWWID + "\"");

    logger.debug("IDN User details URL:" +builder.toUriString());

    HttpEntity<String> entity = new HttpEntity<>(headers);
    logger.debug("Headers : " +entity.getHeaders());
    RestTemplate restTemplate = new RestTemplate();
    try {
        ResponseEntity<IDNResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity,
                IDNResponse.class);

        logger.debug("IDNService :: getUserDetailsFromIDN :: response = " + response);

Hi @peratkar ,

Thanks for sharing details. I have not tested below code , but do give it a try -

UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(config.getIdn().getUserDetails().getUrl())
            .queryParam("filters", URLEncoder.encode("alias eq \"" + userWWID + "\"","UTF-8")).build();

Hi @peratkar,

With a basic sprint boot project i reproduce your issue.

And the came from :

 UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(config.getIdn().getUserDetails().getUrl())
            .queryParam("filters", "alias eq \"" + userWWID + "\"");

You can build manually your url like :

String finalUrl = config.getIdn().getUserDetails().getUrl()+ "?filters=alias eq \"" + userWWID + "\"";

And you can directly use finalUrl directly in your restTemplate.exchange(finalUrl ,…

Below simple code that work :

package com.example;

import java.net.http.HttpHeaders;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

/**
 * Simple test ISC api with sprint boot project!
 *
 */
public class App {
    public static void main(String[] args) {
        String baseUrl = "https://tenant.api.identitynow.com/beta/identities";
        String userWWID = "[email protected]";
        String formattedUserWWID = "\"" + userWWID + "\"";
        String authHeader = "Bearer xxxxx";

        // Create HttpHeaders based on an existing instance
        MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();

        headers.add("Authorization", authHeader);
        headers.add("Accept", "application/json");

        String url1 = baseUrl + "?filters=alias eq \"" + userWWID + "\"";
        // Output the constructed URL
        HttpEntity<String> entity = new HttpEntity<>(headers);

        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<String> response = restTemplate.exchange(url1, HttpMethod.GET, entity, String.class);
        System.out.println("Response: " + response.getBody());

    }
}

thank you very much. This resolved the issue.

1 Like