This repository was archived by the owner on Jun 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathReseller.java
More file actions
82 lines (69 loc) · 2.89 KB
/
Reseller.java
File metadata and controls
82 lines (69 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*********************************************************
* *
* Copyright (C) Microsoft. All rights reserved. *
* *
*********************************************************/
package microsoft.partner.csp.api.v1.samples;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.UUID;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class Reseller {
private String resellerCid;
public Reseller()
{
}
// This method is used to retrieve the reseller cid given the reseller microsoft id, and is used to perform any transactions by the reseller
// param name="resellerMicrosoftId", Microsoft ID of the reseller
// returns: Reseller cid that is required to use the partner apis
public String getResellerCid(String resellerMicrosoftId, String saToken)
{
String requestUrl = String.format("%s%s%s", PartnerAPiCredentialsProvider.getPropertyValue("ApiEndpoint"), "/customers/get-by-identity?provider=AAD&type=tenant&tid=", resellerMicrosoftId);
System.out.println("Request Url = " + requestUrl);
HttpResponse response = null;
CloseableHttpClient client = HttpClientBuilder.create().build();
String responseBody;
HttpGet getRequest = new HttpGet(requestUrl);
try
{
String guid = UUID.randomUUID().toString();
String authorization = String.format("%s%s", "Bearer ",saToken);
getRequest.addHeader("Accept", "application/json");
getRequest.addHeader("Authorization", authorization);
getRequest.addHeader("api-version", "2015-03-31");
getRequest.addHeader("x-ms-correlation-id", guid);
getRequest.addHeader("x-ms-tracking-id", guid);
response = client.execute(getRequest);
responseBody = CrestApiUtilities.parseResponse(response);
JSONParser parser = new JSONParser();
JSONObject jsonResponse = (JSONObject) parser.parse(responseBody);
resellerCid = (String)jsonResponse.get("id");
client.close();
}
catch (ClientProtocolException e)
{
System.out.println("Client Protocol Exception Occured - " + e.getMessage());
}
catch (UnsupportedEncodingException ue)
{
System.out.println("Exception occured while creating the request body - " + ue.getMessage());
}
catch (IOException e)
{
System.out.println("IO Exception occured while getting the response - " + e.getMessage());
}
catch (ParseException e)
{
System.out.println("JSON Parse exception occured - " + e.getMessage());
}
System.out.println("Reseller Cid = " + resellerCid);
return resellerCid;
}
}