# Unable to create a variable and/or apply a run using APIs

**URL:** <https://discuss.hashicorp.com/t/unable-to-create-a-variable-and-or-apply-a-run-using-apis/21052>\
**Category:** Terraform\
**Tags:** hcp-terraform\
**Created:** [February 17, 2021, 10:19am UTC](https://discuss.hashicorp.com/t/unable-to-create-a-variable-and-or-apply-a-run-using-apis/21052 "2021-02-17T10:19:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![raduoctavian.b](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/raduoctavian.b/32/15966_2.png) [@raduoctavian.b](https://discuss.hashicorp.com/u/raduoctavian.b)\
**Post date:** [February 17, 2021, 10:19am UTC](https://discuss.hashicorp.com/t/unable-to-create-a-variable-and-or-apply-a-run-using-apis/21052/1 "2021-02-17T10:19:40Z")

</div>

Hello everyone,

I’m new to TF and I’m trying to learn about working with APIs - I have a few .json files for setting up some variables and I want to apply a run in the end.

The error I’m getting is a 404: {“errors”:[“Not found”],“success”:false}

I cannot seem to see why that is.

I referred to the following TF documentation:

> **[Variables - API Docs - Terraform Cloud and Terraform Enterprise - Terraform...](https://www.terraform.io/docs/cloud/api/variables.html#create-a-variable)**
>
> Terraform by HashiCorp

> **[Runs - API Docs - Terraform Cloud and Terraform Enterprise - Terraform by...](https://www.terraform.io/docs/cloud/api/run.html#create-a-run)**
>
> Terraform by HashiCorp

And here’s an example of my attempt to create a variable:

curl   
–header “Authorization: Bearer $TOKEN”   
–header “Content-Type: application/vnd.api+json”   
–request POST   
–data @var-placeholder.json   
“[https://app.terraform.io/api/v2/organizations/$ORG/workspaces/hashicat-aws](https://app.terraform.io/api/v2/organizations/%24ORG/workspaces/hashicat-aws)”

According to the documentation the parameter for my POST should be /workspaces/:workspace\_id/vars so I tried addint “/vars” too.

The value of $ORG is correct but I also tried using the value directly in the curl.

All my attempts fail with the same error.

If needed I can also paste the curl verbose output.

I’m sure the issue here must be a silly one yet I cannot seem to fix it.

I really appreciate your help.

Thank you and cheers!  
Radu

---

<div class="post-metadata">

**Author:** ![radditude](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/radditude/32/34989_2.png) [@radditude](https://discuss.hashicorp.com/u/radditude)\
**Post date:** [February 18, 2021, 3:52am UTC](https://discuss.hashicorp.com/t/unable-to-create-a-variable-and-or-apply-a-run-using-apis/21052/2 "2021-02-18T03:52:01Z")

</div>

It looks like you may have gotten turned around in the documentation a bit! To create a variable, you’ll actually want to send your POST request to `https://app.terraform.io/api/v2/vars`, with the workspace specified in the `relationships` block like this:

```auto
{
  "data": {
    "type":"vars",
    "attributes": {
      "key":"some_key",
      "value":"some_value",
      "description":"some description",
      "category":"terraform",
      "hcl":false,
      "sensitive":false
    },
    "relationships": {
      "workspace": {
        "data": {
          "id":"ws-4j8p6jX1w33MiDC7",
          "type":"workspaces"
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![raduoctavian.b](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/raduoctavian.b/32/15966_2.png) [@raduoctavian.b](https://discuss.hashicorp.com/u/raduoctavian.b)\
**Post date:** [February 19, 2021, 8:10pm UTC](https://discuss.hashicorp.com/t/unable-to-create-a-variable-and-or-apply-a-run-using-apis/21052/3 "2021-02-19T20:10:35Z")

</div>

Thank you, radditude!

Indeed that did the trick! And yes - I just realized that [https://app.terraform.io/api/v2/vars](https://app.terraform.io/api/v2/vars) was definitely all that was needed and I got confused with the workspaces documentation on the other hand. How silly of me!

Once again, thank you and all the best!  
Radu
