Getting 204 with Smartsheets put request on Postman but 400 in .NET Core Web API

Options

I am testing the same data in postman verses a .NET Core Web API project, however, one returns fine when content is being updated and another (.NET Core) returns 400. Any ideas on why this may be? It's the same data structures, and even same data.

Answers

  • Genevieve P.
    Options

    Hi @Joshua Silverman

    I'm unable to identify what the cause may be based on this information. Would you be able to post the exact query you're making (removing any sensitive data), what language you're using, and a screen capture of the exact error?

    Thanks,

    Genevieve

    Join us at Smartsheet ENGAGE 2024 🎉
    October 8 - 10, Seattle, WA | Register now

  • Joshua Silverman
    edited 04/16/21
    Options

    Sure.

    Here is my .NET Core (C#) wrapper API.


    [HttpPut("{sheetId}/rows")]

        [ProducesResponseType(StatusCodes.Status200OK)]

        [ProducesResponseType(StatusCodes.Status400BadRequest)]

        public async Task<IActionResult> UpdateSmartSheetRow(long sheetId,

          [FromBody] UpdateSheetRow updateObj)

        {

          string Url = GetSmartSheetUrl();

          if (Url == null) return BadRequest();


          string BearerToken = GetSmartSheetApiToken();

          if (BearerToken == null) return BadRequest();


          httpClient.DefaultRequestHeaders.Authorization =

            new AuthenticationHeaderValue("Bearer", BearerToken);

          httpClient.DefaultRequestHeaders

              .Accept

              .Add(new MediaTypeWithQualityHeaderValue("application/json"));

          try

          {

            HttpResponseMessage response = 

              await httpClient.PutAsJsonAsync(Url + sheetId + "/rows/", updateObj);

            if (response.IsSuccessStatusCode)

            {

              return Ok(await response.Content.ReadAsAsync<UpdateSheetRowResponse>());

            }

             

            return StatusCode(400, response.ReasonPhrase);

          }

          catch (Exception ex)

          {

            return StatusCode(500, ex.Message);

          }

        }


  • Genevieve P.
    Options

    Hi @Joshua Silverman

    Thank you for this additional information!

    I blocked out your Bearer token from one image, and I would suggest deleting your current access token and generating a new one since it was displayed for a bit in this public forum.

    I'm still unable to identify what's causing the error; at this point I would suggest reaching out to Smartsheet Support with the same screen captures and data that you have posted here, but also include what JSON response looks like in the 400 error. They'll be able to troubleshoot this with you in a private channel.

    Thanks again,

    Genevieve

    Join us at Smartsheet ENGAGE 2024 🎉
    October 8 - 10, Seattle, WA | Register now