Skip to main content

I am moving your python example/same code found at https://github.com/SafetyCulture/safetyculture-sdk-python

to C#.  I am using the structure of the API calls as a reference as to how to do the same in my C# code. 

I have questions and issues.

Let’s have a look at the Python code:

def get_user_api_token(logger):
"""
Generate iAuditor API Token
:param logger: the logger
:return: API Token if authenticated else None
"""
username = input("iAuditor username: ")
password = getpass()
generate_token_url = "https://api.safetyculture.io/auth"
payload = "username=" + username + "&password=" + password + "&grant_type=password"
headers = {
'content-type': "application/x-www-form-urlencoded",
'cache-control': "no-cache",
'sc-integration-id': "safetyculture-sdk-python",
'sc-integration-version': "4.x",
}
response = requests.request("POST", generate_token_url, data=payload, headers=headers)
if response.status_code == requests.codes.ok:
return response.json()s'access_token']
else:
logger.error('An error occurred calling ' + generate_token_url + ': ' + str(response.json()))
return None

How the headers of an API was set successfully was done by using the HTTPRequestMessage class and the .Header.Add command in C# but it did not work out this time.  Please advise.  See the screen shot here:

 

 

Hi, I’m sorry we can’t help you debug your code, but have you found the ability to get c# samples from the developer documentation useful?

 


Also, please note that the python SDK has been deprecated for several years and is not an up to date reference, we will mark the repo as private to avoid confusion for other developers.


Reply