Reactivate Yammer user via API and PowerShell - yammer

I am trying to workout if it's possible to reactivate a suspended user in Yammer, through the API in PowerShell?
From what I understand, there is no supported endpoint in Yammer for reactivating users, but in the Network Admin UI there is a "Reactivate User" button next to suspended user accounts in the 'Remove Users' section, so there is obviously a way to do this "behind the scenes".
I used Fiddler, to trace the request when clicking the 'Reactivate User' button in the UI, which gave me the URL and content type in the code below.
Edit: I should also add, that the code below is not reactivating the user, but I am getting an 'OK' response and '200' status from the webRequest when executing.
Here is a cut down version of the code I am using:
$reactUserId = read-host -Prompt "Enter user ID"
$headers = Get-BearerToken
$urlToCall = "https://www.yammer.com/companyname.com/admin/reactivate_user?user_id=$($reactUserId)"
$webRequest = Invoke-WebRequest $urlToCall -Method POST -Headers $headers -ContentType "text/html; charset=utf-8"

Related

can't get a token back from epic fhir auth server

I'm not getting a token back from my epic app.
I'm calling my app (PFI_app, non-prod. client id: [my_client_id]) from a browser script:
FHIR.oauth2.authorize({
'client_id':[my_client_id],
'scope':'openid, fhirUser,PATIENT.READ, PATIENT.SEARCH, OBSERVATION.READ, OBSERVATION.SEARCH',
'redirect_uri':[my_redirect_uri],
'state':'abc123',
'aud':'https://fhir.epic.com/interconnect-fhir-oauth/api/fhir/r4'
});
I get prompted to login at signin.epic.com and i use the credentials FHIR (username) and EpicFhir11!(password), which i got from this page: https://fhir.epic.com/Documentation?docId=testpatients.
at my redirect url page i use the following to get the access token:
FHIR.oauth2.ready()
.then(function(client){
myapp.smart = client
console.log(client);
})
BUT, i keep getting the following error message:
Failed to load resource: the server responded with a status of 400 (Bad Request)
app.html:39 https://fhir.epic.com/interconnect-fhir-oauth/oauth2/token
i get another message saying: URL: https://fhir.epic.com/interconnect-fhir-oauth/oauth2/token
unauthorized_client
this leads me to believe that i logged in with an improper user who isn't authorized.
ultimately, i don't get a token. any idea why? is it because I'm using improper login credentials and therfore that user doesn't have access to get a token.
also, I'm using fhir-client.js not, fhir-client-v2.js, is that a problem?
UPDATE:
so I just waited and token issue resolved itself. perhaps there was a time period I had to wait after changing my epic fhir app information at fhir.epic.com. I changed the "Application Audience" from patients to "clinicians and administrative users." I had been logging in to epic when prompted as an admin for many hours before I wrote this post, but I can't think of anything that I changed to my code. I just waited.
now my last remaining problem is that when I try and search for patients from the sandbox with this code:
var obs = await fetch(myapp.smart["state"]["serverUrl"]+"/Patient?address=123%20Main%20St.&address-city=Madison&address-postalcode=53703&address-state=Wisconsin&family=Mychart&gender=Female&given=Allison&telecom=608-123-4567",{
headers:{
"Accept":"application/json+fhir",
"Authorization":"Bearer"+myapp.smart["state"]["tokenResponse"]["access_token"]
}
}).then(function(data){
return data;
});
var response = await obs.json();
console.log( response );
I get another "unauthorized message":
Failed to load resource: the server responded with a status of 401 (Unauthorized) https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4/Patient?address=123%20Main%20St.&address-city=Madison&address-postalcode=53703&address-state=Wisconsin&family=Mychart&gender=Female&given=Allison&telecom=608-123-4567
this is where I got the syntax for structuring this call to the Patient.search resource:
https://fhir.epic.com/Sandbox?api=932
any ideas why I'm unauthorized to make this call? again, I'm logged in using the provider-facing app user credentials listed here: https://fhir.epic.com/Documentation?docId=testpatients (username: FHIR)
UPDATE:
so I changed the FHIR.oauth2.ready call to include the request and it worked. I'm not sure why I couldn't include the provided token as a Bearer token in fetch but the following worked:
var req = "/Patient?address=123%20Main%20St.&address-city=Madison&address-postalcode=53703&address-state=Wisconsin&family=Mychart&gender=Female&given=Allison&telecom=608-123-4567"
FHIR.oauth2.ready( client => client.request(req) ).then(function(output){
console.log(output); /* should include search results for the patient */
});
thanks for any help
To summarize, I changed the FHIR.oauth2.ready call to include the request and it worked.:
var req = "/Patient?address=123%20Main%20St.&address-city=Madison&address-postalcode=53703&address-state=Wisconsin&family=Mychart&gender=Female&given=Allison&telecom=608-123-4567"
FHIR.oauth2.ready( client => client.request(req) ).then(function(output){
console.log(output); /* should include search results for the patient */
});
In addition, I had to wait a period of time, possibly due to the fact that I made some changes in my epic fhir app.

"unable to get local issuer certificate" on Windows with Python and Postman after adding the client certificate

I'm a Data Engineer working in Windows 10.
I'm trying to make a simple Post request in Python to retrieve an authentication token to a custom database service.
My code is as straightforward as possible:
import requests
import ssl
import certifi
url = ""
headers = {'Content_Type': 'application/x-www-form-urlencoded'}
payload = {
'password': '',
'scope': '',
'client_id': '',
'client_secret': '',
'username': '',
'grant_type': ''
}
if __name__ == '__main__':
token_response = requests.request("POST", url, headers=headers, data=payload)
print(token_response.content)
I have removed the payload values as well as the url values for privacy. When I run the code, I get back
and
"Max retries exceeded with url", and "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)".
I am able to sidestep this error by setting verify=False in my Post request, but given that I am handling sensitive data, I cannot do that. I mention that to demonstrate that my credentials do work, and there is clearly something wrong with either the Cinchy certificate, my python setup, or the business network I am working on (VPN? Something else?).
I see from this answer (https://stackoverflow.com/a/67998066/9403186) that it might be that "If you are running under business network, contact the network administrator to apply required configurations at the network level." I am certainly running under a business network, what would the required configurations look like?
Most of the answers out there on this error mention that you need to download the CA certificate of the url (e.g. here Windows: Python SSL certificate verify failed), but I have done that and it is not working. I went to the site, logged in, clicked on the Chrome icon with the lock, and downloaded the certificate as a Base-64 encoded X.509, and added it to my certifi cacert.pem file 'C:\Users\gblinick\AppData\Local\Programs\Python\Python39\lib\site-packages\certifi\cacert.pem' as per https://medium.com/#menakajain/export-download-ssl-certificate-from-server-site-url-bcfc41ea46a2.
Any help here would be greatly appreciated. My hunch is that it has to do with the business network, but I don't know how to check this. Ideas would be fantastic.
Please let me know if I can provide further info.
Thanks so much!
EDIT: The request with Postman also doesn't work, unless I turn off SSL authentication, so clearly it's the same problem and this is not simply an issue with Python.
If I make the same request with Powershell, however, it does work:
# [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$Result = Invoke-WebRequest -Uri $Endpoint -UseBasicParsing -Method 'Post' -Body $Body -Headers $Header -ErrorAction Stop # -SslProtocol Tls
This works whether or not I have the first line commented out or not. It seems like Powershell might have some built in SSL or TLS functionality that Python and Powershell do not. That, or the server somehow expects Powershell to connect and not Postman or Python. Note that I have # -SslProtocol Tls commented out because I was using Powershell 5.1 for which the SslProtocol does not exist.
Ultimately, the answer was super simple: I was downloading the wrong corporate certificate. When downloading the SSL certificate from Chrome, there is a "Certification Path" tab. Mine had 3 certificates in it, I'll call them A, B, and C. B descended from A, and C from B. I made the mistake of downloading C, the lowest level one. When I downloaded A and put it in my cacert.pem file, it worked.

Access ServiceNow API which is okta Enabled

I would like to get list of all Incidents which are in "Awaiting caller feedback State" in ServiceNow. Our servicenow is Okta enabled.
Can you please let us know how can I access Servicenow API which is Okta enabled.
The ServiceNow REST Api uses basic authentication by default. This is separate from the authentication method used to login users. You should be able to use the default example to make a call without worrying about Okta. Here's their Python example:
#Need to install requests package for python
import requests
# Set the request parameters
url = 'https://instance.service-now.com/api/now/table/problem?sysparm_limit=1'
# Eg. User name="username", Password="password" for this code sample.
user = 'username'
pwd = 'password'
# Set proper headers
headers = {"Accept":"application/xml"}
# Do the HTTP request
response = requests.get(url, auth=(user, pwd), headers=headers)
# Check for HTTP codes other than 200
if response.status_code != 200:
print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:', response.content)
exit()
# Decode the XML response into a dictionary and use the data
print(response.content)

How to get reCAPTCHA token to send to curl request

I'm trying to test my backend service which takes a Google reCAPTCHA token and verifies it before proceeding with the request, but each time I want to curl my backend service's endpoint I have to go to the site that is hosting the captcha checkbox, open the network tab in Chrome, click the button, and then manually copy the token from the response into my curl request. Is there a better/easier way to do this? I was hoping that the admin console might have something to help but I don't see anything in there.
In JavaScript you can get reCAPTCHA response by following
let grecaptchaResponse = grecaptcha.getResponse();

Where is the firefox 40.0.3 "Log Request and Response Bodies" check box?

To view the req/res body, it says that I have to enable "Log Request and Response Bodies"
Where's it though? (firefox 40.0.3). If I click a get response from network tab, it shows the headers but nowhere is there place to enable Log req/res bodies".
I am trying to view json data coming in.
Right click in the Console. Example:

Resources