Getting 400 Bad Request when creating a Batch through the API

Hi there,

I am working on adding the ability to create gift batches to our integration with RENXT.

For some reason, when I post to the https://api.sky.blackbaud.com/gift-batch/v1/giftbatches endpoint (CreateGiftBatch) through our code, I always receive a 400 Bad Request.

The response received the following error:

{
"errors": {
"": [
"Unexpected character encountered while parsing value: . Path '', line 0, position 0."
],
"batch": [
"The batch field is required."
]
},
"type": "urn:blackbaud:model-validation-error",
"title": "One or more validation errors occurred.",
"status": 400,
"detail": "Unexpected character encountered while parsing value: . Path '', line 0, position 0.\\\\nThe batch field is required.",
"instance": "urn:blackbaud:bat-gbapi:",
"values": {
"": null,
"batch": null
},
"trace_id": "91cbe92571d84a1e919e85bc5de919c2",
"span_id": "55d739d58a5b3ab9"
}

This is suggesting that the JSON body is formatted incorrectly. That said, I did a network trace and I can see that the data being sent in the request body looks correct.

This is the request body being sent to the endpoint:

{"batch_number":"VS_8_01-08-2024"}

The content type and security headers look correct on the web request as well.

I tried this through the SKY API console and the request works fine there. I am not sure why it does not work when calling this from our application. Any help on this would be much appreciated.

Thank you,

Dylan Hochreiter

Comments

  • Alex Wong
    Alex Wong Community All-Star
    Tenth Anniversary Kudos 5 Facilitator 4 bbcon 2025 Attendee Badge

    @Dylan Hochreiter
    Let's be more specific here.

    I am working on adding the ability to create Gifts in a batch

    then https://api.sky.blackbaud.com/gift-batch/v1/giftbatches is the incorrect API endpoint, this endpoint creates a gift batch, it does not create gift in batch.

    If you are actually trying to create gift batch, not create a gift in batch, then theAPI endpoint and JSON looks correct. Did you make sure you hit the endpoint with POST and content-type is application/json; charset=utf-8

  • @Alex Wong Thanks for the feedback Alex.

    I agree that start of the post was incorrect, I edited the post so it's more specific. I am trying to create a gift batch.

    The content-type is just set to “application/json” but the charset is not mentioned. Let me try that.

  • @Alex Wong Unfortunately, it still does not work with the content type updated to "application/json; charset=utf-8".

    It's very odd as we call many of the other endpoints the same way without running into an issue like this.

  • Alex Wong
    Alex Wong Community All-Star
    Tenth Anniversary Kudos 5 Facilitator 4 bbcon 2025 Attendee Badge

    @Dylan Hochreiter
    given you tried it on console and it works fine, (and I tried it on my test environment as well and it works). it is not a problem with the SKY API endpoint. Then that least how you are calling it.

    Please provide all the details on the exact info on how you are making the call, the request heaader and body, and response header and body

  • @Alex Wong I am making the call using the .NET HttpWebRequest Class. I use this method for other calls we make to Blackbaud APIs, including calls to the Payments API, Gift API, Fundraising API and Constituent API.

    Here is the details on the request sent and the response received:

    Request uri: https://api.sky.blackbaud.com/gift-batch/v1/giftbatches

    Request method: “POST”

    Request headers:

    {

    Authorization: Bearer {authToken}
    Bb-Api-Subscription-Key: {standardApiSubscriptionKey}
    Content-Type: application/json; charset=utf-8;
    Host: api.sky.blackbaud.com

    }

    Request body:

    {
    "batch_number": "VS_8_01-12-2024"
    }

    Response headers:

    {

    x-content-type-options: nosniff
    strict-transport-security: max-age=31536000; includeSubDomains
    Content-Length: 531
    Cache-Control: no-store, must-revalidate, no-cache
    Content-Type: application/problem+json; charset=utf-8
    Date: Fri, 12 Jan 2024 18:25:05...

    }

    Response body:

    {
    "errors": {
    "": [
    "Unexpected character encountered while parsing value: .... Path '', line 0, position 0."
    ],
    "batch": [
    "The batch field is required."
    ]
    },
    "type": "urn:blackbaud:model-validation-error",
    "title": "One or more validation errors occurred.",
    "status": 400,
    "detail": "Unexpected character encountered while parsing value:Path '', lne 0, position0.\\nThe batch field is required.",
    "instance": "urn:blackbaud:bat-gbapi:",
    "values": {
    "": null,
    "batch": null
    },
    "trace_id": "f69e23ffbe634ae6a298601e824e0fc1",
    "span_id": "6f819c7e20f50109"
    }

    Thank you!

  • Alex Wong
    Alex Wong Community All-Star
    Tenth Anniversary Kudos 5 Facilitator 4 bbcon 2025 Attendee Badge

    @Dylan Hochreiter
    I can't really tell what is the problem with the info you provided. I do think it is on your end with the .NET application call as the SKY API endpoint does work, from Console to Power Automation flow (what I use). You might want to check the .NET HttpWebRequest class on if data are being “encoded” in a way that SKY API doesn't recognize.

    Might want to reach out to support (though first level support isn't going to be much help with API stuff, you will have to esculate and see if they can get you an engineer to help. (or maybe someone else on this forum has .NET application experience that can help you further).

    Good Luck

  • @Alex Wong

    I will look into more on our side and I will reach out to support if I can't figure it out.

    Thank you for your help with this!

Categories