Webservice task not working with error in Body URL (400) | XM Community
Solved

Webservice task not working with error in Body URL (400)

  • 13 September 2023
  • 27 replies
  • 292 views

Userlevel 4
Badge +3

Hi,

 

I created a webservice task in workflow with API token for a method to update an embedded data field with a value for test.

I followed the instructions in link : https://api.qualtrics.com/daed82306b1ea-update-response

I am getting 400 error pointing to invalid URL of body. Both the settings and the error is attached.

What I am doing wrong ? It works fine when i test same in the documentation.

icon

Best answer by Nam Nguyen 13 September 2023, 15:02

View original

27 replies

Userlevel 7
Badge +20

@Neha Tank Try to change the data-type to string or you can change key-value pair to free text and write your own API body following the example in that instruction.

Let me know if it helps

Userlevel 4
Badge +3

Same error with both options

 

Userlevel 4
Badge +3

I tried to put in double quotes for string values too in JSON key value pair.. Still not working fine.

Userlevel 7
Badge +20

 

 

Oh, responseID should be in the URL not header, you header should have content-type and API Token

Userlevel 4
Badge +3

Should I pass response ID as a query parameter like q?=<responseid> ? When I tried doing that I get following error :

 

Userlevel 7
Badge +20

Should I pass response ID as a query parameter like q?=<responseid> ? When I tried doing that I get following error :

 

No, just put it in the URL: 

https://yul1.qualtrics.com/API/v3/responses/R_abcxyz

Change the server code yul1 to your server

Userlevel 7
Badge +20

@Neha Tank If I remember correctly, you’re the one that ask me about importing data vs translate API right?

So you’re working on it?

Userlevel 4
Badge +3

You are a saviour. Thanks a ton. It works fine. Now my actual requirement is to have a file which will have ResponseIDs and the field that I want to update. How can i pass all responseIDs in URL ?

Userlevel 4
Badge +3

Yes, I am the one. We are exploring various options to call API (one from outside code, excel macro and have it in workflow). 

Userlevel 7
Badge +20

You are a saviour. Thanks a ton. It works fine. Now my actual requirement is to have a file which will have ResponseIDs and the field that I want to update. How can i pass all responseIDs in URL ?

Glad you did it. However, the API that you need to read info in a excel file and call API automatically to update response should be executed in your computer, QUaltrics workflow can’t read the file as i know. I suggest python code language.

Anyway, you learned how this API work. A huge step

Userlevel 4
Badge +3

Will this API not help ?

 

https://api.qualtrics.com/2ced5de7dc638-start-an-update-embedded-data-job

Userlevel 7
Badge +20

Theoretically yes, this will do your update in a batch. I’m using it right now in one of my survey.

But I don’t expect you to write a huge JSONObject mannually and this API is more complex to run with lots of condition.

Userlevel 7
Badge +20

On the second thought, try this with the API, it might helps
https://tableconvert.com/excel-to-json

Userlevel 4
Badge +3

I cannot use any utility as our org has strict data privacy regulations. I am trying out a way to have a simple formula in excel which would concatenate the data in the json format. If that works then I shall write a macro to use the data of the cell and create a txt file and save it with .json extension. I shall let you know how it goes.

Userlevel 4
Badge +3

Hi,

I placed the json file in library. Then when i test using the file link in the API documentation, it works fine and it updated the data in survey too. But when I put in the same fileurl in webservice task, it throws an error as below:

Is it not able to access the file ?

 

Userlevel 3
Badge +6

Hi,

Try using postman to run the API. We do have an option to run the API automatically for all responses using postman collection. Create the API call “api.qualtrics.com/daed82306b1ea-update-response” and wherever the value should be dynamically passed, write the field name within curly brace like {{ResponseId}}. This should exactly match the column name in csv file. Then save the collection and run the collection by selecting the csv file with all data. This should ease the process of updating all records automatically.

 

Steps to run the postman collection: Working with data files: ramen (getpostman.com)

 

 

Userlevel 4
Badge +3

Thanks for the response. Yesterday I tried placing the JSON file in the Qualtrics library and executed the workflow with webservice ask passing JSON file against key fileURL and it updated the data as expected. 

I tried the entire process using API token. But I believe OAuth 2.0 is the recommended method proposed by Qualtrics. So reading up on which one is better .. Authorization grant or client credentials. I created the Client ID and secret. Now I am trying to know how can i get the bearer code to pass in API. Please suggest how can it be done. I have limited understanding of POST MAN, so I am learning :)

Userlevel 3
Badge +6

@Neha Tank , Enter the client id, client secret and access token url in postman and click on get new access token. Then a pop up window will open, click on process and then another pop-up window will open, click on use token. This will automatically add the token to your api call. Then just run the API.

 

Userlevel 4
Badge +3

Oh thanks a ton once again. I was able to generate the token. Now I used the API to upload data in batch in Qualtrics instead of POST MAN (Qualtrics API : https://api.qualtrics.com/2ced5de7dc638-start-an-update-embedded-data-job)

What should be done ?

Userlevel 4
Badge +3

Also every time I run the API in future, do I need to generate bearer token every time ? In API token I think it runs until the user is active.

Userlevel 3
Badge +6

@Neha Tank , Pass the Token with Bearer like in the below format.

 

Userlevel 4
Badge +3

Worked like gem :)

Hopefully the last question…. I am planning to run this API through webservice task in workflow. Do I need to generate Bearer token everytime I want to run the task ?

Userlevel 3
Badge +6

Great!

 

Userlevel 4
Badge +3

Do I need to generate Bearer token everytime I want to run the task ?

Userlevel 3
Badge +6

@Neha Tank

In General, Bearer token is valid for an hour. So, you should request a new token for using it after an hour. Details are provided regarding the same in below link.

api.qualtrics.com/9398592961ced-o-auth-authentication-client-credentials

 

Hope this helps :)

Leave a Reply