[Python] Azure GraphAPI ISODate Input

Discussão em 'Python' iniciado por Stack, Julho 18, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to setup date on Application's password/secrets in Azure using API as per documentation Here and Here

    As per document default StartDateTime = current time and EndDateTime = startDateTime +2 years. I am trying to set EndDateTime = startDateTime + 60 days but default API is setting up to `EndDateTime = startDateTime +2 years'. I went through all possible documentation, ChatGPT but still not able to figure the issue. There is no error, so its becoming very difficult to find the cause.

    Anyone have faced this issue before, Please advise.

    print(f"inside add_application_password_rest: {application_id}")
    access_token = self.get_authorization_token()
    print(f"access_token: {access_token}")
    url = f"https://graph.microsoft.com/v1.0/applications/{application_id}/addPassword"

    start_date = datetime.now(timezone.utc)
    end_date = start_date + timedelta(days=60)
    # Format in ISO 8601 format with 'Z' suffix
    start_date_str = start_date.strftime('%Y-%m-%dT%H:%M:%S.%fZ')
    end_date_str = end_date.strftime('%Y-%m-%dT%H:%M:%S.%fZ')
    logger.info("end_date: %s", end_date)
    logger.info("start_date_str, end_date_str: %s, %s", start_date_str, end_date_str)


    payload = json.dumps({"passwordCredential": {"displayName": "KeyRenewal","startDateTime":start_date_str,"endDateTime":end_date_str}})
    response = requests.post(url=url,headers={'Authorization': f'Bearer {access_token}',"Content-Type": "application/json"},json=payload)
    logger.info("add_application_password_rest response: %s",response)
    logger.info(f"add_application_password.status_code: ${response.status_code}")
    response.raise_for_status()
    json_response = response.json()
    logger.info("json_response: %s",json_response)

    Continue reading...

Compartilhe esta Página