Skip to main content
Best answer

JS Code Get Input Name for Script Help


Dan_GRHF
Forum|alt.badge.img

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": [ID NUMBER REMOVED BY MODERATOR]
}
headers = {
    "accept": "application/json",
    "content-type": "application/json",
    "authorization": "Bearer [API KEY REMOVED BY MODERATOR]"
}

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

print(response.text)

 

This post has been edited by a moderator to remove personal information. Please remember that this is a public forum and to remove any sensitive information prior to posting.

Best answer by Dan_GRHF

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": [ID NUMBER REMOVED BY MODERATOR]

This post has been edited by a moderator to remove personal information. Please remember that this is a public forum and to remove any sensitive information prior to posting.

View original
Did this topic help you find an answer to your question?
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

Todd Harper
Forum|alt.badge.img+8
  • Zapier Expert
  • 197 replies
  • March 22, 2023

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,

 


Dan_GRHF
Forum|alt.badge.img
  • Author
  • Beginner
  • 5 replies
  • Answer
  • March 23, 2023

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": [ID NUMBER REMOVED BY MODERATOR]

This post has been edited by a moderator to remove personal information. Please remember that this is a public forum and to remove any sensitive information prior to posting.


Todd Harper
Forum|alt.badge.img+8
  • Zapier Expert
  • 197 replies
  • March 23, 2023

@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 :)


Dan_GRHF
Forum|alt.badge.img
  • Author
  • Beginner
  • 5 replies
  • March 23, 2023

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.