Search code examples
c#.netasp.net-coremaximomaximo-anywhere

MAXIMO API 7.6.1 POST to create service requests programmatically creates null records, but the same work in POSTMAN


I am trying to use MAXIMO 7.6.1 API to create requests in MAXIMO through POST requests programmatically.

Problem 1:

The problem is, though the POST is successful .i.e I am getting a 201.

Only null records are being created.

However the same request when done using POSTMAN works perfectly.

Here is my programmatic implementation:

    var jsonData = JsonConvert.SerializeObject(somemodel);
    string MaximoUrl = @"someurl/maxrest/oslc/os/mxapisr";
    WebRequest request = (HttpWebRequest)WebRequest.Create(MaximoUrl);
    request.Headers["authheaderkey"] = "authheadervalue";
    request.Headers["properties"] = "*";
    request.Method = "POST";
    request.ContentType = "application/json";

    using (var RequestStream = new StreamWriter(request.GetRequestStream()))
            {
                RequestStream.Write(jsonData);
            }

            string ResponseResult;

            HttpWebResponse RequestResponse = (HttpWebResponse)request.GetResponse();
            using (var ResponseReader = new StreamReader(RequestResponse.GetResponseStream()))
            {
                ResponseResult = ResponseReader.ReadToEnd();
            }

The above creates a record but creates null records.

Same in POSTMAN: request Headers

Request body

Problem 2:

When I include query string parameters in the request url I get a 400 Bad Request. Again, the same works in POSTMAN.

This works:

string MaximoUrl = @"someurl/maxrest/oslc/os/mxapisr";

This doesn't:

string MaximoUrl = @"someurl/maxrest/oslc/os/mxapisr?lean=1";

I believe this is a problem with how MAXIMO understands requests.

model being sent:

public class obj
    {
        public Int64 ticketuid { get; set; }

        public string ticketid { get; set; }

        public string description { get; set; }

        public string reportedby { get; set; }

        public int rc { get; set; }

        public string workt { get; set; }

        public string ownergroup { get; set; }

        public string siteid { get; set; }

        public string reportedemail { get; set; }

        public string affectedemail { get; set; }

        public DateTime? changedate { get; set; }

        public DateTime? affecteddate { get; set; }

        public DateTime? reportdate { get; set; }

        public DateTime? statusdate { get; set; }

        public DateTime? desireddate { get; set; }

        public string description_longdescription { get; set; }

        public string assetnum { get; set; }

        public string location { get; set; }

        public string status { get; set; }

    }

Solution

  • When using the Maximo REST API to create objects in Maximo, don't forget to use the lean flag. If you don't specify this parameter you need to qualify each attribute with its namespace in your request's body.

    Example without lean flag:

    http://maximohost/maximo/oslc/os/MXASSET
    

    Without the lean flag you'd need to provide the namespace for each attribute:

     {
            "spi:assetnum": "PUMP01",
            "spi:description": "Some Pump",
            "spi:siteid": "BEDFORD"
     }
    

    And if you don't provide the namespace qualifier you'll get empty records because Maximo won't be able to map any of the attributes in your request's body with the object structure's definition.

    Also, make sure that the attributes that you want to set are not excluded at the object structure level.

    Ref.: https://developer.ibm.com/static/site-id/155/maximodev/restguide/Maximo_Nextgen_REST_API.html