List products for a tenant

WARNING

This API is in alpha and is subject to change. We do not recommend using this in production.

Prerequisites

  1. An OAuth 2.0 client
  2. A client access token

Required scope

  • products.list_for_tenant:read

Code

TIP

You can test our APIs without authorization by targetting sandbox.api.wgtwo.com instead of api.wgtwo.com and removing any authorization from the request/code sample.

Download proto definitions
curl -sL 'https://github.com/working-group-two/wgtwoapis/blob/master/image.bin?raw=true' -o wgtwo.bin
1
export ACCESS_TOKEN="my_client_access_token"
grpcurl -protoset wgtwo.bin \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '
  {
    "tenant": "wotel"
  }
  ' \
  api.wgtwo.com:443 \
  wgtwo.products.v0.ProductService/ListProductsForTenant
1
2
3
4
5
6
7
8
9
10

Example result

{
  "products": [
    {
      "id": "7",
      "name": "Product 7",
      "subtitle": "Product 7 subtitle",
      "productUrl": "https://product7.example",
      "description": "Product 7 description. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
    },
    {
      "id": "10",
      "name": "Product 10",
      "subtitle": "Product 10 subtitle",
      "productUrl": "https://product10.example",
      "description": "Product 10 description. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
    },
    {
      "id": "9",
      "name": "Product 9",
      "subtitle": "Product 9 subtitle",
      "productUrl": "https://product9.example",
      "description": "Product 9 description. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
    }
  ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Install dependencies

Maven

<dependency>
  <groupId>com.wgtwo.api.v0.grpc</groupId>
  <artifactId>products</artifactId>
  <version>0.1.10</version>
</dependency>
package com.example.products

import com.wgtwo.api.v0.products.ProductServiceGrpc
import com.wgtwo.api.v0.products.ProductsProto.ListProductsForTenantRequest
import com.wgtwo.auth.BearerTokenCallCredentials
import io.grpc.ManagedChannelBuilder

/** Use the sandbox environment for testing without authentication */
private val environment = Environment.SANDBOX

private val endpoint = when (environment) {
    Environment.SANDBOX -> "sandbox.api.wgtwo.com"
    Environment.PRODUCTION -> "api.wgtwo.com"
}
private val channel = ManagedChannelBuilder.forAddress(endpoint, 443).build()
private val stub = ProductServiceGrpc.newBlockingStub(channel).apply {
    /**
     * If you are not using the sandbox, you need to add credentials.
     * The BearerTokenCallCredentials class can be found in our auth library.
     */
    if (environment == Environment.PRODUCTION) {
        this.withCallCredentials(BearerTokenCallCredentials { "MY_CLIENT_ACCESS_TOKEN" })
    }
}

fun main(vararg args: String) {
    require(args.size <= 1) { "This program requires 1 or 0 arguments: [tenant-identifier]" }

    val tenant = args.getOrNull(1) ?: "wotel"
    val request = ListProductsForTenantRequest.newBuilder().apply {
        this.tenant = tenant
    }.build()
    println("Request:\n$request")

    val response = stub.listProductsForTenant(request)
    println("Response:\n$response")

    channel.shutdownNow()
}

enum class Environment {
    SANDBOX,
    PRODUCTION,
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

Example result

products {
  id: "6"
  name: "Product 6"
  subtitle: "Product 6 subtitle"
  product_url: "https://product6.example"
  description: "Product 6 description. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
}
products {
  id: "5"
  name: "Product 5"
  subtitle: "Product 5 subtitle"
  product_url: "https://product5.example"
  description: "Product 5 description. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
}
products {
  id: "10"
  name: "Product 10"
  subtitle: "Product 10 subtitle"
  product_url: "https://product10.example"
  description: "Product 10 description. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

Read more