How to format MembershipRequest objects for an Add New Project request?

I’m trying to create a private project that assigns the members from a Trello card to that project, using a single Add New Project request. I’m using Zapier to connect Trello and Clockify. Everything is working except the membership assignments. I keep getting this error:

JSON parse error: Cannot deserialize value of type java.util.ArrayList<com.clockify.adapter.http.project.MembershipRequest> from String value (token JsonToken.VALUE_STRING) (HTTP Status Code: 400)

I’m looping through a list to collect the properties, and push the objects to a list, then inserting that list of objects into an array as the value the “memberships” property. My objects looks like this:

{
“userId”:“xxxxxxxxx”,
“hourlyRate”:“undefined”,
“costRate”:“undefined”,
“targetId”:“undefined”,
“membershipType”:“PROJECT”,
“membershipStatus”:“ACTIVE”
}

I’m a total novice, so I’m hoping I’m just missing some basic syntax here that’s making these objects unreadable to the API. Is it acceptable to have these properties undefined? Is that the correct way to notate undefined in JSON? How could I have the target ID (of the project) when the project isn’t yet made? I would be grateful for some suggested resources in lieu of a definite answer. :slight_smile:

Hello,

You could remove the rates, and the targetId, as the targetId is generated after a project has been created. Here’s how the JSON body could look like:

{
  "name": "My API Project",
  "memberships": [{
    "userId": "ENTER-USER-ID-HERE",
    "membershipType": "PROJECT",
    "membershipStatus": "ACTIVE"
  }]
}

The parameter userId must have a value if you are creating a private project and assigning a user to it. You can get all the userIds by using the Find all users on workspace call
Method: GET
URL: https://api.clockify.me/api/v1/workspaces/{workspaceId}/users

How are you planning on automating the addition of the userId? You could consider matching the userId in Clockify with users in Trello. A custom field comes to mind. You could then use that information to use in the “memberships” param.

Thanks for your response. I removed the extra pairs from the membershipRequests. Once I knew that was right I was able to troubleshoot and found that Zapier was wrapping each JSON value in double quotes, rendering the array to a string. I was able to build a custom HTTP request and manually format it to be correct. Thanks for your help!

To answer your question, I am looping through checklist items on a Trello card which contain Roles and Assignees for gigs. A table in Zapier translates the Trello ID to a Clockify ID. That’s used to create the list of Member request objects and task objects.

When the project is created, each user’s role on the project is made into a task which is pre assigned to them so they can easily clock hours on whatever projects they’re booked on. It’s working!