Failed to parse PAYLOAD_FILE payload.json: invalid JSON provided
Asked by Edgar Khimich:

Hello guys   
Trying to integrate slack messages in my pipeline but receiving an "Invalid JSON provided" error.   

This is my pipeline:   

```
pipelines:
  default:
    - step:
        name: Slack Notification
        script:
          - apt-get update && apt-get install gettext-base
          - envsubst < ./pipeline/slack/payloads/payload_firebase_beta.json.template > ./pipeline/slack/payloads/payload_firebase_beta.json
          - pipe: atlassian/slack-notify:2.0.0
            variables:
              WEBHOOK_URL: $WEBHOOK_URL
              PRETEXT: 'New Android beta release was published to Firebase! ???'
              PAYLOAD_FILE: ./pipeline/slack/payloads/payload_firebase_beta.json
```

*payload_firebase_beta.json*

```
{
  "blocks": [
      {
          "type": "section",
          "text": {
              "type": "mrkdwn",
              "text": "$WEBSITE"
          }
      },
      {
          "type": "divider"
      },
      {
          "type": "section",
          "text": {
              "type": "mrkdwn",
              "text": "Test mrkdwn text"
          }
      }
  ]
}
```

*payload_firebase_beta.json.template*

```
WEBSITE="test website"
```

Error:  

```
INFO: Starting with payload provided in PAYLOAD_FILE...
INFO: Sending notification to Slack...
? Failed to parse PAYLOAD_FILE payload.json: invalid JSON provided.
```

Thank you in advance


Answers:
author: Mark C
body: Hi [@Edgar Khimich](/t5/user/viewprofilepage/user-id/3446033)

Thank you for reaching out to the community.

I've tested the same on my end.  
However, using the JSON format you provided works fine on my end.  
I tried providing an invalid JSON format to the Pipes script and I was able to reproduce the same error message.

For this, would it be possible for you to check the JSON format after the command **envsubst**?

```
- envsubst < ./pipeline/slack/payloads/payload_firebase_beta.json.template > ./pipeline/slack/payloads/payload_firebase_beta.json- cat ./pipeline/slack/payloads/payload_firebase_beta.json
```

Let me know how it goes.

Regards,  
Mark C

comments: author: Edgar Khimich
body: Sorry for a bit late response.   
It overwrites the payload_firebase_beta.json file with this text.

WEBSITE="test website"  

It replaced the whole file instead of the specific veriable.  
That's why it says that the JSON is invalid  

Which envsubst command are you using that works from your side?  
Should my file with variables (template) be in a template format or txt?  


author: Edgar Khimich
body: Okay  
I found the reason why it didn't work.  
I should have first export them as ENVIRONMENT VARS and only after that use it with **envsubst.**

```
- export RELEASE_DATE=$(date +'%b %d, %Y')
- envsubst < ./pipeline/slack/payloads/payload_firebase_beta.json.template > ./pipeline/slack/payloads/payload_firebase_beta.json
```

Now it works!


author: Mark C
body: Hi [@Edgar Khimich](/t5/user/viewprofilepage/user-id/3446033)  

Glad to know you've found the reason why it didn't work.  

Thank you also for sharing your solution.  

Let me know if you have further questions.

Regards,  
Mark C


Tags: bitbucket-cloud

bitbucket-pipelines

cloud

slack