0

I have this code running for accessing Mindbody API. This method adds a client to selected class. But this is not working and giving me message:

"ErrorCode : 201 An action has failed. Please see object message for details."

 public string SignUp(Credentials credentials, string[] clientIds, int[] classIds)
    {
        var addToclassRequest = new AddClientsToClassesRequest
        {
            SourceCredentials = new SourceCredentials
            {
                SourceName = credentials.SourceName,
                Password = credentials.SourcePassword,
                SiteIDs = credentials.SiteId
            },
           ClientIDs = clientIds,
           ClassIDs = classIds,
           Test = true,
           RequirePayment = false,
           Waitlist = false,
           SendEmail = true
        };
        var c = _classService.AddClientsToClasses(addToclassRequest);

        return c.Message.ToString();
    }

I dont know why its failing. Any help will be highly appreciated.

2 Answers2

0

You might need to set the request.UserCredentials besides request.SourceCredentials; remove the RequirePayment, Waitlist, set Test = false; and make sure the clientId and classId are exist.

public string SignUp(Credentials credentials, string[] clientIds, int[] classIds)
{
    var addToclassRequest = new AddClientsToClassesRequest
    {
        SourceCredentials = new SourceCredentials
        {
            SourceName = credentials.SourceName,
            Password = credentials.SourcePassword,
            SiteIDs = credentials.SiteId
        },
       ClientIDs = clientIds,
       ClassIDs = classIds,
       Test = false,
       //RequirePayment = false,
       //Waitlist = false,
       SendEmail = true
    };
    var c = _classService.AddClientsToClasses(addToclassRequest);

    return c.Message.ToString();
}
0

Since you're not sending any UserCredentials in your request, you're operating in "Consumer Mode", which typically has a lower level of permissions than "Business Mode", the mode your API call would be in if you passed both SourceCredentials and UserCredentials.

I'm not entirely sure, but it could be that if you want to ensure that you don't need to require a payment in order to add a client to a class (RequirePayment = false), you may need to run the call in "Business Mode".

If that doesn't work and you still get back the same error, you should probably confirm that:

  • You have a valid client ID
  • You have a valid class ID

If that still doesn't work, you might want to try passing in a ClientServiceID aka a Pricing Option ID (I know that this parameter is not documented specifically in the AddClientsToClasses API call documentation, but you can pass it in; figuring that out was guesswork) for the pricing option that you intend to use in order to pay for a class. This takes you down the road of working out a way to make some kind of payment for the class you want to book your client into.

Not sure if this will help, but this is the workflow that I found I needed to end up doing in order to get a client booked properly in a class (each of the steps below required an API call):

  • Retrieve or create the MindBody client ID for the user I want to book in
  • Retrieve the MindBody class ID of the class to book the client into
  • Retrieve all the Service Categories (aka Program IDs) from the MindBody site and choose the one that contained the Pricing Option I would be using to pay for the class
  • Retrieve all the Pricing Options (aka Client Service IDs) that the client is able to use, and choose an appropriate one
  • Retrieve the list of payment methods and extract the ID of the one I intended to use
  • Purchase a pricing option for the client using the the client ID, pricing option ID, and payment method ID
  • Retrieve the ID of the purchased pricing option using the client ID and class ID, and then use the service category ID from earlier to make sure the pricing option is the right one
  • Add client to the class using the IDs of the client, class, purchased pricing option

It was quite complicated and took me a long time to finally get working as intended.

Paul Fioravanti
  • 16,423
  • 7
  • 71
  • 122