Best answer

JS Code Get Input Name for Script Help

  • 22 March 2023
  • 4 replies
  • 46 views

Userlevel 1
Badge

Hello I have some JS code below related to the API of an app we use at work.

 

I am trying to get the to numbers section below to return the input data in the screen shot. I have no idea how to write JS but any help or ideas to get this to be correct would be great. 

 

In the actual JS code from the API docs I was returning this and on testing it worked.

 

"to_numbers": ["+15555555555"],

 

I can’t however figure out how to pull the input data

 

 

import requests

url = "https://dialpad.com/api/v2/sms"

payload = {
"infer_country_code": False,
"to_numbers": return {'phone': input_data ['phone']},
"text": "test message",
"user_id": 4897195490967552
}
headers = {
"accept": "application/json",
"content-type": "application/json",
"authorization": "Bearer TBEfvRW49wqwqJN7pyYZ3mNgYU3qdeb92VSaKtqgesXaMLLSWnPMQ9t9A4xZapMNnscpVaT3qWhzFvAF3qJy42NvSvjrr3CKAHCN"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)

 

icon

Best answer by Dan_GRHF 23 March 2023, 14:16

View original

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

4 replies

Userlevel 6
Badge +8

Assuming the number has to be surrounded by square brackets:

At the top, write:

let phone = '["' + inputData.phone + '"]';

then, in the API call, write:

"to_numbers": phone,

 

Userlevel 1
Badge

That didn’t quite work. But it made me realize what the Zapier were instructions were saying. Updated it and this seemed to work in the test.

return {'phone': input_data ['phone']}

import requests

url = "https://dialpad.com/api/v2/sms"

payload = {
"infer_country_code": False,
"to_numbers": 'phone',
"text": "test message",
"user_id": 4897195490967552

 

Userlevel 6
Badge +8

@Dan_GRHF Ah, looks like you were actually using Python, not JS. Didn’t catch that on my first read through, since I was hyper focused on the JS solution. Glad it worked in the end :)

Userlevel 1
Badge

my mistake sorry about that. Probably because I am not a coder and was just copying what the api docs gave me I must not have realized it.