# Unable to use put method from python for environment API

**URL:** <https://community.dynatrace.com/t/unable-to-use-put-method-from-python-for-environment-api/43426>\
**Category:** Dynatrace API\
**Tags:** credential-vault, dynatrace-api\
**Created:** [January 2, 2024, 4:01pm UTC](https://community.dynatrace.com/t/unable-to-use-put-method-from-python-for-environment-api/43426 "2024-01-02T16:01:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemanth](https://avatars.discourse-cdn.com/v4/letter/h/7993a0/32.png) [@hemanth](https://community.dynatrace.com/u/hemanth)\
**Post date:** [January 2, 2024, 4:01pm UTC](https://community.dynatrace.com/t/unable-to-use-put-method-from-python-for-environment-api/43426/1 "2024-01-02T16:01:45Z")

</div>

Hello,

I am unable to use put method in dynatrace from python requests module, My code is as follows, i am trying to update the credential vault entry it throws the below error,  
{‘error’: {‘code’: 400, ‘message’: ‘Syntax error near line 1 column 6’}}

Seems like there is an issue with “:”

```auto
def put_authtoken_in_dt(vault_id, session_token, name, description):
    url = "https://<host>/e/<env-id>/api/v2/credentials/"+ vault_id
    print(url)
    headers = {
        "accept": "application/json; charset=utf-8",
        "Content-Type": "application/json; charset=utf-8",
        "Authorization": "Api-Token <token>"
    }
    data = {"name": name,
             "id":vault_id,
             "description":description,
             "ownerAccessOnly":"false",
             "type":"TOKEN",
             "token":session_token
             }

    try:
        response = requests.put(url, headers=headers, data=data ,verify=False)
        print(response.request.body)
        if response.status_code < 400:
            print(response.json())
            return True
        else:
            print(response.json())
            return False
    except Exception as e:
        print(e)
        return False

```

Please let me if i am doing something wrong in request headers.

Thanks

---

<div class="post-metadata">

**Author:** ![Pawel\_Zalewski](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/pawel_zalewski/32/8101_2.png) [@Pawel\_Zalewski](https://community.dynatrace.com/u/Pawel_Zalewski)\
**Post date:** [January 3, 2024, 9:52am UTC](https://community.dynatrace.com/t/unable-to-use-put-method-from-python-for-environment-api/43426/2 "2024-01-03T09:52:50Z")

</div>

Hi!

Why you put in authorization

```auto
"Api-Token <token>"

```

token in \<\> brackets. I don’t know if this is a case but maybe try:

DT\_API\_TOKEN=“”

“Authorization”: "Api-Token " + DT\_API\_TOKEN

Have a nice day!

---

<div class="post-metadata">

**Author:** ![Radoslaw\_Szulgo](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/radoslaw_szulgo/32/1977_2.png) [@Radoslaw\_Szulgo](https://community.dynatrace.com/u/Radoslaw_Szulgo)\
**Post date:** [January 3, 2024, 10:49am UTC](https://community.dynatrace.com/t/unable-to-use-put-method-from-python-for-environment-api/43426/3 "2024-01-03T10:49:39Z")

</div>

IMHO the error suggests it’s a payload issue, rather than authorization issue.

If I were you, I’d try with the other method to create a payload object. For example:

Spoiler

```auto
data = { "name": name,
"id":vault_id,
"description":description,
"ownerAccessOnly":"false",
"type":"TOKEN",
"token":session_token
}

```

Then convert the payload to JSON format

Spoilerjson\_payload = json.dumps(payload)

And then send the PUT request with the JSON payload

Spoilerresponse = requests.put(url, data=json\_payload, headers=headers)
