Facing issue with nested element parameter in API connector

Hi,

I am trying to connect to an API using API connector.

This is my API end point requirement:
Screenshot 2020-08-25 at 7.55.26 PM

I can’t figure out how to create the JSON for this with or without dynamic data. The problem is the nested object “customer”. Whenever I add it with or without dynamic data, I am getting error from API.
Var 1:

{
"amount":"<amount>",
"type":"<type>",
"description":"<description>",
"customer":{  
    "name":"<customer_name>",  
    "email":"<customer_email>",  
    "contact":"<customer_contact>"  
    },
"callback_url":"<callback_url>",
"callback_method":"<callback_method>"
}

Var 2:

{
"customer":[{  
    "name":"bbb",  
    "email":"bbb@beegle.app",  
    "contact":"9880728522"  
    }],
"amount":"<amount>",
"type":"<type>",
"description":"<description>",
"callback_url":"<callback_url>",
"callback_method":"<callback_method>"
}

Var 3:

{
"amount":"<amount>",
"type":"<type>",
"description":"<description>",
"name":"<customer_name>",  
"email":"<customer_email>",  
"contact":"<customer_contact>",
"callback_url":"<callback_url>"
}

Var 4:

{
"amount":"<amount>",
"type":"<type>",
"description":"<description>",
"customer":[  
    "name":"<customer_name>",  
    "email":"<customer_email>",  
    "contact":"<customer_contact>"  
    ],
"callback_url":"<callback_url>",
"callback_method":"<callback_method>"
}

Var 5:

{
"amount":"<amount>",
"type":"<type>",
"description":"<description>",

"customer": {

      "name": "Jay",

      "email": "jay@beegle.app",

      "contact": "9880728771"

},

"callback_url":"<callback_url>"
}

What am I doing wrong and what is the right syntax?

Please note that API is hitting fine if i remove “customer” section as it is optional. So, I have got all other things like content-type etc set correctly. It is just this nested element that I am not getting right.

Please also note that I have had a look at several threads including following, but couldn’t get right answer:

Thanks,
Mukesh

Hi Mukesh,

Can you post a screenshot of the error you’re getting?

Ambroise

Need extra help?

Book a free 15 minutes call - happy to help if I can

And the full setting in API Connector?
Did you set the header to Content-type application/json

@ambroisedlg here are the screenshots.

Error message:

Overall API Setting:

Setting specific to this call:

@Jici as I had mentioned in my original post, the API call is working without the nested parameter and hence Content Type of errors are not the issue here. Yes, I have already set it up as application/json

customer is not an array. So you need to remove it
The message say that the line_item is not there. So I guess you need to add it. But I checked the documentation and see that when the type is link, this is not needed. Are you sure you are filling type to “link” ? (you din’t post the bottom of API connector so I don’t see what you use to test)

you can debug using tool like postman and requestbin. Replace the link to the api to a requestbin and check the payload sent. It may help you to find what doens’t work.

Yes, I am passing type as “link”.

Here’s the snapshot of the bottom part:

I am referring to documentation on https://razorpay.com/docs/payment-links/api/create/ . Is that what you are referring to too? I don’t see any mention of “line_item” in documentation. I just assumed it is a keyword indicating that some line item is missing.

As I have posted in my initial post, there are examples where I tried with and without square brackets both.

line_item is when you use type invoice (read invoice section create)
https://razorpay.com/docs/api/invoices/#create-an-invoice

Did you tst in postman (or insomnia)? Does it work?

Okay, yeah looks like they use same API for two different purposes depending on the value of “type”.

I haven’t tried in postman. I am just overwhelmed with the tools and integrations. Postman will use its own new terminologies assuming that a non geek person like me will understand everything and I’ll spend another few hours in cracking it :frowning:

Anyway I’ll try that.

@Jici So, your pointer about postman helped.

Actually there was nothing wrong in what I was trying as such.

Amazingly the spaces that I had given in before “name”, “email” etc. sub fields in the “customer” segment were not right. Either the number of spaces were not right, or it was expecting a tab there. Not sure.

Here’s the final thing that worked.

{
  "customer": {
    "name": "<name>",
    "email": "<email>",
    "contact": "<contact>"
  },
  "type": "link",
  "amount": "<amount>",
  "currency": "INR",
  "description": "Beegle Services",
  "callback_url": "<callback_url>",
  "callback_method": "get"
}

It is same as one of my previously tried versions, except for the spaces in the nested field.

It is absurd that spaces would make so much difference, and they won’t make it clear that it should be so.

How I found this out?

  • So, I pasted my version in postman and I got the same line_items missing error.
  • Then I thought let me try the version that they have given on the website. Interestingly it worked.
  • Initially I thought it could be presence of some extra parameters, or their sequence.
  • I tried to match everything, but nothing worked.
  • Then I did a diff of text of mine and theirs. Saw some spaces differences.
  • I started matching that too to make sure my text and theirs was similar. At last when I changed the spaces before the nested field’s names, the texts were identical and it worked!

So now I copied the text from postman to Bubble and changed the static fields to dynamic angular bracket thing and tried.

And it worked!

Weird, funny, and relieving!

Thanks for all your help.

2 Likes

These spacing issues are ridiculous!!!