Skip to content

POST/Create Resource Samples

The three POST samples accept an order as JSON, create it in Sage through the connector, and return the created order to the client.

Five boxes in a row: a WebAPI Reader to accept the request, standard transform logic, a JSON Reader to parse the request body, standard transform logic with a Sage 300 connector to complete the request, and a JSON writer to write the response to the client

Making the Request

Postman with a POST request to http://localhost/IManWebAPI/sage300order, its Body tab set to raw JSON, and an order in the body

Url

Method Url
Sage 200 POST http://localhost/IManWebAPI/sage200order
Sage 300 POST http://localhost/IManWebAPI/sage300order
Sage X3 POST http://localhost/IManWebAPI/sagex3order

Authorisation

Every sample endpoint requires authentication. Set the request's authorisation to Basic Auth, with the username and password of the sample web user for the endpoint.

Postman's Authorization tab with Type set to Basic Auth, Username sage300 and the password hidden

Web User Setup

The Edit Web User dialog for SAGE300: Http Authentication Type Basic Authentication, the User Token, Username sage300, and Enabled ticked

Headers

Two request headers complete the request.

Postman's Headers tab with the two headers Debug, True, and X-User-Token, holding the web user's token, beneath the headers Postman adds itself. A callout marks the two

X-User-Token

The web user's User Token, from its setup. The username in the Authorization header and this token must belong to the same user; the token finds the user, and the username and password authenticate it.

Debug

True routes the request to the Designer, where the reader's Refresh Schema picks it up. False, or no Debug header at all, runs the integration.

Body

The body is the order to create. Each sample's items are from its demo company.

Sage 200

{
  "orderNumber": "PO16262773",
  "lineItems": [
    {
      "lineId": 23894,
      "sku": "ACS/BLENDER",
      "qty": 2,
      "description": "Two Blenders for the Kitchen"
    },
    {
      "lineId": 4759,
      "sku": "ACS/ESPRESSO",
      "qty": 1,
      "description": "Woohoo! Coffee!"
    }
  ]
}

Sage 300

{
  "orderNumber": "PO16262773",
  "lineItems": [
    {
      "lineId": 23894,
      "sku": "A1-103/0",
      "qty": 2,
      "description": "A desk lamp"
    },
    {
      "lineId": 4759,
      "sku": "A1-401/0",
      "qty": 1,
      "description": "Some Bulbs"
    },
    {
      "lineId": 82929,
      "sku": "A1-105/0",
      "qty": 1,
      "description": "A Notepad"
    }
  ]
}

Sage X3

{
  "orderNumber": "PO16262773",
  "lineItems": [
    {
      "lineId": 23894,
      "sku": "DIS007",
      "qty": 2,
      "description": "A desk lamp"
    },
    {
      "lineId": 4759,
      "sku": "DIS008",
      "qty": 1,
      "description": "Some Bulbs"
    }
  ]
}

Integration Design

WebAPI Reader

The WebAPI Reader accepts the request and presents it as one record. Two of its fields do the work below: Http.Content, the body, which the JSON Reader parses, and the user property the connector posts the order against.

User Property

The caller's property values arrive as Http.User.<property> fields. The sample property set maps each web user to its customer account, and the connector's mapping takes the order's customer from that field, so a caller can only create orders for itself.

The preview record scrolled to its last columns: Http.User.UserId SAGE300, Http.Content holding the JSON body, and the three property fields Http.User.Sage300CustID, Http.User.Sage200CustID and Http.User.SageX3CustID

Map Transform

The first Map is empty in the samples. It is where the request would be validated before anything is read from it, with the Check function, as the GET samples do.

JSON Reader

The JSON Reader parses the body into fields. Its Source is Transaction and its Field is Http.Content.

The JSON Reader's Setup tab with Source set to Transaction and Field set to Http.Content

From there it is set up like any JSON Reader: its Refresh Schema detects the order and its line items from the queued request.

The JSON Reader's Field Mapping tab with its two transactions, Record and Lines, Lines selected with its Transaction JPath lineItems and its fields ItemCode, LineId, Quantity and Description

Preview shows the order the request carried.

The preview pane showing the order record with orderNumber PO16262773 and, expanded beneath it, its three line items with lineId, sku, qty and description

Map Transform

The second Map holds any field-level transformation the connector needs. The Sage 200 sample sets the warehouse here.

Sage Connector

The connector is set up exactly as it would be for an order read from a file, with the customer taken from the user property.

JSON Writer

A JSON Writer returns the created order to the client: the client's own reference beside the number Sage gave it, and the lines. Its Target is WebAPI, which routes the output back to the client as the response.

The JSON Writer's Setup tab with Target set to WebAPI and, beneath it, the line naming the endpoint

Output

The response is the order as created. While designing, produce it with the steps under Sending the Response.

Postman's response pane showing 200 OK and a JSON body with yourOrderReference PO16262773, ourOrderNumber ORD000000041819 and the three line items