Solved

Drupal 8 Webforms to ticket via API

  • 7 April 2021
  • 1 reply
  • 14 views

Has anyone successfully integrated Drupal 8 Webforms with Freshdesk? 

Using the Freshdesk cURL API, I can create a ticket so I know my authentication is working. I get “status: 201 Created”

curl -v -u VqWhnMiPpGjp4WG5BN8:X -H "Content-Type: application/json" -d '{ "description": "fred test 11:45am", "subject": "Support Needed...", "email": "fred@random.com", "priority": 1, "status": 2}' -X POST 'https://newaccount1617642128034.freshdesk.com/api/v2/tickets'

 

With Drupal 8 webforms, I keep getting “Status: 401 Unauthorized”.

I think it has to do with the HTTP Authorization header in webforms. I’ve tried both API:x and the base64 encoded of API:x

 

Authorization: ‘VqWhnMiPpGjp4WG5BN8:X’

Authorization: 'Basic VnFXaG5NaVBwR2pwNFdHNUJOODpY'

 

(I’m using a free eval account for Freshdesk so I’m not worried about posting this API key.)

This is the debug page from Drupal 8 weboforms:

Request URL https://newaccount1617642128034.freshdesk.com/api/v2/tickets

Request method POST

Request type json

Request options

Authorization: 'Basic VqWhnMiPpGjp4WG5BN8:X'json:  your_email_address: test@test.com  your_name: Dixisset  description: 'Quae cum dixisset, finem ille. Quamquam non negatis nos intellegere quid sit voluptas, sed quid ille dicat. Progredientibus autem aetatibus sensim tardeve potius quasi nosmet ipsos cognoscimus. Gloriosa ostentatio in constituendo summo bono.'  attach_a_file: null

Response status code: 401

Response header:

Date:  - 'Wed, 07 Apr 2021 21:32:14 GMT'Content-Type:  - 'application/json; charset=utf-8'Transfer-Encoding:  - chunkedConnection:  - keep-aliveStatus:  - '401 Unauthorized'X-Request-Id:  - 96ac2c95-b0ea-970a-9b35-d3783ad514a8X-Freshdesk-Api-Version:  - 'latest=v2; requested=v2'X-Rack-Cache:  - 'invalidate, pass'Cache-Control:  - no-cacheX-Xss-Protection:  - '1; mode=block'X-Ua-Compatible:  - 'IE=Edge,chrome=1'X-Content-Type-Options:  - nosniffSet-Cookie:  - '_x_w=41; path=/; HttpOnly; secure'  - '_x_m=x_c; path=/; HttpOnly; secure'X-Fw-Ratelimiting-Managed:  - 'true'X-Ratelimit-Total:  - '280'X-Ratelimit-Remaining:  - '279'X-Ratelimit-Used-Currentrequest:  - '1'X-Envoy-Upstream-Service-Time:  - '38'X-Trace-Id:  - 00-632e47f4f5b4a6b3d04301e0d9051ddc-c06e9caeea63c103-01Server:  - fwe

Response body:

{"code":"invalid_credentials","message":"You have to be logged in to perform this action."}

 

 

icon

Best answer by Keer 8 April 2021, 13:55

Hello @PaErickson, good day! Thank you for sharing the response beforehand. Upon checking this from our end, it looks like the API key was never passed in the header of the API call that’s why the call is failing with ‘401 Unauthorized’ error. 

 

Additionally, the parameters in the body of the call are also not passed right as per the guidelines mentioned here. The right format would be:

 

curl -v -u user@yourcompany.com:test -H "Content-Type: application/json" -d '{ "description": "Details about the issue...", "subject": "Support Needed...", "email": "tom@outerspace.com", "priority": 1, "status": 2, "cc_emails": ["ram@freshdesk.com","diana@freshdesk.com"] }' -X POST 'https://domain.freshdesk.com/api/v2/tickets'

 

So the issue is not with the right API key being used, but it’s about how it’s passed. Can you please recheck both of the above-mentioned points and tweak the script accordingly? 

 

If you need any further help on this, can you share how you are making the call over email to support@freshdesk.com so that our support buddies can help you with the same?

 

 

Thanks and have a great day!

View original

1 reply

Userlevel 2

Hello @PaErickson, good day! Thank you for sharing the response beforehand. Upon checking this from our end, it looks like the API key was never passed in the header of the API call that’s why the call is failing with ‘401 Unauthorized’ error. 

 

Additionally, the parameters in the body of the call are also not passed right as per the guidelines mentioned here. The right format would be:

 

curl -v -u user@yourcompany.com:test -H "Content-Type: application/json" -d '{ "description": "Details about the issue...", "subject": "Support Needed...", "email": "tom@outerspace.com", "priority": 1, "status": 2, "cc_emails": ["ram@freshdesk.com","diana@freshdesk.com"] }' -X POST 'https://domain.freshdesk.com/api/v2/tickets'

 

So the issue is not with the right API key being used, but it’s about how it’s passed. Can you please recheck both of the above-mentioned points and tweak the script accordingly? 

 

If you need any further help on this, can you share how you are making the call over email to support@freshdesk.com so that our support buddies can help you with the same?

 

 

Thanks and have a great day!

Reply