public JSONObject PostRequest()

in src/CsrValidation/java/lib/src/main/java/com/microsoft/intune/scepvalidation/IntuneClient.java [278:353]


    public JSONObject PostRequest(String serviceName, String urlSuffix, String apiVersion, JSONObject json, UUID activityId, Map<String,String> additionalHeaders) throws ServiceUnavailableException, InterruptedException, ExecutionException, ClientProtocolException, IOException, AuthenticationException, IllegalArgumentException, IntuneClientException
    {
        if(serviceName == null || serviceName.isEmpty())
        {
            throw new IllegalArgumentException("The argument 'serviceName' is missing");
        }
        
        if(urlSuffix == null || urlSuffix.isEmpty())
        {
            throw new IllegalArgumentException("The argument 'urlSuffix' is missing");
        }
        
        if(apiVersion == null || apiVersion.isEmpty())
        {
            throw new IllegalArgumentException("The argument 'apiVersion' is missing");
        }
        
        if(json == null)
        {
            throw new IllegalArgumentException("The argument 'json' is missing");
        }
        
        
        String intuneServiceEndpoint = GetServiceEndpoint(serviceName);
        if(intuneServiceEndpoint == null || intuneServiceEndpoint.isEmpty())
        {
            IntuneServiceNotFoundException ex = new IntuneServiceNotFoundException(serviceName);
            this.log.error(ex.getMessage(), ex);
            throw ex;
        }
        
        Set<String> scopes = new HashSet<String>();
        scopes.add(this.intuneResourceUrl + "/.default");
        
        String token = this.msalAuthClient.getAccessToken(scopes);
        
        String intuneRequestUrl = intuneServiceEndpoint + "/" + urlSuffix;
        CloseableHttpClient httpclient = this.getCloseableHttpClient();
        HttpPost httpPost = new HttpPost(intuneRequestUrl);
        httpPost.addHeader("Authorization", "Bearer " + token);
        httpPost.addHeader("content-type", "application/json");
        httpPost.addHeader("client-request-id", activityId.toString());
        httpPost.addHeader("api-version", apiVersion);
        
        if(additionalHeaders != null)
        {
            for (Map.Entry<String, String> entry : additionalHeaders.entrySet())
            {
                httpPost.addHeader(entry.getKey(), entry.getValue());
            }
        }
        
        httpPost.setEntity(new StringEntity(json.toString()));
        
        CloseableHttpResponse intuneResponse = null;
        JSONObject jsonResult = null;
        try 
        {
            intuneResponse = httpclient.execute(httpPost);
            jsonResult = ParseResponseToJSON(intuneResponse, intuneRequestUrl, activityId);
        }
        catch(UnknownHostException e)
        {
            this.log.error("Failed to contact intune service with URL: " + intuneRequestUrl, e);
            serviceMap.clear(); // clear contents in case the service location has changed and we cached the value
            throw e;
        }
        finally 
        {    
            if(httpclient != null)
                httpclient.close();
            if(intuneResponse != null)
                intuneResponse.close();
        }
        return jsonResult;
    }