Help

Re: Beginner - creating a FETCH? API from a url that is password protected.

Solved
Jump to Solution
3951 1
cancel
Showing results for 
Search instead for 
Did you mean: 
SarahB
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi all,

I'm a complete beginner and have never worked with API's before. So I'm really sorry, but I'm hoping someone could help me, as I've been googling for days and don't know what is what anymore!

I am trying to link my shipping solution (Shipstation) to my Airtable database.

So far, I've managed to successfully set up a webhook, so when an order is shipped, Shipstation sends a webhook to Airtable. However the webhook is just a "resource_url", not actual useful data (like an order number). I've gone to the "resource_url" (which needs a username and password) and it has all the data I need.

So I guess I need to "run a script" and write an API to go and fetch the data from the "resource_url", so I can then use the order number to "update record".

I've added the "resource_url" from the webhook as a variable / input config.

So what I need the script to do is;

  • Go to "resource_url" (which is the input config called SHIPSTATION)
  • Login with Username and password
  • Output the data

Can anyone help? Or point me to a resource that explains where I need to start (to someone who doesn't really know what an API is?)

Many thanks Sarah

1 Solution

Accepted Solutions

Yeap, I recommend checking out the documentation for creating records found here, it should have all the info you need for creating records.

To get the data out of the response, try something like:

 

let config = input.config();
let response = await fetch(config.url, {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Basic U2hpcFN0YXRpb246Um9ja3M='
    },
});
let data = await response.json()
let shipDate = data.shipments[0].shipDate
let orderNumber = data.shipments[0].orderNumber

Then just plug `shipDate` and `orderNumber` into that create records code found above and you should be good to go

 

See Solution in Thread

7 Replies 7

The easiest way for a beginner to work with APIs is to use Make.com.

Not only because they make it super-easy to craft your own API calls when necessary, but more importantly, because they already have built-in support for 1,300+ apps including ShipStation, so you don't have to worry about crafting your own API calls at all! 

If you need further help from my community of Make experts and Airtable API experts, please post at TableForums.com. I am unable to provide more detailed technical support here, because this blogging platform makes it impossible to type up detailed posts. 

You'd need to use a fetch call (Airtable documentation) to the `resource_url` value, parse the output, and then create/update records as needed.

So something like:

let response = await fetch('https://ssapiX.shipstation.com/orders?storeID=123456&importBatch=1ab23c4d-12ab-1abc-a1bc-a12b12cdabcd', {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Basic U2hpcFN0YXRpb246Um9ja3M='
    },
});
console.log(await response.json());

You mentioned you've managed to go to the "resource_url" and it has the data you need, and I assume you did that via a GET request and so know how to get your API authentication stuff?  If not, here's a link to ShipStation's docs on that

Depending on how familiar you are with JavaScript, you might want to just use a third party service like Zapier or something to just deal with this for you though; probably take you 10-15 minutes to set up in Zapier and saves you a bunch of a hassle you know what I mean?

Thank you so much! I've used Zapier before, but would like to set up a few different API's, so thought if I can get one working, I'll understand a bit more about them, and could maybe create my own!

 

 

let config = input.config();
let response = await fetch(config.url, {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Basic U2hpcFN0YXRpb246Um9ja3M='
    },
});
console.log(await response.json());

 

 
So I've used your suggestion (using the input.config url I got from the webhook) and everything I need shows in the Config log. 😄
 
 
CONSOLE.LOG
  • {shipments: Array(1), total: 1, page: 1, pages: 1}
    • shipments: Array(1)
      • 0: Object
        • orderNumber: "89898989"
        • shipDate: "2023-02-06"
        • etc

Now I need to create a new record in to a table (called Shipstation) and fill the Order number and Ship Date with the data showing in the console log.

Is this possible?

Thanks again - I really appreciate your help.

Sarah

 

 

SarahB
5 - Automation Enthusiast
5 - Automation Enthusiast

Thank you, I've used something like this, but wanted to keep them within Airtable. Thanks anyway.

Yeap, I recommend checking out the documentation for creating records found here, it should have all the info you need for creating records.

To get the data out of the response, try something like:

 

let config = input.config();
let response = await fetch(config.url, {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Basic U2hpcFN0YXRpb246Um9ja3M='
    },
});
let data = await response.json()
let shipDate = data.shipments[0].shipDate
let orderNumber = data.shipments[0].orderNumber

Then just plug `shipDate` and `orderNumber` into that create records code found above and you should be good to go

 

Adam you are my hero!!!

It's now working perfectly, meaning I can remove the Zapier step and save myself £100+ a year. Plus I feel like I understand API's a "tiny" bit more.

Full code below - incase anyone else will find this useful.

let config = input.config();
let response = await fetch(config.url, {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Basic U2hpcFN0YXRpb246Um9ja3M='
    },
});
let data = await response.json()
let shipDate = data.shipments[0].shipDate
let orderNumber = data.shipments[0].orderNumber

// Create records in the table
let table = base.getTable("Webhook");
let recordIds = await table.createRecordsAsync([
    {fields: 
        {"shipDate": shipDate, "orderNumber": orderNumber},
    },
]);
console.log("Created " + recordIds.length + " records!");