当前位置: 动力学知识库 > 问答 > 编程问答 >

node.js - PHP to Nodejs conversion for Pipedrive Deals

问题描述:

I am getting back into programming after being gone for 20 years. A lot has changed! lol...

I have a NodeJS server setup on Heroku for my mobile app. I am trying to add an event on my server that will add new user info to Pipedrive.com using their API.

They have only written their API examples in PHP. So I'm trying to translate PHP to Javascript, while also learning NodeJS, PHP, and understanding Pipedrive's API all at the same time.

They pointed me to Tonicdev which has been epically useful in getting my javascript syntax down. Since that uses live Pipedrive data when I add my token, I can do all my testing there too, before trying to upload and test on my actual Nodejs server. So that's handy!

But I'm still trying to get a grip on what's happening in their API code. This is my first time to implement an API by myself.

Here is the page I am trying to translate:

http://support.pipedrive.com/hc/en-us/articles/206679239-Creating-a-deal-using-the-REST-API-and-PHP-full-working-example-code-

I don't need the organization. Just the person and the deal.

In my create_person function, I found this php:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, $person);

$output = curl_exec($ch);

$info = curl_getinfo($ch);

curl_close($ch);

My questions are:

What is curl_init and curl_setopt?

Do I need them in my Nodejs script file for this?

If not, what javascript do I use in their place?

Thanks for your patience. Learning a ton here!!!

网友答案:

curl is a PHP library that handles making requests.

In this case curl_init() is initialising a new request and curl_setopt is setting certain options.

You'll want to replace curl with an equivalent library for NodeJS. The request module is pretty good for this, although there's plenty of other options too.

分享给朋友:
您可能感兴趣的文章:
随机阅读: