VMware Cloud Community
Paul87
Contributor
Contributor
Jump to solution

Source with session authentication - The request body is not parsed correctly

Hello,

So, I am trying to create a pack to connect to the Veeam API.

This particular one is using sessions, so I need to call a POST method to retrieve the token.

The issue is that the builder always states that it is unable to parse the body as a json object and it is sending it as a raw string, which is not something that the API likes.

I've tried modifying the body in a lot of ways but I get the same error no matter what I do.

Did anyone encountered this before? is there a workaround?

I've found this link (vRealize Operations Management Pack Builder - Building your first management pack (veducate.co.uk)) that uses the beta version and actually connects to the Veeam API, but the same settings do not work in my case.

Thank you,

Paul

0 Kudos
1 Solution

Accepted Solutions
Paul87
Contributor
Contributor
Jump to solution

For anybody that has this issue. I managed to make it work by changing the content-type.

Although the Veeam documentation asks for the content type to be set as application/x-www-form-urlencoded, just set is as application/json

The body needs to be a valid JSON.

Paul87_0-1686049648238.png

Paul87_1-1686049658694.png

This will work.

Paul87_2-1686049684370.png

 

Thank you,

Paul

 

 

 

View solution in original post

5 Replies
marbogast
VMware Employee
VMware Employee
Jump to solution

Hi @Paul87,

We've not had any issues reported around sending a JSON body in a POST request with MP Builder.

A few questions to help troubleshoot:

1. What version of MP Builder are you using? What version of the Veeam API?

2. Have you set the "Content-Type" query parameter for your POST request?

3. I can't speak to the correctness of that 3rd-party blog. It looks like the body they're using (starting with "grant_type=") is not JSON. You can use various free tools for validating JSON.

The Veeam API documentation may provide an example body that you can reference.

Please feel free to post screenshots here (be careful not to expose any sensitive information), or you can email us at mp-builder-dev@vmware.com. We'd also be happy to jump on a call to help.

Best regards,

Mark

0 Kudos
Paul87
Contributor
Contributor
Jump to solution

Hello @marbogast ,

Thank you for your reply.

The MP builder is at the latest version. 1.1.0.

Paul87_0-1685551727869.png

I actually have 3 API versions for Veeam. But this is not an issue with the Veeam API. It is responsive. I've tried this connection from a linux box, from Windows using PowerShell and from Postman. All are successful.

Paul87_1-1685551789318.png

 

This is the Content-Type:

Paul87_2-1685551913315.png

The 3rd party blog is referenced by VMware documentation - Management Pack Builder - VMware Technology Network VMTN

 

The builder wants to parse the body as JSON and it fails. It even does so when I enter valid JSON. I tried all possible combinations, but it just send the body as raw string. 

Paul87_3-1685552551597.png

This is the API log.

Paul87_4-1685552647569.png

 

The same call done from Postman has this in the API log:

Paul87_5-1685552734841.png

I do not understand how should I write this bit, in order for the parser to not error out.

Paul87_6-1685552831964.png

 

Thank you,

Paul

0 Kudos
Paul87
Contributor
Contributor
Jump to solution

Hello @marbogast ,

I've tried sending you guys an e-mail, but I am not whitelisted. I've tried using two different e-mail addresses.

Thank you,

Paul

0 Kudos
Paul87
Contributor
Contributor
Jump to solution

For anybody that has this issue. I managed to make it work by changing the content-type.

Although the Veeam documentation asks for the content type to be set as application/x-www-form-urlencoded, just set is as application/json

The body needs to be a valid JSON.

Paul87_0-1686049648238.png

Paul87_1-1686049658694.png

This will work.

Paul87_2-1686049684370.png

 

Thank you,

Paul

 

 

 

marbogast
VMware Employee
VMware Employee
Jump to solution

Hi @Paul87,

Glad you were able to find a workaround! Thank you for sharing your solution for others.

Strangely, we were not able to reproduce this issue in our lab. The log about "Could not parse body as a JSON object" is not an error, it's expected behavior for any non-JSON content type (it is misleading; we will look at rewording). And the API's response that grant_type was not specified is also strange - you clearly specified it.

Our best guess is that maybe there was a special character in the password that needed to be url-encoded, thus breaking the entire body of the request.

Regarding the mp-builder-dev@vmware.com address - it appears this email address was made private at some point. My mistake. I have requested it be made public - it may take some time to take effect.

Best regards,

Mark

0 Kudos