Confirming Your Registration¶
You must confirm your registration using a GraphQL mutation which takes the following format:
mutation {
confirmRegistration(
confirmationToken: "YOUR CONFIRMATION TOKEN",
password: "YOUR SECURE PASSWORD"
) {
message
}
}
Upon successful registration confirmation, you receive the message "Registration confirmation succeeded. You can log in and begin processing statements."
The examples below illustrate running the mutation in several different languages.
# Terminate lines with \ character to allow command to span multiple lines.
# Escape quotation marks in body of mutation or query with backslashes.
# Use here document for data stream.
# Tested using the bash interpreter on Linux.
curl 'https://sandbox.ottertax.com/v2/graphql' \
-i \
-X POST \
-H 'content-type: application/json' \
-d @- <<END_DATA
{
"query":"
mutation {
confirmRegistration(
confirmationToken: \"YOUR CONFIRMATION TOKEN\"
password: \"YOUR SECURE PASSWORD\"
) {
message
}
}
"
}
END_DATA
:: Terminate lines with ^ character to allow command to span multiple lines.
:: Precede quotation marks in body of mutation or query with triple backslashes.
:: Precede other quotation marks in data stream with single backslashes.
:: Tested using a command prompt on Windows 10.
curl "https://sandbox.ottertax.com/v2/graphql" ^
-i ^
-X POST ^
-H "content-type: application/json" ^
-d "{ \"query\":\" ^
mutation { ^
confirmRegistration( ^
confirmationToken: \\\"YOUR CONFIRMATION TOKEN\\\" ^
password: \\\"YOUR SECURE PASSWORD\\\" ^
) { ^
message ^
} ^
} ^
\" }"
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
// This example uses version 2.9.1 of the
// open source gson library from Google.
// See https://github.com/google/gson.
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
// This example uses httpclient (version 4.5.13)
// and httpcore (version 4.4.13) libraries of the
// open source Apache HttpComponents project.
// See https://hc.apache.org/index.html.
import org.apache.http.entity.StringEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
// Download the OtterTax java classes for the GraphQL
// query and mutation responses at
// https://github.com/OtterTax/graphql-java-classes
import com.ottertax.support.ConfirmRegistrationResponse;
public class RegistrationConfirmer {
private String mutation = "mutation {\n" +
" confirmRegistration(\n" +
" confirmationToken: \"YOUR CONFIRMATION TOKEN\",\n" +
" password: \"YOUR SECURE PASSWORD\"\n" +
" ) {\n" +
" message\n" +
" }\n" +
"}\n";
private String endpoint = "https://sandbox.ottertax.com/v2/graphql";
private void confirm() {
CloseableHttpClient httpClient = HttpClients.createDefault();
try {
HttpPost httpPost = new HttpPost(endpoint);
httpPost.addHeader("Content-Type", "application/json");
StringEntity stringEntity = new StringEntity(querify(mutation));
httpPost.setEntity(stringEntity);
CloseableHttpResponse httpResponse = httpClient.execute(httpPost);
BufferedReader reader = new BufferedReader(new InputStreamReader(
httpResponse.getEntity().getContent()));
StringBuffer responseBuffer = new StringBuffer();
String inputLine;
while ((inputLine = reader.readLine()) != null) {
responseBuffer.append(inputLine);
}
reader.close();
String response = responseBuffer.toString();
int responseCode = httpResponse.getStatusLine().getStatusCode();
if( responseCode == 200 ) {
String successMessage = "Registration confirmation succeeded. " +
"You can log in and begin processing statements.";
Gson gson = new Gson();
ConfirmRegistrationResponse confirmRegistrationResponse = gson.fromJson(response, ConfirmRegistrationResponse.class);
String message = confirmRegistrationResponse.getData().getConfirmRegistration().getMessage();
if(message.equals(successMessage)) {
System.out.println("\nRegistration confirmation succeeded.");
}
else {
System.out.println(message);
System.out.println("Registration failed. Please correct the error above and try again.");
System.exit(1);
}
} else {
System.out.println("Registration failed. Response code from server was " + String.valueOf(responseCode) + ".");
System.exit(1);
}
httpResponse.close();
httpClient.close();
} catch(IOException e) {
System.out.println("Error confirming registration.\nExiting");
System.exit(1);
}
}
private String querify(String rawGraphql) {
Gson gson = new Gson();
return("{\"query\":" + gson.toJson(rawGraphql) + "}");
}
public static void main(String[] args) {
RegistrationConfirmer registrationConfirmer = new RegistrationConfirmer();
registrationConfirmer.confirm();
}
}
// Using graphql-request from
// https://github.com/prisma-labs/graphql-request
// Example tested with node version 14.16.0
import { request, gql } from 'graphql-request'
const query = gql`
mutation {
confirmRegistration(
confirmationToken: "YOUR CONFIRMATION TOKEN",
password: "YOUR SECURE PASSWORD"
) {
message
}
}
`
request('https://sandbox.ottertax.com/v2/graphql', query)
.then((data) => console.log(data))
<?php
// Tested with php-cli version 8.0.5.
$query =<<<'END_DATA'
mutation {
confirmRegistration(
confirmationToken: "YOUR CONFIRMATION TOKEN",
password: "YOUR SECURE PASSWORD"
) {
message
}
}
END_DATA;
$payload = array ('query' => $query);
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode( $payload ),
'header'=> "Content-Type: application/json\r\n"
)
);
$context = stream_context_create( $options );
$response = file_get_contents( 'https://sandbox.ottertax.com/v2/graphql',
false, $context );
if( $response === FALSE ) {
echo "Call to server failed.\n";
} else {
echo $response . "\n";
}
?>
# Using GQL from
# https://github.com/graphql-python/gql
# Tested using python version 3.8.8
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
transport = AIOHTTPTransport(url="https://sandbox.ottertax.com/v2/graphql/")
client = Client(transport=transport, fetch_schema_from_transport=True)
query = gql(
"""
mutation {
confirmRegistration(
confirmationToken: "YOUR CONFIRMATION TOKEN",
password: "YOUR SECURE PASSWORD"
) {
message
}
}
"""
)
result = client.execute(query)
print(result)
# If you wish to use a library instead, see
# https://github.com/github/graphql-client
# Tested using ruby 2.7.2.
require( 'net/http' )
require( 'uri' )
require( 'json' )
query = <<-END_QUERY
mutation {
confirmRegistration(
confirmationToken: "YOUR CONFIRMATION TOKEN",
password: "YOUR SECURE PASSWORD"
) {
message
}
}
END_QUERY
uri = URI( 'https://sandbox.ottertax.com/v2/graphql' )
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request = Net::HTTP::Post.new( uri.request_uri,
{'Content-Type': 'application/json'} )
request.body = {query: query}.to_json
response = http.request(request)
if( response.code == '200' )
json = JSON.parse( response.body )
message = json.dig( 'data', 'confirmRegistration', 'message' )
STDOUT.puts( message )
else
STDOUT.puts( "Response code was #{response.code}:\n#{response.inspect}" )
end