Skip to main content
Question

porting your python example code to C# has caused some issues.

  • October 16, 2024
  • 2 replies
  • 35 views

DashBoard

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()['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:

 

 

This topic has been closed for comments

2 replies

Austin Turner
SafetyCulture Crew
Forum|alt.badge.img+2
  • SafetyCulture Crew
  • 36 replies
  • October 16, 2024

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?

 


Austin Turner
SafetyCulture Crew
Forum|alt.badge.img+2
  • SafetyCulture Crew
  • 36 replies
  • October 16, 2024

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.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings