The Temboo service has moved away from Arduino support. The service access in this older guide will no longer work.

Next, let’s set up your Zendesk alert. Go to the Zendesk > Tickets > CreateTicket Choreo page and, as you did for FedEx, put in your Zendesk credentials and whatever subject and body text you’d like for your alert. Once again, you’ll find that the code for running the Choreo has been generated further down the page. Since you’ve already set up most of your Arduino sketch with your FedEx code, you’ll only need to add a few more lines to bring in the Zendesk functionality. From void loop() in the generated Zendesk code, copy the following lines (note that the inputs in the code below have been replaced with placeholders):

TembooChoreo CreateTicketChoreo(client);

// Invoke the Temboo client
CreateTicketChoreo.begin();

// Set Temboo account credentials
CreateTicketChoreo.setAccountName(TEMBOO_ACCOUNT);
CreateTicketChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
CreateTicketChoreo.setAppKey(TEMBOO_APP_KEY);

// Set Choreo inputs
String EmailValue = "PLACEHOLDER";
CreateTicketChoreo.addInput("Email", EmailValue);
String SubjectValue = "Delivery Alert";
CreateTicketChoreo.addInput("Subject", SubjectValue);
String PasswordValue = "PLACEHOLDER";
CreateTicketChoreo.addInput("Password", PasswordValue);
String CommentValue = "Your package was just delivered!";
CreateTicketChoreo.addInput("Comment", CommentValue);
String ServerValue = "PLACEHOLDER";
CreateTicketChoreo.addInput("Server", ServerValue);

// Identify the Choreo to run
CreateTicketChoreo.setChoreo("/Library/Zendesk/Tickets/CreateTicket");

// Run the Choreo; when results are available, print them to serial
CreateTicketChoreo.run();

while(CreateTicketChoreo.available()) {
 char c = CreateTicketChoreo.read();
 Serial.print(c);
}
CreateTicketChoreo.close();

and paste them into your sketch in the Arduino IDE after

TrackByNumberChoreo.close();

from the FedEx Choreo.

To make sure that the Zendesk ticket is created only if the package is delivered, we want to make the running of the Zendesk Choreo dependent on the FedEx Choreo’s returning True. To do this, we need to do two things. First, we'll store the FedEx response in a variable called “delivered” by declaring

boolean delivered;

before

while(TrackByNumberChoreo.available()) {

and then replacing the lines

char c = TrackByNumberChoreo.read();
Serial.print(c);

with

boolean delivered = TrackByNumber.readStringUntil('\x1E');
delivered.trim();

Second, let’s enclose the CreateTicket lines that we just added in a conditional:

if(delivered == true){

Now, the FedEx TrackByNumber Choreo will run whenever someone trips your sensor, it will return whether or not the package has been delivered and save the response as a variable, and that variable will be checked to determine whether or not a Zendesk ticket should be filed. Your code should look like this (the individual inputs that you provided will be different, of course):

/* Setup shield-specific #include statements */
#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <Temboo.h>
#include "TembooAccount.h" // Contains Temboo account information


WiFiClient client;

int numRuns = 1;   // Execution count, so this doesn't run forever
int maxRuns = 10;   // Maximum number of times the Choreo should be executed


void setup() {
  Serial.begin(9600);
  
  // For debugging, wait until the serial console is connected.
  delay(4000);
  while(!Serial);

  int wifiStatus = WL_IDLE_STATUS;

  // Determine if the WiFi Shield is present.
  Serial.print("\n\nShield:");
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("FAIL");

    // If there's no WiFi shield, stop here.
    while(true);
  }

  Serial.println("OK");

  // Try to connect to the local WiFi network.
  while(wifiStatus != WL_CONNECTED) {
    Serial.print("WiFi:");
    wifiStatus = WiFi.begin(WIFI_SSID, WPA_PASSWORD);

    if (wifiStatus == WL_CONNECTED) {
      Serial.println("OK");
    } else {
      Serial.println("FAIL");
    }
    delay(5000);
  }

  Serial.println("Setup complete.\n");
}

void loop() {
  if (numRuns <= maxRuns) {
    Serial.println("Running TrackByNumber - Run #" + String(numRuns++));

    TembooChoreo TrackByNumberChoreo(client);

    // Invoke the Temboo client
    TrackByNumberChoreo.begin();

    // Set Temboo account credentials
    TrackByNumberChoreo.setAccountName(TEMBOO_ACCOUNT);
    TrackByNumberChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
    TrackByNumberChoreo.setAppKey(TEMBOO_APP_KEY);

    // Set Choreo inputs
    String AccountNumberValue = "PLACEHOLDER";
    TrackByNumberChoreo.addInput("AccountNumber", AccountNumberValue);
    String PasswordValue = "PLACEHOLDER";
    TrackByNumberChoreo.addInput("Password", PasswordValue);
    String TrackingNumberValue = "123456789012";
    TrackByNumberChoreo.addInput("TrackingNumber", TrackingNumberValue);
    String MeterNumberValue = "PLACEHOLDER";
    TrackByNumberChoreo.addInput("MeterNumber", MeterNumberValue);
    String EndpointValue = "test";
    TrackByNumberChoreo.addInput("Endpoint", EndpointValue);
    String AuthenticationKeyValue = "PLACEHOLDER";
    TrackByNumberChoreo.addInput("AuthenticationKey", AuthenticationKeyValue);

    // Identify the Choreo to run
    TrackByNumberChoreo.setChoreo("/Library/FedEx/TrackingAndVisibility/TrackByNumber");

    TrackByNumberChoreo.addOutputFilter(“delivered”, “/SOAP-ENV:Body/CompletedTrackDetails/TrackDetails/StatusDetail/Location/Residential”, “Response”)

    // Run the Choreo; when results are available, print them to serial
    TrackByNumberChoreo.run();

    boolean delivered;

    while(TrackByNumberChoreo.available()) {
      boolean delivered = TrackByNumber.readStringUntil('\x1E');
      delivered.trim();
    }
    
    TrackByNumberChoreo.close();

    if(delivered == true){
      TembooChoreo CreateTicketChoreo(client);

      // Invoke the Temboo client
      CreateTicketChoreo.begin();

      // Set Temboo account credentials
      CreateTicketChoreo.setAccountName(TEMBOO_ACCOUNT);
      CreateTicketChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
      CreateTicketChoreo.setAppKey(TEMBOO_APP_KEY);

      // Set Choreo inputs
      String EmailValue = "PLACEHOLDER";
      CreateTicketChoreo.addInput("Email", EmailValue);
      String SubjectValue = "Delivery Alert";
      CreateTicketChoreo.addInput("Subject", SubjectValue);
      String PasswordValue = "PLACEHOLDER";
      CreateTicketChoreo.addInput("Password", PasswordValue);
      String CommentValue = "Your package was just delivered!";
      CreateTicketChoreo.addInput("Comment", CommentValue);
      String ServerValue = "PLACEHOLDER";
      CreateTicketChoreo.addInput("Server", ServerValue);

      // Identify the Choreo to run
      CreateTicketChoreo.setChoreo("/Library/Zendesk/Tickets/CreateTicket");

      // Run the Choreo; when results are available, print them to serial
      CreateTicketChoreo.run();

      while(CreateTicketChoreo.available()) {
        char c = CreateTicketChoreo.read();
        Serial.print(c);
      }
      
      CreateTicketChoreo.close();
      
    }
  }

  Serial.println("\nWaiting...\n");
  delay(30000); // wait 30 seconds between TrackByNumber calls
}

This guide was first published on Feb 24, 2016. It was last updated on Feb 24, 2016.

This page (Add an Alert) was last updated on Aug 02, 2021.

Text editor powered by tinymce.