Question

API Request with x-www-form-urlencoded

  • 29 January 2024
  • 20 replies
  • 380 views

Userlevel 1
Badge

I am currently trying to use an API Request step in a Zap to update a field on Chargebee; they don’t take JSON requests so I’m trying to change it into x-www-form-urlencoded. The response data seems like it was a successful request, but the field that I’m trying to update is not changing at all. 

This is how I have the step setup at the moment:

https://{{site}}.chargebee.com/api/v2/subscriptions/{{subscription_id}}/update_for_items/ for the URL

 

Would what I’m trying to do here even be possible? What can I do to make this work?

Thank you,

Michelle


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

20 replies

Userlevel 7
Badge +14

Hi @MichelleT 

Please link to the Chargebee API docs for the endpoint you are trying to use to give us more context, thanks.

Userlevel 1
Badge

Hi @Troy Tessalone!

Here’s the URL for the documentation I was using and testing on Postman!

https://apidocs.chargebee.com/docs/api/subscriptions?lang=curl#update_subscription_for_items

 

After using the sample CURL and changing it a bit to fit what I needed, it worked well when it was in x-www-form-urlencoded format, but Chargebee doesn’t take JSON which is the primary thing Zapier uses :(

(I got confirmation from our Chargebee contact that they don’t use JSON for requests, only for the response body)

Userlevel 1
Badge

Hi @Troy Tessalone,

Just wanted to provide more context as well, I did try to use the existing Update a Subscription step, but it asks for other required fields that I don’t want to touch. It asks for Item Family and Item but I don’t want to add/delete/overwrite the information that’s already in there. I tried to use a Retrieve Subscription step before the Update step to try and grab this information to keep it the same, but it’s not even information that’s coming in the response. So that’s why I thought it would be better to use an API request to update the one field, but it’s proving to be difficult as well 😅

 

Thanks again,

Michelle

Userlevel 7
Badge +14

@MichelleT 

https://apidocs.chargebee.com/docs/api/

Chargebee provides an HTTP-based API that follows the principles of REST. The HTTP rules followed allow simple HTTP clients like cURL to be used as well.
The URLs are resource-oriented, the request format is form-encoded, and the responses are in JSON.

 

We would need to see full screenshots with how the Zap step is configure for the Chargebee API. (e.g. method, url, headers)

Userlevel 1
Badge

@Troy Tessalone 

Sure!

 

Userlevel 7
Badge +14

@MichelleT 

Have you tried reaching out to Chargebee Support for help with their API?

 

NOTE: Remove the trailing /

 

Custom Fields

Purchase API supports custom fields of Subscriptions, use the following format to specify custom fields in Purchase API: subscription_info[custom_field].

 

 Try setting the Content-Type to application/json OR removing the additional Header for Content-Type.

 

Userlevel 1
Badge

@Troy Tessalone 

I have reached out to the Chargebee team, they’re the ones that confirmed that Chargebee doesn’t support JSON so I can’t change the Content Type and expect it to work. Since the issue is formatting the request in Zapier, not sure how else they could help me.


subscription_info[custom_field]This is for the Purchase API, I’m not currently working with Purchases, just the Subscriptions.

Userlevel 7
Badge +14

@MichelleT 

Did Chargebee Support tell you to use that Content-Type? (Or where in their API docs do you see that Content-Type specified?)

 

On the Subscriptions endpoints, I don’t see reference to Custom Fields.

Can you screenshot/link to that info?

Userlevel 1
Badge

@Troy Tessalone 

This is what I see in the API documentation for Subscriptions; I realize that it shows me the Custom fields we have in our instance of the site because currently I’m logged in (You can also see what formats are supported for the API requests at the top, and the custom field I want to update at the bottom)

 

Userlevel 7
Badge +14

@MichelleT 

What about this?

Did Chargebee Support tell you to use that Content-Type? (Or where in their API docs do you see that Content-Type specified?)

Userlevel 1
Badge

@Troy Tessalone 

They didn’t tell me to use that Content Type specifically, they just confirmed they don’t support JSON. So I assumed x-www-form-urlencoded was the next best thing since the CURL requests in Postman turned into it when I was testing. But I’m more than willing to switch to anything else that would work, it doesn’t need to be this current format if it’s not the best solution.

Userlevel 7
Badge +14

@MichelleT 

Try without the Content-Type Header as it may not be required.

Try with the Content-Type Header set to application/json since the data being sent is in JSON format.

 

 

Userlevel 1
Badge

@Troy Tessalone 

I’ve already tried both suggestions and it’s all the same, the field is not being changed.

I know that the body looks like JSON, I just don’t know how to write it in the Key and Value format that Postman was doing it in.

Userlevel 7
Badge +14

@MichelleT 

If it works in Postman, then post screenshots with how the request was configured along with the logs of the processed request.

Userlevel 1
Badge

@Troy Tessalone 

This is what the successful API request looks like on Postman in case you were curious and/or it helps in this case:

 

Userlevel 1
Badge

@Troy Tessalone

Oh ok! I sent that screenshot before that previous reply, I’ll add the other screenshots you’ve asked for!

 

 

Userlevel 7
Badge +14

@MichelleT 

Can you show the Headers?

 

Userlevel 1
Badge

@Troy Tessalone 

The relevant headers, at least in my opinion, are in that second screenshot but I can send one of all of them sure:

In case you think of the same thing as me, it’s not “failing” because of Authorization issues because the JSON in response on Zapier still claims that the request was successful. It just doesn’t actually make the change it’s supposed to.

Hi, i am having the same problem with Twilio API, they expect an urlencoded POST, POstman works ok but not in Zapier, it always send the request with JSON Body instead of a form data.

Userlevel 1
Badge

@andresamayadiaz I don’t know if this is related to your issue, but the way that I was able to fix this was by putting the “key” and “value” into the Query String Parameter part instead of the Body