# Pinata cloud POST API

**URL:** <https://discourse.nodered.org/t/pinata-cloud-post-api/52267>\
**Category:** General\
**Tags:** http-request\
**Created:** [15 October 2021 13:16 UTC](https://discourse.nodered.org/t/pinata-cloud-post-api/52267 "2021-10-15T13:16:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [15 October 2021 13:16 UTC](https://discourse.nodered.org/t/pinata-cloud-post-api/52267/1 "2021-10-15T13:16:53Z")

</div>

Did someone managed to set a flow for sending file to [pinata cloud](https://www.pinata.cloud/) ?  
I managed to use Postman to upload an image, so I copied the headers and set the msg.headers property.

```auto
msg.headers = {
 "content-type": 'multipart/form-data; boundary',
"pinata_api_key": flow.get('api-key'),
"pinata_secret_api_key": flow.get('api-key-secret')
}
return msg;

```

And I guessed the file should be sent in as a buffer inside msg.payload, but got a response:

> Invalid request format

So I found the [tutorial](https://medium.com/pinata/how-to-pin-to-ipfs-effortlessly-ba3437b33885).  
But got stuck on the boundary (in msg.headers)  
Any suggestions or examples on how to accomplish pushing the stream of data?

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [16 October 2021 10:51 UTC](https://discourse.nodered.org/t/pinata-cloud-post-api/52267/2 "2021-10-16T10:51:04Z")

</div>

Hi Vukmirovic,

unfortunately i dont know anything about the Pinata service but i had a quick browse through its documentation and they have something called [Pinata NodeJS SDK](https://docs.pinata.cloud/pinata-node-sdk)

Looking at the code examples,  
you could use the Function node's new feature of loading external libraries ( [functionExternalModules](https://nodered.org/docs/user-guide/writing-functions#using-the-functionexternalmodules-option) )  
and try to replicate the [pinfiletoipfs](https://docs.pinata.cloud/pinata-node-sdk#pinfiletoipfs) code examples

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/7561ea78079fbb2426a04b244c900e047b44c3b4.png)

ps. instead of using `const fs = require('fs');` try to pass the data from the File read node

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [16 October 2021 12:00 UTC](https://discourse.nodered.org/t/pinata-cloud-post-api/52267/3 "2021-10-16T12:00:35Z")

</div>

Yea i tried, but without luck...

```auto
const pinata = pinataSDK('yourPinataApiKey', 'yourPinataSecretApiKey');

```

> TypeError: pinataSDK is not a function
> 
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/c/ec71a401c80703755563f6b5fb759bc1d92ecb51.png)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [16 October 2021 12:21 UTC](https://discourse.nodered.org/t/pinata-cloud-post-api/52267/4 "2021-10-16T12:21:03Z")

</div>

can you confirm that the library is indeed installed in NR node\_modules.  
have you tried the **testAuthentication** code on that page ?

```javascript
const pinata = pinataSDK('yourPinataApiKey', 'yourPinataSecretApiKey');

pinata.testAuthentication().then((result) => {
    //handle successful authentication here    
    node.warn(result);
}).catch((err) => {    
  //handle error here    
    node.warn(err);
});

```

it seems to be working for me. i get an error reply back

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/8/581eeddc9b259c6a5fd3126b01b0b202919e622b.png)

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [18 October 2021 11:19 UTC](https://discourse.nodered.org/t/pinata-cloud-post-api/52267/5 "2021-10-18T11:19:28Z")

</div>

Okay so doing basic authentication with a function node gets the same error...  
Have edited the setup tab correctly.  
And can confirm that in .node-red/node\_modules is a @pinata folder and a subfolder sdk...

Running node-red on digital ocean as a root user.  
I was trying to parse global context as api key and secret, maybe this is causing some kind of error, will edit and check again...

Edit2: Still getting the same error: PinataSDK is not a function.

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [18 October 2021 11:26 UTC](https://discourse.nodered.org/t/pinata-cloud-post-api/52267/6 "2021-10-18T11:26:23Z")

</div>

```auto
[
    {
        "id": "f6c8bb8c.63c8b",
        "type": "inject",
        "z": "d8af3a19.cf979",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 140,
        "y": 560,
        "wires": [
            [
                "9a7fa24aec49c733"
            ]
        ]
    },
    {
        "id": "eb856269.cdcd78",
        "type": "debug",
        "z": "d8af3a19.cf979",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 490,
        "y": 560,
        "wires": []
    },
    {
        "id": "9a7fa24aec49c733",
        "type": "function",
        "z": "d8af3a19.cf979",
        "name": "",
        "func": "const pinata = pinataSDK('dbe7b2988967075232d6','fdc928821fa73ae6b896091a3ef0d8d02eac5a47baa1a14385c42b8302c58eb9')\npinata.testAuthentication().then((result) => {\n //handle successful authentication here\n console.log(result);\n}).catch((err) => {\n //handle error here\n console.log(err);\n});",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [
            {
                "var": "pinataSDK",
                "module": "@pinata/sdk"
            }
        ],
        "x": 300,
        "y": 560,
        "wires": [
            [
                "eb856269.cdcd78"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [18 October 2021 12:57 UTC](https://discourse.nodered.org/t/pinata-cloud-post-api/52267/7 "2021-10-18T12:57:52Z")

</div>

Hello lizzardguki,

I can connect with your flow .. so it must something having to do with running your system with digital ocean. ( dont know how to help debug that .. we need some help from the master developers )

lets try will the traditional way of loading external libraries ([functionGlobalContext](https://nodered.org/docs/user-guide/writing-functions#loading-additional-modules))  
Edit your `settings.js` file and look for the section of `functionGlobalContext` and uncomment/add

```auto
functionGlobalContext: {
    pinataSDK:require('@pinata/sdk')
}

```

Then from the Function node remove the entry from Setup tab (by press the X button) and add in the code  
`let pinataSDK= global.get('pinataSDK')`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [17 December 2021 12:58 UTC](https://discourse.nodered.org/t/pinata-cloud-post-api/52267/8 "2021-12-17T12:58:12Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
