• Log in
  • Sign up
  • Contact Us

Get in touch  

Getting started with cURL

1

Authenticate

With cURL, you just need to authenticate with your store keys. You can find your store keys in your store dashboard. This request will return an access token for you to use in future requests.

curl -X "POST" "https://api.moltin.com/oauth/access_token" \
        -d "client_id=XXXX" \
        -d "client_secret=XXXX" \
        -d "grant_type=client_credentials"

A simple checkout flow

1

Get products

Using a product ID we can insert a quantity of this product into the cart with one simple request. The first parameter passed is the product ID, the second the quantity to be added to the cart. A third parameter can be added for modifiers and variations (e.g. size and color) if these are set up.

This response should contain an array of the individual cart item data e.g. title, quantity, price. A good example of integrating this would be to add a simple button or form to the product page that posts the product ID and quantity to this endpoint.

curl -X "GET" "https://api.moltin.com/v2/products" \
        -H "Authorization: ACCESS_TOKEN"

2

Add to cart

Using a product ID we can insert a quantity of this product into the cart with one simple request. The first parameter passed is the product ID, the second the quantity to be added to the cart. A third parameter can be added for modifiers and variations (e.g. size and color) if these are set up.

This response should contain an array of the individual cart item data e.g. title, quantity, price. A good example of integrating this would be to add a simple button or form to the product page that posts the product ID and quantity to this endpoint.

curl -X "POST" "https://api.moltin.com/v2/carts/any-unique-string/items" \
        -H "Content-Type: application/json" \
        -H "Authorization: ACCESS_TOKEN" \
        -d $'{
            "data": {
              "type": "cart_item",
              "id": "PRODUCT_ID",
              "quantity": 1
            }
          }'

3

Get cart contents

Now that there is at least one product in the cart let’s get the full cart contents.

This response should contain an array of all cart items and cart totals. A good place to show this data would be on the cart or orders page, or even a widget in the header of your website.

curl "GET" "https://api.moltin.com/v2/carts/any-unique-string/items" \
        -H "Authorization: ACCESS_TOKEN"

4

Convert to order

When the customer is ready to checkout we need to convert the cart to an order. This call lets you define the payment gateway and conditional order parameters such as customer, billing and shipping addresses.

This call will return an object containing data for the newly created order.

curl -X "POST" "https://api.moltin.com/v2/carts/:CART_ID/checkout" \
        -H "Content-Type: application/json" \
        -H "Authorization: ACCESS_TOKEN" \
        -d $'{
            "data": {
              "customer": {
                "name": "John Doe",
                "email": "john@doe.co"
              },
              "shipping_address": {
                "first_name": "John"
                "last_name": "Doe",
                "company_name": "Moltin",
                "line_1": "123 Sunny Street",
                "line_2": "Sunnycreek",
                "postcode": "CA94040",
                "county": "California",
                "country": "US",
                "instructions": "none",
              },
              "billing_address": {
                "first_name": "John"
                "last_name": "Doe",
                "company_name": "Moltin",
                "line_1": "123 Moltin Street",
                "line_2": "Mountain View",
                "postcode": "CA94040",
                "county": "California",
                "country": "US",
              }
            }
          }'

5

Process payment

Once we’ve converted a cart into an order we’re now ready to process a payment. In this example, we’ve used the dummy gateway so we just need to provide some card details. The data you need to provide in this step depends on your chosen gateway.

Congratulations, if you made it this far you’ve implemented a simple step by step checkout!

curl -X "POST" "https://api.moltin.com/v2/orders/:ORDER_ID/payments" \
       -H "Content-Type: application/json" \
       -H "Authorization: ACCESS_TOKEN" \
       -d $'{
           "data": {
             "gateway": "stripe",
             "method": "purchase",
             "first_name": "John",
             "last_name": "Doe",
             "number": "4242424242424242",
             "month": "08",
             "year": "2020",
             "verification_value": "123"
           }
         }'

Ready to get started?

It always starts with a conversation.

Get in touch