Create consent for subscription

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

  • subscription.consent:write

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 '
  {
    "id": {
      "value": "my_unique_subscription_id_here",
      "tenant": {
        "name": "my_tenant_name_here"
      }
    },
    "productId": "my_product_id_here"
  }' \
  api.wgtwo.com:443 \
  wgtwo.consents.v0.ConsentService/CreateConsentForSubscription
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Example result success

{
  "statusCode": "STATUS_CODE_OK"
}
1
2
3

Example result error

{
  "statusCode": "STATUS_CODE_ACCESS_DENIED",
  "errorMessage": "Error message from fake API that matches the status code"
}
1
2
3
4
Install dependencies

Maven

<dependency>
  <groupId>com.wgtwo.api.v0.grpc</groupId>
  <artifactId>consents</artifactId>
  <version>0.3.0</version>
</dependency>
package com.example.consents

import com.wgtwo.api.v0.common.TypesProto
import com.wgtwo.api.v0.consent.ConsentServiceGrpc
import com.wgtwo.api.v0.consent.ConsentsProto.CreateConsentForSubscriptionRequest
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 = ConsentServiceGrpc.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) {
    val subscriptionId = "my_unique_subscription_id_here"
    val tenant = "my_tenant_name_here"
    val productId = "my_product_id"
    val request = CreateConsentForSubscriptionRequest.newBuilder().apply {
        this.id = TypesProto.SubscriptionIdentifier.newBuilder().apply {
            this.value = subscriptionId
            this.tenant = TypesProto.Tenant.newBuilder().apply {
                this.name = tenant
            }.build()
        }.build()
        this.productId = productId
    }.build()
    println("Request:\n$request")

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

    channel.shutdownNow()
}
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
45
46

Example result success

status_code: STATUS_CODE_OK
1

Example result error

status_code: STATUS_CODE_INTERNAL_ERROR
error_message: "Error message from fake API that matches the status code"
1
2

Read more