API integration

hey, hope someone can help me with this. I know I’m missing something.

we are trying to integrate our Tadabase app with ShipStation so we can get orders, among other things.
I managed to pull the data from shipstation through their endpoint and using JavaScript. the issue I’m having is when I use tadabase endpoint to post the data i just got a “bad request” error. I tested tababase endpoint on postman so i know it works
here are the screenshots

any suggestion would be greatly appreciated. thanks

1 Like

@kruizf201 I think you’d be great to help answer this!

@osgordon please note that exposing your api credentials through the page JS is not recommended.

1 Like

Hi, I used the the TB API a lot, and sometimes it requires more Google script flavor rather than “pure” JS. I can give you an example that it’s working for me, I think the key point is the order of method, headers and payload in the settings variable, also using the function urlFetchApp.fetch instead of using fetch alone. Maybe you can try this.

var creado = [];
for (var i = 0; i < mismaCompany.length; i++) {
    var doc = mismaCompany[i];
    const GAP_URL = "https://api.tadabase.io/api/v1/data-tables/{gapTable}/records";

    var payload = {
        "iteration": i,
        "field_108": doc["field_120"],
        "field_109": lanzamiento,
        "field_110": doc["field_122"][0],
        "field_111": company,
    };

    creado.push(payload);

    var settings2 = {
        "method": "POST",
        "headers": {
            'X-Tadabase-App-id': appId,
            'X-Tadabase-App-Key': apiKey,
            'X-Tadabase-App-Secret': apiSecret,
        },
        "payload": payload
    };

    UrlFetchApp.fetch(GAP_URL, settings2);
}

I can see you are receiving a json from Shipstation, but you need to iterate thru TB to create the records, TB only creates 1 record at a time using the POST

Hi @osgordon @tim.young

Sure, you can do this integration, but first there are some steps for this to be successfull and most important secure:

  1. You want to create the Ship Station API as a pipe:

*For this exaple I used this Ship Station API call



  1. Then you want to use/install Tadabase API Pipe:

  1. Now you have access to the Pipes/Javascript feature for both Pipe services:

  1. Create your custom code, this is my solution approach:
// Promise wrapper for TB.triggerPipe
function shipStationPipe(params) {
  return new Promise((resolve, reject) => {
    TB.triggerPipe('eyJpdiI6ImJ5NGpLclVSV1lxOTRTalNkY0VsZ2c9PSIsInZhbHVlIjoiZnoxWit3aHVvaTRyZ21neXUwZ0xCeWlsT1FlRW1GZDNRdDFVVFE0RHJpcz0iLCJtYWMiOiJhMzNmYjM1NTBlN2Y1ZTBlZmRmYzc2NTlmYTk3ZGYwZWU1ZDRmYmQ4MTA5Y2I3MTU3ZDAyMzc4ZDAyMjcwZjY1In0=', 
      params,
      function(type, response, xhrRespone) {
        if (type === 'success') {
          resolve({type, response, xhrRespone});
        } else {
          reject({type, response, xhrRespone});
        }
      }
    );
  });
}

// Promise wrapper for TB.triggerPipe
function tadabasePipe(params) {
  return new Promise((resolve, reject) => {
    TB.triggerPipe('eyJpdiI6Imw0dkRMRU1ObGZ6blFPd0Z0UDFCY2c9PSIsInZhbHVlIjoicFB0eEd4eU9yU2xCS3RjcUZmZ2pvWk05S3B3Mm1za2hraTRMc1VhRzFWZz0iLCJtYWMiOiJhMDYxOGQwNzNmZWE0ZmU5Y2NlYzM1YjVlYzMwMWVkMDM4Njg5ZjU5YzM3YTBjY2I4NzI5NGJmNjk1NDBhZTVhIn0=',
      params,
      function(type, response, xhrRespone) {
        if (type === 'success') {
          resolve({type, response, xhrRespone});
        } else {
          reject({type, response, xhrRespone});
        }
      }
    );
  });
}

// Async function to execute the pipe
async function processOrder(amount) {
  try {
    const orderParams = {
      orderId: '[ORDER]]'
    };
    
    const getOrder = await shipStationPipe(params);
    
    console.log('Get Order Success');
    
    const tadabaseParams = {
      field_1: getOrder.somefield,
      field_2: getOrder.somefield
    };
    
    const updateTadabase = await tadabasePipe(tadabaseParams);

  } catch (error) {
      
    console.log('Order failed:', error);
    
  }
}

Hope this works for you, happy building!

2 Likes