Maximo

 View Only
  • 1.  Post to Maximo gives a Error

    Posted Tue September 06, 2022 09:19 AM
    When posting json to http://localhost/maximo/oslc/os/mxinvvendor
    i get a 
    {
    "oslc:Error": {
    "oslc:statusCode": "400",
    "spi:reasonCode": null,
    "oslc:message": "oslc#expectedobjgotarray"
    }
    }
    when performing a bulk update

    the get is working ok so authorization is not the issue.
    does someone know why this happens?

    my code  C#:

    HttpClient client = new HttpClient();
    client.BaseAddress = new Uri(ms.Url);

    // Add an Accept header for JSON format.
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    client.DefaultRequestHeaders.Add("maxauth", ms.Authorization);


    var pilist = new List<PostPrice>();
    pilist.Add(new PostPrice
    {
    _data = new Data
    {
    SpiBiddate = DateTime.Today,
    SpiBidprice = 2.00
    },
    _meta = new Meta
    {
    method = "PATCH",
    patchtype = "MERGE",
    uri = $"{ms.Url}/6111"
    }
    });
    pilist.Add(new PostPrice
    {
    _data = new Data
    {
    SpiBiddate = DateTime.Today,
    SpiBidprice = 1.00
    },
    _meta = new Meta
    {
    method = "PATCH",
    patchtype = "MERGE",
    uri = $"{ms.Url}/9172"
    }
    });


    HttpContent json = new StringContent(JsonConvert.SerializeObject(pilist), System.Text.Encoding.UTF8,
    "application/json");
    HttpResponseMessage result = client.PostAsync(ms.Url,json).Result;

    ------------------------------
    Theo Leijen
    ------------------------------



    #Maximo
    #MaximoIntegrationandScripting
    #AssetandFacilitiesManagement


  • 2.  RE: Post to Maximo gives a Error

    Posted Wed September 07, 2022 07:29 AM
    resolved by adding

    client.DefaultRequestHeaders.Add("X-method-override", "BULK");

    ------------------------------
    Theo Leijen
    ------------------------------



  • 3.  RE: Post to Maximo gives a Error

    Posted Wed September 07, 2022 08:28 AM
    You should also add the query parameter lean=1 unless you really want the OSLC prefixed namespaces. If nothing else, it reduces the size of the JSON payloads

    ------------------------------
    Steven Shull
    ------------------------------