cancel
Showing results for 
Search instead for 
Did you mean: 

Alternatives to CLR Module Import - How to replace Webclient ?

tomdevilder
Discoverer
0 Kudos
282

For calling API's we are using the Webclient (from System.Net import WebClient)

Since importing  .net namespaces or cpq namespaces is no longer possible due this restriction, we need a solution. But in the documentation on the 'Alternatives to CLR Module Import' page there is not trace of this on how to make it work without Webclient

https://help.sap.com/docs/SAP_CPQ/7fc27540a0f14bd1a10b639117a9d4d7/210211e2ddd84124ad23c08ab4e043b3....

Does anyone has an example on how to do it ?

 

Accepted Solutions (0)

Answers (2)

Answers (2)

tomdevilder
Discoverer
0 Kudos

Found it out myself:

 
service_url = "https://service_url"
apiKeyServicePlans = "apikey"
accessToken = "accestoken"
 
headers = {"Authorization": "Bearer " + accessToken, "apikey": apiKeyServicePlans}
resp = RestClient.Get(service_url, headers)
dmonta
Explorer
0 Kudos

Hello,

I do not have an example with WebClient, but with WebRequest.

before:

newRequest = WebRequest.Create(TokenURL)
newRequest.Method = "POST"
newRequest.Headers.Add("AUTHORIZATION", RestClient.GetBasicAuthenticationHeader(Token, Password),)
newRequest.ContentLength = 0
response = newRequest.GetResponse()
data = StreamReader(response.GetResponseStream()).ReadToEnd()
dataInJson = JsonConvert.DeserializeObject(data)
accessToken = dataInJson.access_token.ToString()

After:
headers = { "Authorization": RestClient.GetBasicAuthenticationHeader(Token, Password) }
data = RestClient.Post(TokenURL, "", headers, False)
accessToken = data.access_token.ToString()

Please share your code.