Order items

orders
order-items
#1

I am trying to implement a My Account page to list orders. Listing of orders work fine, but I am having trouble actually listing the items in an order.

My issue is I’m using customer tokens and according to the permissions page, I should have read access to orders which I do, but it seems order items have different permissions as I am denied access when making the request.

I’m using JavaScript SDK and the following call:
Moltin.Orders.Items(orderId)

EDIT:
I generate a customer token as follows:
Moltin.Customers.Token(email, password)
I then use this token all through my app. To get order I make the following call:
Moltin.Orders.With(‘items’).All(token)
which I assumed would have the items, but it does not which is why I am investigating in the first place

0 Likes

#2

Hi @stephan,

You are correct that you can’t access subresources such as /items and /transactions with the customer token, but including the items with the order request is supported. Are you able to post what is returned from Moltin.Orders.With(‘items’).All(token)?

Thanks,
James

0 Likes

#3

Hi James

The response I get is as follows (data). It looks the same as a regular order response. I did also confirm that the API call makes a request to URL https://api.moltin.com/v2/orders?include=items

{
  "type": "order",
  "id": "a3bf801b-a29a-4c86-b21c-3a2a326040ec",
  "status": "complete",
  "payment": "paid",
  "shipping": "unfulfilled",
  "customer": {
    "name": "Dummy Name",
    "email": "sample@sample.com"
  },
  "shipping_address": {
    "first_name": "fake",
    "last_name": "naem",
    "phone_number": "",
    "company_name": "",
    "line_1": "street",
    "line_2": "",
    "city": "city",
    "postcode": "",
    "county": "county",
    "country": "Country",
    "instructions": ""
  },
  "billing_address": {
    "first_name": "fake",
    "last_name": "naem",
    "company_name": "",
    "line_1": "street",
    "line_2": "",
    "city": "city",
    "postcode": "",
    "county": "county",
    "country": "Country"
  },
  "links": {},
  "meta": {
    "display_price": {
      "with_tax": {
        "amount": 2999,
        "currency": "ZAR",
        "formatted": "R2999"
      },
      "without_tax": {
        "amount": 2999,
        "currency": "ZAR",
        "formatted": "R2999"
      },
      "tax": {
        "amount": 0,
        "currency": "ZAR",
        "formatted": "R0"
      }
    },
    "timestamps": {
      "created_at": "2019-04-02T05:23:31Z",
      "updated_at": "2019-04-02T05:23:31Z"
    }
  },
  "relationships": {
    "items": {
      "data": [
        {
          "type": "item",
          "id": "7f70de67-36a0-4aeb-afd4-bc5310dadec5"
        }
      ]
    },
    "customer": {
      "data": {
        "type": "customer",
        "id": "c64d768f-50a6-4c31-9758-6f9190d6108b"
      }
    }
  }
}
0 Likes

#4

Hi @stephan

I think there should be some additional data attached to that response. The format for included resources would be:

{
  "data": [
    {
       // Order...
    }
  ],
  "links": {
    "current": "https://api.moltin.com/v2/orders?page[offset]=0&page[limit]=1&filter=",
    "first": "https://api.moltin.com/v2/orders?page[offset]=0&page[limit]=1&filter=",
    "last": "https://api.moltin.com/v2/orders?page[offset]=162&page[limit]=1&filter=",
    "prev": "https://api.moltin.com/v2/orders?page[offset]=0&page[limit]=1&filter=",
    "next": "https://api.moltin.com/v2/orders?page[offset]=1&page[limit]=1&filter="
  },
  "meta": {
    "page": {
      "limit": 1,
      "offset": 0,
      "current": 1,
      "total": 163
    },
    "results": {
      "total": 163
    }
  },
  "included": {
    "items": [
      {
        // Included item..
      }
    ]
  }
}

The section you posted is the initial order section, so the included items aren’t inside that section.

0 Likes

#5

Of course, that makes perfect sense and it does work exactly as you described. Thank you very much for your assistance

0 Likes