List products for a tenant

WARNING

This API is in alpha and may be subject to change. Therefore, we do not recommend using this in production.

Interested in this feature? Please reach out to products@wgtwo.com

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": "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.",
      "icon": {
        "url": "https://picsum.photos/512?random=10"
      },
      "banner": {
        "url": "https://picsum.photos/1024/512?random=10"
      },
      "images": [
        {
          "url": "https://picsum.photos/1024?random=310"
        },
        {
          "url": "https://picsum.photos/1024?random=210"
        }
      ]
    },
    {
      "id": "6",
      "name": "Product 6",
      "subtitle": "Product 6 subtitle",
      "productUrl": "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.",
      "icon": {
        "url": "https://picsum.photos/512?random=6"
      },
      "banner": {
        "url": "https://picsum.photos/1024/512?random=6"
      }
    }
  ]
}
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
Install dependencies

Maven

<dependency>
  <groupId>com.wgtwo.api.v0.grpc</groupId>
  <artifactId>products</artifactId>
  <version>0.3.0</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: "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."
  icon {
    url: "https://picsum.photos/512?random=10"
  }
  banner {
    url: "https://picsum.photos/1024/512?random=10"
  }
  images {
    url: "https://picsum.photos/1024?random=310"
  }
  images {
    url: "https://picsum.photos/1024?random=210"
  }
}
products {
  id: "8"
  name: "Product 8"
  subtitle: "Product 8 subtitle"
  product_url: "https://product8.example"
  description: "Product 8 description. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
  icon {
    url: "https://picsum.photos/512?random=8"
  }
  banner {
    url: "https://picsum.photos/1024/512?random=8"
  }
}
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

Read more