How to Annotate an Invoice

In this example we take you through how to annotate an invoice while using the Operator API

What you’ll learn

In this article you’ll learn:

  • What Invoice Annotations are
  • How to create Invoice Annotation Types
  • How to add an Invoice Annotation to an Invoice

What are invoice annotations

Invoice Annotations are a way of communicating information about an order from a seller, back to your connected eCommerce system. For example a seller may use Invoice Annotations to communicate that they have received the order and are processing it, or that a line item on the order is on back-order and will therefore be delayed.

In order to use Invoice Annotations:

  • The Operator will have to create a list of Invoice Annotation Types
  • The Seller will select one of those types and add it to an invoice

You can execute these steps using the Marketplacer Operator and Seller Portals, or via the GraphQL API. In this article we cover how you can use Invoice Annotations using the GraphQL API.

GraphQL Queries and Mutations

While we won’t necessarily be using all of the following queries and mutations in this article, we have listed those queries and mutations that can be used to work directly with Invoice Annotations:


Mutation or QueryTypeDescriptionOperatorSeller
InvoiceAnnotationCreateMutationCreate an annotation of a given type on a single invoiceYesYes
InvoiceAnnotationUpdateMutationUpdate an existing annotationYesYes
InvoiceAnnotationResolveMutationSet the status of the annotation to resolvedYesYes
InvoiceAnnotationTypeCreateMutationCreate an Invoice Annotation TypeYesNo
InvoiceAnnotationTypeUpdateMutationUpdate an Invoice Annotation TypeYesNo
InvoiceAnnotationTypeDiscardMutationDestroy an Invoice Annotation TypeYesNo
Any query that can reference the Invoice typeQueryQuerying an invoice will give you access to the annotations on itYesYes

Create an Invoice Annotation Type

This can only be performed by the Operator, an example mutation call is provided below:

    mutation {
      invoiceAnnotationTypeCreate(
        input: {
          attributes: {
            name: "Order Received"
            description: "The order has been received"
            creatableByCustomer: true
            creatableBySeller: true
            creatableByOperator: true
            editableBySeller: true
            editableByCustomer: true
            editableByOperator: true
            resolvableBySeller: true
            resolvableByCustomer: true
            resolvableByOperator: true
            viewableBySeller: true
            viewableByCustomer: true
            viewableByOperator: true
          }
        }
      ) {
        errors {
          field
          messages
        }
        invoiceAnnotationType {
          id
        }
      }
    }

An example response is given below:

    {
      "data": {
        "invoiceAnnotationTypeCreate": {
          "errors": null,
          "invoiceAnnotationType": {
            "id": "SW52b2ljZUFubm90YXRpb25UeXBlLTg="
          }
        }
      }
    }

We will use the invoiceAnnotationType id in the next step.

Adding an Annotation to an Invoice

This step can be performed by either the Seller or the Operator, an example mutation call is provided below:

    mutation{
      invoiceAnnotationCreate(input:
        {
          invoiceId: "SW52b2ljZS0xMDM3Nw=="
          invoiceAnnotationTypeId: "SW52b2ljZUFubm90YXRpb25UeXBlLTg="
          attributes:{
            content: "Picking order"
            resolved: false
          }
        })
      {
        errors{
          field
          messages
        }
        invoiceAnnotation{
          id
        }
      }
    }

In this case we have added an annotation to the Invoice using the `invoiceAnnotationType` `id` from the previous section. You’ll note that at this point we specified that the annotation is not resolved.

Querying for Invoice Annotations

You can access the Invoice Annotations on your invoices using any query that permits you to resolve the invoice type. This can be performed by either the Seller or Operator, for Sellers it should be noted that they only have access to their invoices.

An example of querying an Invoice directly using a node query is shown below:


    query{
      nodes(ids: [
        "SW52b2ljZS0xMDM3Nw=="
      ])
      {
        ... on Invoice {
          legacyId
          id
          statusFlags
          seller{
            businessName
          }
          annotations{
            content
            createdAt
            updatedAt
            invoiceAnnotationType{
              name
            }
            resolved
          }
        }
      }
    }

With an example payload as shown below

    {
      "data": {
        "nodes": [
          {
            "legacyId": 10377,
            "id": "SW52b2ljZS0xMDM3Nw==",
            "statusFlags": [
              "PAID"
            ],
            "seller": {
              "businessName": "ACME Corp."
            },
            "annotations": [
              {
                "content": "Picking Order",
                "createdAt": "2022-11-17T10:52:13+11:00",
                "updatedAt": "2022-11-17T10:52:13+11:00",
                "invoiceAnnotationType": {
                "name": "Order Received"
              },
              "resolved": false
              }
            ]
          }
        ]
      }
    }

Marking an annotation as resolved

When we created the annotation initially, we set its resolved status to false, we can now update to true to reflect the “completion” of this annotation type.

This can be performed by either the Operator or Seller, and example mutation is given below.

    mutation{
      invoiceAnnotationResolve(input:
        {
          invoiceAnnotationId: "SW52b2ljZUFubm90YXRpb24tNDI="
        })
      {
        errors{
          field
          messages
        }
        invoiceAnnotation{
          id
        }
      }
    }