# Updating Variable with Terraform Cloud API 404s

**URL:** <https://discuss.hashicorp.com/t/updating-variable-with-terraform-cloud-api-404s/12260>\
**Category:** HCP Terraform\
**Tags:** hcp-terraform\
**Created:** [July 31, 2020, 3:16pm UTC](https://discuss.hashicorp.com/t/updating-variable-with-terraform-cloud-api-404s/12260 "2020-07-31T15:16:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![buddylindsey](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/buddylindsey/32/10039_2.png) [@buddylindsey](https://discuss.hashicorp.com/u/buddylindsey)\
**Post date:** [July 31, 2020, 3:16pm UTC](https://discuss.hashicorp.com/t/updating-variable-with-terraform-cloud-api-404s/12260/1 "2020-07-31T15:16:10Z")

</div>

I am trying to use the API to upgrade variables, but I am getting a 404 back from the url.

I tried to build the url myself, and got a 404.

So then I tried pulling the list of variables from the api. Finding the one I wanted to update, and grabbing the `link` prepending the base url, and making a post to it. Still I get a 404.

The URL I call is `https://app.terraform.io/api/v2/workspaces/ws-xxxxxx/vars/var-xxxxxx`.

Am I doing something wrong?  
Is the new api not functional and I need to use the old variable api to update?

---

<div class="post-metadata">

**Author:** ![alisdair](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/alisdair/32/4227_2.png) [@alisdair](https://discuss.hashicorp.com/u/alisdair)\
**Post date:** [July 31, 2020, 3:26pm UTC](https://discuss.hashicorp.com/t/updating-variable-with-terraform-cloud-api-404s/12260/2 "2020-07-31T15:26:05Z")

</div>

[Here are the API docs for updating variables on Terraform Cloud](https://www.terraform.io/docs/cloud/api/variables.html#update-variables). Note that the URL is `/api/v2/vars/:variable_id`, and the request method is `PATCH`, not `POST`. Hope this helps!

---

<div class="post-metadata">

**Author:** ![buddylindsey](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/buddylindsey/32/10039_2.png) [@buddylindsey](https://discuss.hashicorp.com/u/buddylindsey)\
**Post date:** [July 31, 2020, 3:28pm UTC](https://discuss.hashicorp.com/t/updating-variable-with-terraform-cloud-api-404s/12260/3 "2020-07-31T15:28:56Z")

</div>

Okay I can do that. This is where I was getting confused because of the note at the top saying it is deprecated and move to the workspace variables api.

```auto
Important: The Variables API is deprecated and will be removed in a future release. All existing integrations with this API should transition to the Workspace Variables API.

```

I guess i’ll just use that until it doesn’t work anymore.

---

<div class="post-metadata">

**Author:** ![alisdair](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/alisdair/32/4227_2.png) [@alisdair](https://discuss.hashicorp.com/u/alisdair)\
**Post date:** [July 31, 2020, 3:31pm UTC](https://discuss.hashicorp.com/t/updating-variable-with-terraform-cloud-api-404s/12260/4 "2020-07-31T15:31:01Z")

</div>

Oh! You’re absolutely right, I had missed that. Perhaps the problem you’re having with the other API call is the use of `POST` vs `PATCH`?

---

<div class="post-metadata">

**Author:** ![buddylindsey](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/buddylindsey/32/10039_2.png) [@buddylindsey](https://discuss.hashicorp.com/u/buddylindsey)\
**Post date:** [July 31, 2020, 3:31pm UTC](https://discuss.hashicorp.com/t/updating-variable-with-terraform-cloud-api-404s/12260/5 "2020-07-31T15:31:32Z")

</div>

I’ll give that a shot real quick.

---

<div class="post-metadata">

**Author:** ![buddylindsey](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/buddylindsey/32/10039_2.png) [@buddylindsey](https://discuss.hashicorp.com/u/buddylindsey)\
**Post date:** [July 31, 2020, 3:36pm UTC](https://discuss.hashicorp.com/t/updating-variable-with-terraform-cloud-api-404s/12260/6 "2020-07-31T15:36:02Z")

</div>

That was totally it. I was getting confused because of this line.

```auto
This POST endpoint requires a JSON object with the following properties as a request payload.

```

Even though above it says

```auto
PATCH /workspaces/:workspace_id/vars/:variable_id

```

Man I feel dumb.

Thank you for the help.

---

<div class="post-metadata">

**Author:** ![alisdair](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/alisdair/32/4227_2.png) [@alisdair](https://discuss.hashicorp.com/u/alisdair)\
**Post date:** [July 31, 2020, 3:43pm UTC](https://discuss.hashicorp.com/t/updating-variable-with-terraform-cloud-api-404s/12260/7 "2020-07-31T15:43:51Z")

</div>

Ah, thanks for pointing that out! [I’ve opened a PR to fix up the typo](https://github.com/hashicorp/terraform-website/pull/1378).
