Solved

How to create report domain?

  • 14 July 2022
  • 6 replies
  • 44 views

Hello,

Does anybody knows how to create a report folder (also known as domain) via the Ruby SDK?

My report structure looks like the one below, I’ve marked in red the resource that I want to create. It seems that this model is only for folders for metrics and facts, not reports.

GoodData Resource
{
   "report" : {
      "content" : {
         "definitions" : [
            "/gdc/md/qplmsdfsdfsdfsdfsdfsdfsdfsdfsdfqv/obj/1111111"
         ],
         "domains" : [
            "/gdc/md/qplmcrc1ytrn3d817ilflrkdgi6gs1qv/obj/241134"
         ]

      },
      "meta" : {
         "author" : "/gdc/account/profile/sdfsdfsdf",
         "category" : "report",
         "contributor" : "/gdc/account/profile/sdfsdfsdf",
         "created" : "2022-06-24 19:37:08",
         "deprecated" : "0",
         "identifier" : "abv6eR9gfcCa",
         "isProduction" : 1,
         "summary" : "",
         "tags" : "",
         "title" : "Contacts by Category",
         "updated" : "2022-07-14 16:37:07",
         "uri" : "/gdc/md/csdfsdfsdffsdfqv/obj/174472"
      }
   }
}

 

Thanks!

 

 

 

icon

Best answer by Jan Rehanek 15 July 2022, 09:52

View original

6 replies

Userlevel 2

Hello,

Assuming that we’re using project jpigc5ejzqcw38kkw9xkcj2jnx6pg2z9 and with credentials stored in ~/.gooddata, a simple way of creating a folder (domain) is this:

 

require 'gooddata'

client = GoodData.connect()

client.post("/gdc/md/jpigc5ejzqcw38kkw9xkcj2jnx6pg2z9/obj?createAndGet=true", {
"domain"=>{
"meta"=>{
"title"=>"Folder_for_testing",
"summary"=>"",
"tags"=>"",
"deprecated"=>0
},
"content"=>{
"entries"=>[]
}
}
})

 

The result will be visible in https://<domain_id>.com/gdc/md/jpigc5ejzqcw38kkw9xkcj2jnx6pg2z9/query/domains as “Folder_for_testing”, with JSON contents:
 

{
"domain" : {
"content" : {
"entries" : []
},
"meta" : {
"author" : "/gdc/account/profile/c8ec863a97d9a46c2b6e072d8486d3ca",
"category" : "domain",
"contributor" : "/gdc/account/profile/c8ec863a97d9a46c2b6e072d8486d3ca",
"created" : "2022-07-15 09:49:51",
"deprecated" : "0",
"identifier" : "aa6NHhyxGAxq",
"isProduction" : 1,
"summary" : "",
"tags" : "",
"title" : "Folder_for_testing",
"updated" : "2022-07-15 09:49:51",
"uri" : "/gdc/md/jpigc5ejzqcw38kkw9xkcj2jnx6pg2z9/obj/551"
}
}
}


Does this help?

Hi Jan,

Thanks again for responding!

I’m sure that this would work but it seems that I don’t have the permissions? which is weird because I’m using the same client object that I use to create reports, metrics, etc.

I’ve got this response:

403 Forbidden: Invalid operation request_id: :tBxu9Nu_-GDFW9WSnt6OTQ:zn-ju3k-661zl2LHQ2X5Qw:kIjNUZZYGXFzQXH9 (RestClient::Forbidden)
 

Here is my code, is there anything wrong with it?  The first 2 lines I always use them to create the client and project. Does this means that I’m missing some permissions?

 

client = GoodData.connect(options[:user_name], options[:password], server: options[:server] )
project_target = client.projects( data['target_workspace'] )


client.post("#{project_target.uri}/obj?createAndGet=true", {
"domain"=>{
"meta"=>{
"title"=>"Folder_for_testing",
"summary"=>"",
"tags"=>"",
"deprecated"=>0
},
"content"=>{
"entries"=>[]
}
}
})

 

Userlevel 2

Hello,

Your permissions are fine in this case. From what I am seeing, you are sending the request to: /gdc/projects/qplmcrc9ytrn2d919mlflrxdgi6gs1qv/obj?createAndGet=true

The correct endpoint should be: /gdc/md/qplmcrc9ytrn2d919mlflrxdgi6gs1qv/obj?createAndGet=true

If you fix that, it should work fine.

omg that worked! awesome thanks!

Can I ask you something else?

How can I get the uri from a domain using the name? In later runs I want to check if the domain already exists before creating it again. 

 

For metrics folders I would find it like this:

all_folders = GoodData::Folder.all({client: client, project: project_target })

folder = all_folders.find{ |f| f.title == folder_title }

 

Userlevel 2

I don’t think the SDK has any sort of easy-baked solution for the domains in particular the same way it does for attribute/metric folders. What can be done is accessing the GoodData API directly through Ruby:
 

require "gooddata"

client = GoodData.connect()

res = client.get("/gdc/md/jpigc5ejzqcw38kkw9xkcj2jnx6pg2z9/query/domains")

#Iterate over res and "link"


This returns a Ruby hash that matches the structure of this JSON, with one entry in the “entries” array for each domain:
 

{
"query": {
"entries": [
{
"unlisted": 0,
"summary": "",
"created": "2022-07-15 15:32:00",
"identifier": "ac6O4qjefqzl",
"author": "/gdc/account/profile/d61c6cc59f2c996211f3dc3f1aa9c5be",
"category": "domain",
"isProduction": 1,
"title": "Folder_for_testing",
"updated": "2022-07-15 15:32:00",
"locked": 0,
"link": "/gdc/md/jpigc5ejzqcw38kkw9xkcj2jnx6pg2z9/obj/553",
"deprecated": "0",
"tags": "",
"contributor": "/gdc/account/profile/d61c6cc59f2c996211f3dc3f1aa9c5be"
}
],
"meta": {
"summary": "Metadata Query Resources for project 'jpigc5ejzqcw38kkw9xkcj2jnx6pg2z9'",
"title": "List of domains",
"category": "query"
}
}
}


This data structure can then be iterated over. “link” corresponds to the uri and can be filtered programmatically according to your preference. It is a bit more work to do it this way, but I imagine you could write a custom set of functions to abstract the manual work and make it visually consistent with the rest of the SDK. 

amazing, thank you Jan :)

Reply