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

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:

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

–header “Authorization: Bearer $TOKEN”
–header “Content-Type: application/vnd.api+json”
–request POST
–data @var-placeholder.json

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!

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:

  "data": {
    "attributes": {
      "description":"some description",
    "relationships": {
      "workspace": {
        "data": {

Thank you, radditude!

Indeed that did the trick! And yes - I just realized that 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!