Freebase MQL query via PowerShell

134 Views Asked by At

Here's the first example from the MQL overview in PowerShell:

$result = Invoke-RestMethod `
    -Uri ('https://www.googleapis.com/freebase/v1/mqlread?query={0}' -f `
        [System.Web.HttpUtility]::UrlEncode(
            (ConvertTo-Json @(@{ 
                type = '/astronomy/planet'; id = @(); name = @(); 
            }))))

Showing the results:

PS C:\> $result.result

type                                 id                                   name                                
----                                 --                                   ----                                
/astronomy/planet                    {/en/earth}                          {Earth}                             
/astronomy/planet                    {/en/venus}                          {Venus}                             
/astronomy/planet                    {/en/mars}                           {Mars}                              
/astronomy/planet                    {/wikipedia/pt_id/1214}              {Mercury}                           
/astronomy/planet                    {/en/jupiter}                        {Jupiter}                           
/astronomy/planet                    {/en/neptune}                        {Neptune}                           
/astronomy/planet                    {/en/saturn}                         {Saturn}                            
/astronomy/planet                    {/en/uranus}                         {Uranus}                            

The MQL cookbook has the following example query:

{
  "q1" : {
    "as_of_time" : "2007-01-09T22:00:56.0000Z",
    "query" : [
      {
        "domain" : "/architecture",
        "id" : null,
        "return" : "count",
        "timestamp" : null,
        "type" : "/type/type"
      }
    ]
  }
}

What's a good way to submit that query via PowerShell?

1

There are 1 best solutions below

0
On
$result = Invoke-RestMethod `
    -Uri (
        'https://www.GoogleAPIs.com/freebase/v1/mqlread?' + 
        ('query={0}' -f [System.Web.HttpUtility]::UrlEncode(
            (ConvertTo-Json -Depth 100 `
                @(
                    @{
                        domain = '/architecture';
                        id = $null;
                        return = 'count';
                        timestamp = $null;
                        type = '/type/type'
                    }
                )
            )
        )) +
        '&as_of_time=2007-01-09'
    )