31,003
edits
mNo edit summary Tag: 2017 source edit |
mNo edit summary Tag: 2017 source edit |
||
| Line 119: | Line 119: | ||
Paste the following code in it: | Paste the following code in it: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="js">const options = { | ||
url: `${bundle.authData.host}/api/index.php/users/info`, | url: `${bundle.authData.host}/api/index.php/users/info`, | ||
method: 'GET', | method: 'GET', | ||
| Line 165: | Line 165: | ||
return results; | return results; | ||
});</syntaxhighlight> | });</syntaxhighlight> | ||
You will then have to specify a “Connection Label”, which will be displayed to the user when he connects to his Dolibarr account from Zapier. For example, you can use the first and last name of the user, or the name of the Dolibarr instance. By imagining that the user is called “John Doe” and that the Dolibarr instance is available at the address <code>https://yourdolibarrurl</code>, you can use the following value: <syntaxhighlight> | You will then have to specify a “Connection Label”, which will be displayed to the user when he connects to his Dolibarr account from Zapier. For example, you can use the first and last name of the user, or the name of the Dolibarr instance. By imagining that the user is called “John Doe” and that the Dolibarr instance is available at the address <code>https://yourdolibarrurl</code>, you can use the following value: <syntaxhighlight lang="js"> | ||
{{bundle.authData.firstname}} {{bundle.authData.lastname}}({{bundle.authData.host}} | {{bundle.authData.firstname}} {{bundle.authData.lastname}}({{bundle.authData.host}} | ||
</syntaxhighlight> which will show <code>John Doe (https://yourdolibarrurl)</code>. | </syntaxhighlight> which will show <code>John Doe (https://yourdolibarrurl)</code>. | ||
| Line 339: | Line 339: | ||
return {id: results}; | return {id: results}; | ||
});</syntaxhighlight> | }); | ||
</syntaxhighlight> | |||
<blockquote>'''Note:''' The code above is to be adapted according to the fields you created in the previous step. For strings, you can directly use user-entered values via <code>bundle.inputData</code>. For dates, you need to use <code>Date.parse()</code> to convert the date entered by the user into timestamp (in milliseconds in JavaScript), then divide by 1000 to get a timestamp in seconds (Dolibarr API expects a timestamp in seconds). Some fields take “hard” numeric values, such as <code>type_id</code>, which will then have to be discovered by exploring the Dolibarr API. Finally, for the <code>userownerid</code> field, we use <code>bundle.authData.id</code>, which was automatically populated by Zapier with the user ID when the user configured their Dolibarr account in Zapier. | <blockquote>'''Note:''' The code above is to be adapted according to the fields you created in the previous step. For strings, you can directly use user-entered values via <code>bundle.inputData</code>. For dates, you need to use <code>Date.parse()</code> to convert the date entered by the user into timestamp (in milliseconds in JavaScript), then divide by 1000 to get a timestamp in seconds (Dolibarr API expects a timestamp in seconds). Some fields take “hard” numeric values, such as <code>type_id</code>, which will then have to be discovered by exploring the Dolibarr API. Finally, for the <code>userownerid</code> field, we use <code>bundle.authData.id</code>, which was automatically populated by Zapier with the user ID when the user configured their Dolibarr account in Zapier. | ||
</blockquote> | </blockquote> | ||