profile
viewpoint

Ask questionsUnable to view any output

Hi,

I am trying to do some GETS on an API which returns JSON's inside a list. The output query that I am trying to use is as below

data "restapi_object" "test" {
  path = "/api/credentials"
  search_value = "test-creds"
  search_key = "credentials_name"
}
  value = jsondecode(data.restapi_object.test.api_response)
}

What am I doing wrong? Niraj

Mastercard/terraform-provider-restapi

Answer questions gangofnuns

So to answer your question, Niraj8241 -- I think you may need the results_key to retrieve your array.

Error: api_object.go: The results of a GET to '/users/foo_user' did not return an array. It is a 'map[string]interface {}'. Perhaps you meant to add a results_key?

Alas, it looks like golang datatypes are leaking in. From the docs:

results_key (string, required): When issuing a GET to the path, this JSON key is used to locate the results array. The format is 'field/field/field'. Example: 'results/values'. If omitted, it is assumed the results coming back are already an array and are to be used exactly as-is

So the data resource expects a '/' separated, path-like string which is used to navigate to the desired array within the nested data returned from the API. Implying that you can only search for arrays.
AFAICT, looking for anything else (such as a user record) will cause an error.

Hi,

I am trying to do some GETS on an API which returns JSON's inside a list. The output query that I am trying to use is as below

data "restapi_object" "test" {
  path = "/api/credentials"
  search_value = "test-creds"
  search_key = "credentials_name"
}
  value = jsondecode(data.restapi_object.test.api_response)
}

What am I doing wrong? Niraj

useful!

Related questions

No questions were found.
source:https://uonfu.com/
answerer
Marc Anthony Slayton gangofnuns First2Know, Inc. Bay Area, CA https://www.linkedin.com/in/marc-anthony-slayton-b34187/ Software Engineer, Security Buff, and DevOps Architect.
Github User Rank List