Hello
I'm trying to use REST API to create a test case folder
I make a REST call to the url http: //mysquashserver/squash/api/rest/latest/test-case-folders with the POST method and 2 headers:
- Authorization basic
- Content-Type header: application/json
body is:
{
"_type": "test-case-folder",
"name": "Test case folder 1",
"description": "Description Test case folder 1",
"custom_fields": [
{
"code": "cuf1",
"value": "Cuf1 Value"
}
]
"parent": {
"_type": "project",
"id": 18
}
}
the folder is not created
in the body of the answer I receive the list of the folder
as if i had run the GET method
the status code that I receive in response is 0200 (OK)
instead I would have expected 0201 (created)
am I doing something wrong ?
Thanks for your help
nobody help me ?
thanks a lot. i'll never post something here.
problems creating test-case-folders with REST API
-
- Messages : 2
- Inscription : mar. janv. 07, 2020 3:41 pm
problems creating test-case-folders with REST API
Dernière modification par dbombardieri le lun. févr. 03, 2020 4:14 pm, modifié 2 fois.
Re: problems creating test-case-folders with REST API
Hello,
I'm new to squash and I want to consume the rest API but there is no way to find a tutorial or an example to how it should look like. could you please helpl me I just need to know more about the Authorization basic part and how to do it.
It would be very helpful
Thank you
I'm new to squash and I want to consume the rest API but there is no way to find a tutorial or an example to how it should look like. could you please helpl me I just need to know more about the Authorization basic part and how to do it.
It would be very helpful
Thank you
-
- Messages : 2
- Inscription : mar. janv. 07, 2020 3:41 pm
Re: problems creating test-case-folders with REST API
<<could you please helpl me I just need to know more about the Authorization basic part and how to do it.>>
for Authorization you must insert a header with
Header name=Authorization
Header value =Basic xxx
where xxx should be the following string yoursquashusername:yoursquashpassword encoded in base 64
you can use this link https://www.base64encode.org/ to encode
for Authorization you must insert a header with
Header name=Authorization
Header value =Basic xxx
where xxx should be the following string yoursquashusername:yoursquashpassword encoded in base 64
you can use this link https://www.base64encode.org/ to encode
Re: problems creating test-case-folders with REST API
Thanks a lot for your response that was very helpful
Re: problems creating test-case-folders with REST API
Hi mates!
As REST API is fairly uncomplete, I do recommend using cookie instead of Basic Auth.
In fact, REST API won't allow you to work on every levels ; I often consumes "regular" HTTP calls (such as ${SQUASH_SERVER_URL}/test-cases/${TEST_CASE_ID}).
Here is a short snippet to generate a proper session cookie:
As REST API is fairly uncomplete, I do recommend using cookie instead of Basic Auth.
In fact, REST API won't allow you to work on every levels ; I often consumes "regular" HTTP calls (such as ${SQUASH_SERVER_URL}/test-cases/${TEST_CASE_ID}).
Here is a short snippet to generate a proper session cookie:
Code : Tout sélectionner
#!/bin/bash
### Define variables
squashtmcookiejar=/tmp/squashcookies.txt
SQUASH_SERVER_PROTO=http://
SQUASH_SERVER_DN= your.domain.name
SQUASH_SERVER_PORT=8080
SQUASH_SERVER=${SQUASH_SERVER_PROTO}${SQUASH_SERVER_DN}:${SQUASH_SERVER_PORT}
SQUASH_SERVER_URL=${SQUASH_SERVER}/squash
SQUASH_u=username
SQUASH_p=password
### Catch CSRF token and header
rm ${squashtmcookiejar}
CURL_RESPONSE=$(curl -c ${squashtmcookiejar} --silent --location --request GET "${SQUASH_SERVER_URL}/login" -w %{http_code})
HTTP_CODE=$(echo "${CURL_RESPONSE}" | tail -n1)
CSRF_TOKEN=$(printf "%s\n" "$CURL_RESPONSE" | grep -Pi '<meta[^<>]*?(name="_csrf")[^<>]*?\>' | grep -Po '(?<=content=")(.*?)(?=")')
CSRF_TOKEN_HEADER=$(printf "%s\n" "$CURL_RESPONSE" | grep -Pi '<meta[^<>]*?(name="_csrf_header")[^<>]*?\>' | grep -Po '(?<=content=")(.*?)(?=")')
### Login to SquashTM for cookie
CURL_RESPONSE=$(curl --silent -b ${squashtmcookiejar} -c ${squashtmcookiejar} --max-redirs 0 --location \
--request POST "${SQUASH_SERVER_URL}/login?_csrf=${CSRF_TOKEN}&username=${SQUASH_u}&password=${SQUASH_p}" \
--header "Host: ${SQUASH_SERVER_DN}:${SQUASH_SERVER_PORT}" -w %{http_code})
HTTP_CODE=$(echo "${CURL_RESPONSE}" | tail -n1)
CURL_RESPONSE=$(curl --silent -b ${squashtmcookiejar} -c ${squashtmcookiejar} --location \
--request GET "${SQUASH_SERVER_URL}/home-workspace" -w %{http_code})
HTTP_CODE=$(echo "${CURL_RESPONSE}" | tail -n1)
CURL_RESPONSE=$(curl --silent -b ${squashtmcookiejar} -c ${squashtmcookiejar} --location \
--request GET "${SQUASH_SERVER_URL}/test-case-workspace/" -w %{http_code})
HTTP_CODE=$(echo "${CURL_RESPONSE}" | tail -n1)
## Check if authentification is successful
echo "${CURL_RESPONSE}" | grep "This file is part of the Squashtest platform." > /dev/null
if [ ! "${?}" -eq 0 ]; then
printf "\033[0;31mAuthentification unsuccessful...\033[0m\n"
else
printf "\033[0;32mAuthentification successful !\033[0m\n"
fi
QA ninja @ easiware
Re: problems creating test-case-folders with REST API
Hello @dbombardieri,
I have the same issue with the Squash API request to create and update the campaign-folder and iteration . ( yet the other requests work well in the same way... )
did you find a solution please ?
I have the same issue with the Squash API request to create and update the campaign-folder and iteration . ( yet the other requests work well in the same way... )
did you find a solution please ?